* test/automated/occur-tests.el: Move from test/occur-testsuite.el.
[bpt/emacs.git] / test / automated / occur-tests.el
CommitLineData
c07b2710 1;;; occur-tests.el --- Test suite for occur.
5275ff8b 2
73b0cd50 3;; Copyright (C) 2010-2011 Free Software Foundation, Inc.
5275ff8b
JL
4
5;; Author: Juri Linkov <juri@jurta.org>
6;; Keywords: matching, internal
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
5275ff8b
JL
23;;; Code:
24
c07b2710
JL
25(require 'ert)
26
5275ff8b
JL
27(defconst occur-tests
28 '(
29 ;; * Test one-line matches (at bob, eob, bol, eol).
30 ("x" 0 "\
31xa
32b
33cx
34xd
35xex
36fx
37" "\
c07b2710 385 matches for \"x\" in buffer: *temp*<2>
5275ff8b
JL
39 1:xa
40 3:cx
41 4:xd
42 5:xex
43 6:fx
44")
45 ;; * Test multi-line matches, this is the first test from
46 ;; http://lists.gnu.org/archive/html/emacs-devel/2005-06/msg01008.html
47 ;; where numbers are replaced with letters.
48 ("a\na" 0 "\
49a
50a
51a
52a
53a
54" "\
c07b2710 552 matches for \"a^Ja\" in buffer: *temp*<2>
5275ff8b
JL
56 1:a
57 :a
58 3:a
59 :a
60")
61 ;; * Test multi-line matches, this is the second test from
62 ;; http://lists.gnu.org/archive/html/emacs-devel/2005-06/msg01008.html
63 ;; where numbers are replaced with letters.
64 ("a\nb" 0 "\
65a
66b
67c
68a
69b
70" "\
c07b2710 712 matches for \"a^Jb\" in buffer: *temp*<2>
5275ff8b
JL
72 1:a
73 :b
74 4:a
75 :b
76")
77 ;; * Test line numbers for multi-line matches with empty last match line.
78 ("a\n" 0 "\
79a
80
81c
82a
83
84" "\
c07b2710 852 matches for \"a^J\" in buffer: *temp*<2>
5275ff8b
JL
86 1:a
87 :
88 4:a
89 :
90")
91 ;; * Test multi-line matches with 3 match lines.
92 ("x\n.x\n" 0 "\
93ax
94bx
95c
96d
97ex
98fx
99" "\
c07b2710 1002 matches for \"x^J.x^J\" in buffer: *temp*<2>
5275ff8b
JL
101 1:ax
102 :bx
103 :c
104 5:ex
105 :fx
106 :
107")
dc2d2590
JL
108 ;; * Test non-overlapping context lines with matches at bob/eob.
109 ("x" 1 "\
110ax
111b
112c
113d
114ex
115f
116g
117hx
118" "\
c07b2710 1193 matches for \"x\" in buffer: *temp*<2>
dc2d2590
JL
120 1:ax
121 :b
122-------
123 :d
124 5:ex
125 :f
126-------
127 :g
128 8:hx
129")
130 ;; * Test non-overlapping context lines with matches not at bob/eob.
131 ("x" 1 "\
132a
133bx
134c
135d
136ex
137f
138" "\
c07b2710 1392 matches for \"x\" in buffer: *temp*<2>
dc2d2590
JL
140 :a
141 2:bx
142 :c
143-------
144 :d
145 5:ex
146 :f
147")
148 ;; * Test overlapping context lines with matches at bob/eob.
149 ("x" 2 "\
150ax
151bx
152c
153dx
154e
155f
156gx
157h
158i
159j
160kx
161" "\
c07b2710 1625 matches for \"x\" in buffer: *temp*<2>
dc2d2590
JL
163 1:ax
164 2:bx
165 :c
166 4:dx
167 :e
168 :f
169 7:gx
170 :h
171 :i
172 :j
173 11:kx
174")
175 ;; * Test overlapping context lines with matches not at bob/eob.
176 ("x" 2 "\
177a
178b
179cx
180d
181e
182f
183gx
184h
185i
186" "\
c07b2710 1872 matches for \"x\" in buffer: *temp*<2>
dc2d2590
JL
188 :a
189 :b
190 3:cx
191 :d
192 :e
193 :f
194 7:gx
195 :h
196 :i
197")
198 ;; * Test overlapping context lines with empty first and last line..
199 ("x" 2 "\
200
201b
202cx
203d
204e
205f
206gx
207h
208
209" "\
c07b2710 2102 matches for \"x\" in buffer: *temp*<2>
dc2d2590
JL
211 :
212 :b
213 3:cx
214 :d
215 :e
216 :f
217 7:gx
218 :h
219 :
220")
221 ;; * Test multi-line overlapping context lines.
222 ("x\n.x" 2 "\
223ax
224bx
225c
226d
227ex
228fx
229g
230h
231i
232jx
233kx
234" "\
c07b2710 2353 matches for \"x^J.x\" in buffer: *temp*<2>
dc2d2590
JL
236 1:ax
237 :bx
238 :c
239 :d
240 5:ex
241 :fx
242 :g
243 :h
244 :i
245 10:jx
246 :kx
247")
248 ;; * Test multi-line non-overlapping context lines.
249 ("x\n.x" 2 "\
250ax
251bx
252c
253d
254e
255f
256gx
257hx
258" "\
c07b2710 2592 matches for \"x^J.x\" in buffer: *temp*<2>
dc2d2590
JL
260 1:ax
261 :bx
262 :c
263 :d
264-------
265 :e
266 :f
267 7:gx
268 :hx
269")
270 ;; * Test non-overlapping negative (before-context) lines.
271 ("x" -2 "\
272a
273bx
274c
275d
276e
277fx
278g
279h
280ix
281" "\
c07b2710 2823 matches for \"x\" in buffer: *temp*<2>
dc2d2590
JL
283 :a
284 2:bx
285-------
286 :d
287 :e
288 6:fx
289-------
290 :g
291 :h
292 9:ix
293")
294 ;; * Test overlapping negative (before-context) lines.
295 ("x" -3 "\
296a
297bx
298c
299dx
300e
301f
302gx
303h
304" "\
c07b2710 3053 matches for \"x\" in buffer: *temp*<2>
dc2d2590
JL
306 :a
307 2:bx
308 :c
309 4:dx
310 :e
311 :f
312 7:gx
313")
314
315)
5275ff8b
JL
316 "List of tests for `occur'.
317Each element has the format:
318\(REGEXP NLINES INPUT-BUFFER-STRING OUTPUT-BUFFER-STRING).")
319
c07b2710
JL
320(defun occur-test-case (test)
321 (let ((regexp (nth 0 test))
322 (nlines (nth 1 test))
323 (input-buffer-string (nth 2 test))
324 (output-buffer-string (nth 3 test)))
325 (save-window-excursion
326 (with-temp-buffer
327 (insert input-buffer-string)
328 (occur regexp nlines)
329 (equal output-buffer-string
330 (with-current-buffer "*Occur*"
331 (buffer-string)))))))
332
333(ert-deftest occur-tests ()
334 "Test the functionality of `occur'.
335The test data is in the `occur-tests' constant."
336 (let ((occur-hook nil))
5275ff8b 337 (dolist (test occur-tests)
c07b2710 338 (should (occur-test-case test)))))
5275ff8b 339
c07b2710 340(provide 'occur-tests)
5275ff8b 341
c07b2710 342;;; occur-tests.el ends here