1 ;; Copyright (C) 2015 Free Software Foundation, Inc
3 ;; Author: Rocky Bernstein <rocky@gnu.org>
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.
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.
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/>.
19 (require 'test-simple)
20 (load-file "../loc-changes.el")
24 (setq sample-buffer (find-file-noselect "./sample.txt"))
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))
33 (note "loc-changes-goto-line")
35 (set-buffer sample-buffer)
36 (loc-changes-goto-line 5)
37 (assert-equal 5 (line-number-at-pos (point))))
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)))
45 ;; (assert-equal 2 (current-column))
48 (note "loc-changes-goto-line-invalid-column")
50 (set-buffer sample-buffer)
51 (loc-changes-goto-line 1 300)
52 (assert-equal 1 (line-number-at-pos (point)))
54 ;; (assert-equal 0 (current-column))
56 (not (current-message))
57 (string-match "^Column ignored." (current-message))))
59 ;; (loc-changes-goto-line 2 -5)
60 ;; (assert-equal 2 (line-number-at-pos (point)))
61 ;; (assert-equal 0 (current-column))
63 ;; (not (current-message))
64 ;; (string-match "^Column ignored." (current-message))))
67 (note "loc-changes-clear-buffer null")
68 (loc-changes-clear-buffer)
69 (assert-equal '() loc-changes-alist)
71 (note "loc-changes-add-and-goto - update")
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")
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")
84 (note "loc-changes-goto - update")
86 (set-buffer sample-buffer)
88 (assert-equal 11 (line-number-at-pos)
89 "point should be at line 11")
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")
97 (note "loc-changes-goto - no update")
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")