]> code.delx.au - gnu-emacs-elpa/blob - packages/realgud/test/test-file.el
6f9de6838608a1ea7340fe0fc597267b01bc373d
[gnu-emacs-elpa] / packages / realgud / test / test-file.el
1 (require 'test-simple)
2 (load-file "../realgud/common/loc.el")
3 (load-file "../realgud/common/file.el")
4
5 ;; Note the below line number is tested so it must match what's listed
6 ;; below.
7 (declare-function __FILE__ 'load-relative)
8
9 (declare-function realgud:file-loc-from-line 'realgud-file)
10 (declare-function realgud:file-line-count 'realgud-file)
11 (declare-function realgud:file-column-from-string 'realgud-file)
12 (declare-function realgud-loc? 'realgud-loc)
13
14 (declare-function realgud-loc-line-number 'realgud-loc)
15 (declare-function realgud-loc-column-number 'realgud-loc)
16 (declare-function realgud-loc-filename 'realgud-loc)
17
18 (test-simple-start)
19
20 (eval-when-compile
21 (defvar realgud-file-remap)
22 (defvar test-filename)
23 (defvar test-file-loc)
24 (defvar remap-filename)
25 (defvar old-compilation-find-file)
26 )
27
28 (clrhash realgud-file-remap)
29
30 (setq old-compilation-find-file (symbol-function 'compilation-find-file))
31
32 (setq test-filename (symbol-file 'test-simple))
33
34 (note "realgud:file-line-count")
35
36 (assert-nil
37 (realgud:file-line-count "not-found-file")
38 "File not found")
39
40 (assert-t (integerp (realgud:file-line-count test-filename))
41 "File found")
42
43
44 (note "realgud:file-loc-from-line")
45
46 (fset 'compilation-find-file (lambda(mark test-filename opt)
47 (get-buffer "*scratch*")))
48
49 (save-excursion
50 ;; NOTE: this calls compilation-find-file which prompts for a file
51 ;; (assert-equal
52 ;; "File named `not-found-file' not readable"
53 ;; (realgud:file-loc-from-line
54 ;; "not-found-file" 5 (make-marker))
55 ;; )
56
57 (assert-t (stringp (realgud:file-loc-from-line test-filename 5.5))
58 "invalid real line number")
59
60 (assert-t (stringp (realgud:file-loc-from-line test-filename -1))
61 "negative number")
62
63 (note "realgud:file-loc-from-line information")
64
65 (assert-t (stringp (realgud:file-loc-from-line test-filename 10001))
66 "Line number too large for file")
67
68 (setq test-file-loc (realgud:file-loc-from-line (__FILE__) 5 nil ";; Note"))
69 (assert-t (realgud-loc? test-file-loc)
70 "Ok loc creation - no cmd marker")
71
72 (assert-t (realgud-loc?
73 (realgud:file-loc-from-line test-filename 30 (make-marker)))
74 "Ok loc creation - cmd marker")
75
76 (assert-equal 5 (realgud-loc-line-number test-file-loc))
77
78 ;; FIXME: don't know why this fails in batch
79 ;; (assert-equal 0 (realgud-loc-column-number test-file-loc))
80
81 (assert-equal (__FILE__) (realgud-loc-filename test-file-loc))
82
83 (note "realgud:file-loc-from-line remapping")
84
85 (setq remap-filename " bogus remap-filename.el")
86
87 ;; (assert-equal
88 ;; (format "File named `%s' not readable" remap-filename)
89 ;; (realgud:file-loc-from-line
90 ;; remap-filename 5 (make-marker))
91 ;; )
92 )
93
94
95 (puthash remap-filename test-filename realgud-file-remap)
96
97 (assert-t (realgud-loc?
98 (realgud:file-loc-from-line remap-filename 30))
99 "Ok loc creation with remap - no cmd marker")
100
101 ;; FIXME: don't know why this fails in batch
102 ;; (assert-equal
103 ;; 18
104 ;; (realgud:file-column-from-string (__FILE__) 7 "__FILE__")
105 ;; "Should find string in file/line and get column"
106 ;; )
107
108 (assert-nil
109 (realgud:file-column-from-string (__FILE__) 5 "__FILE__")
110 "Should not find string at this line in located file"
111 )
112
113 (assert-nil
114 (realgud:file-column-from-string (concat (__FILE__) "FOO") 7 "__FILE__")
115 "Should not find file"
116 )
117
118 (assert-nil
119 (realgud:file-column-from-string (__FILE__) 10000 "__FILE__")
120 "Should not find line in file at all"
121 )
122
123 (fset 'compilation-find-file old-compilation-find-file)
124
125 (end-tests)