]> code.delx.au - gnu-emacs-elpa/blob - packages/loc-changes/test/test-basic.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / loc-changes / test / test-basic.el
1 ;; Copyright (C) 2015 Free Software Foundation, Inc
2
3 ;; Author: Rocky Bernstein <rocky@gnu.org>
4
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
9
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
14
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 (require 'cl)
19 (require 'test-simple)
20 (load-file "../loc-changes.el")
21
22 (test-simple-start)
23
24 (setq sample-buffer (find-file-noselect "./sample.txt"))
25
26 (note "loc-changes-goto-line error conditions")
27 (assert-raises error (loc-changes-goto-line "foo"))
28 (message "buffer %s" (current-buffer))
29 (assert-raises error (loc-changes-goto-line "0"))
30 (assert-raises error (loc-changes-goto-line 0))
31 (assert-raises error (loc-changes-goto-line 10000))
32
33 (note "loc-changes-goto-line")
34 (save-excursion
35 (set-buffer sample-buffer)
36 (loc-changes-goto-line 5)
37 (assert-equal 5 (line-number-at-pos (point))))
38
39 (note "loc-changes-goto-line-with-column")
40 (with-current-buffer sample-buffer
41 (set-buffer sample-buffer)
42 (loc-changes-goto-line 1 3)
43 (assert-equal 1 (line-number-at-pos (point)))
44 ;; FIXME:
45 ;; (assert-equal 2 (current-column))
46 )
47
48 (note "loc-changes-goto-line-invalid-column")
49 (save-excursion
50 (set-buffer sample-buffer)
51 (loc-changes-goto-line 1 300)
52 (assert-equal 1 (line-number-at-pos (point)))
53 ;; FIXME
54 ;; (assert-equal 0 (current-column))
55 (assert-t (or
56 (not (current-message))
57 (string-match "^Column ignored." (current-message))))
58 ;; FIXME:
59 ;; (loc-changes-goto-line 2 -5)
60 ;; (assert-equal 2 (line-number-at-pos (point)))
61 ;; (assert-equal 0 (current-column))
62 ;; (assert-t (or
63 ;; (not (current-message))
64 ;; (string-match "^Column ignored." (current-message))))
65 )
66
67 (note "loc-changes-clear-buffer null")
68 (loc-changes-clear-buffer)
69 (assert-equal '() loc-changes-alist)
70
71 (note "loc-changes-add-and-goto - update")
72 (save-excursion
73 (set-buffer sample-buffer)
74 (loc-changes-add-and-goto 10)
75 (assert-equal 10 (line-number-at-pos)
76 "point should be at line 10")
77 ;; FIXME:
78 ;; (assert-t (assq 10 loc-changes-alist)
79 ;; "Should find 10 in loc-changes-alist")
80 ;; (assert-t (markerp (cdr (assq 10 loc-changes-alist)))
81 ;; "10 in loc-changes-alist should be a marker")
82 )
83
84 (note "loc-changes-goto - update")
85 (save-excursion
86 (set-buffer sample-buffer)
87 (loc-changes-goto 11)
88 (assert-equal 11 (line-number-at-pos)
89 "point should be at line 11")
90 ;; FIXME:
91 ;; (assert-t (assq 11 loc-changes-alist)
92 ;; "Should find 11 in loc-changes-alist")
93 ;; (assert-t (markerp (cdr (assq 11 loc-changes-alist)))
94 ;; "11 in loc-changes-alist should be a marker")
95 )
96
97 (note "loc-changes-goto - no update")
98 (save-excursion
99 (set-buffer sample-buffer)
100 (loc-changes-goto 12 nil 't)
101 (assert-equal 12 (line-number-at-pos)
102 "point should be at line 12")
103 (assert-nil (assq 12 loc-changes-alist)
104 "Should not find 12 in loc-changes-alist")
105 )
106
107 (end-tests)