Rename configure.in to configure.ac.
[emacs.git] / test / automated / occur-tests.el
blobeb62688d78821a335a1bc3c342dd89cb6e167ba0
1 ;;; occur-tests.el --- Test suite for occur.
3 ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
5 ;; Author: Juri Linkov <juri@jurta.org>
6 ;; Keywords: matching, internal
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
23 ;;; Code:
25 (require 'ert)
27 (defconst occur-tests
29 ;; * Test one-line matches (at bob, eob, bol, eol).
30 ("x" 0 "\
35 xex
37 " "\
38 5 matches for \"x\" in buffer: *temp*<2>
39 1:xa
40 3:cx
41 4:xd
42 5:xex
43 6:fx
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 "\
54 " "\
55 2 matches for \"a^Ja\" in buffer: *temp*<2>
56 1:a
58 3:a
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 "\
70 " "\
71 2 matches for \"a^Jb\" in buffer: *temp*<2>
72 1:a
74 4:a
77 ;; * Test line numbers for multi-line matches with empty last match line.
78 ("a\n" 0 "\
84 " "\
85 2 matches for \"a^J\" in buffer: *temp*<2>
86 1:a
88 4:a
91 ;; * Test multi-line matches with 3 match lines.
92 ("x\n.x\n" 0 "\
99 " "\
100 2 matches for \"x^J.x^J\" in buffer: *temp*<2>
101 1:ax
104 5:ex
108 ;; * Test non-overlapping context lines with matches at bob/eob.
109 ("x" 1 "\
118 " "\
119 3 matches for \"x\" in buffer: *temp*<2>
120 1:ax
122 -------
124 5:ex
126 -------
128 8:hx
130 ;; * Test non-overlapping context lines with matches not at bob/eob.
131 ("x" 1 "\
138 " "\
139 2 matches for \"x\" in buffer: *temp*<2>
141 2:bx
143 -------
145 5:ex
148 ;; * Test overlapping context lines with matches at bob/eob.
149 ("x" 2 "\
161 " "\
162 5 matches for \"x\" in buffer: *temp*<2>
163 1:ax
164 2:bx
166 4:dx
169 7:gx
173 11:kx
175 ;; * Test overlapping context lines with matches not at bob/eob.
176 ("x" 2 "\
186 " "\
187 2 matches for \"x\" in buffer: *temp*<2>
190 3:cx
194 7:gx
198 ;; * Test overlapping context lines with empty first and last line..
199 ("x" 2 "\
209 " "\
210 2 matches for \"x\" in buffer: *temp*<2>
213 3:cx
217 7:gx
221 ;; * Test multi-line overlapping context lines.
222 ("x\n.x" 2 "\
234 " "\
235 3 matches for \"x^J.x\" in buffer: *temp*<2>
236 1:ax
240 5:ex
245 10:jx
248 ;; * Test multi-line non-overlapping context lines.
249 ("x\n.x" 2 "\
258 " "\
259 2 matches for \"x^J.x\" in buffer: *temp*<2>
260 1:ax
264 -------
267 7:gx
270 ;; * Test non-overlapping negative (before-context) lines.
271 ("x" -2 "\
281 " "\
282 3 matches for \"x\" in buffer: *temp*<2>
284 2:bx
285 -------
288 6:fx
289 -------
292 9:ix
294 ;; * Test overlapping negative (before-context) lines.
295 ("x" -3 "\
304 " "\
305 3 matches for \"x\" in buffer: *temp*<2>
307 2:bx
309 4:dx
312 7:gx
316 "List of tests for `occur'.
317 Each element has the format:
318 \(REGEXP NLINES INPUT-BUFFER-STRING OUTPUT-BUFFER-STRING).")
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)))))))
333 (ert-deftest occur-tests ()
334 "Test the functionality of `occur'.
335 The test data is in the `occur-tests' constant."
336 (let ((occur-hook nil))
337 (dolist (test occur-tests)
338 (should (occur-test-case test)))))
340 (provide 'occur-tests)
342 ;;; occur-tests.el ends here