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/>.
29 ;; * Test one-line matches (at bob, eob, bol, eol).
38 5 matches for \"x\" in buffer: *test-occur*
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.
55 2 matches for \"a^Ja\" in buffer: *test-occur*
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.
71 2 matches for \"a^Jb\" in buffer: *test-occur*
77 ;; * Test line numbers for multi-line matches with empty last match line.
85 2 matches for \"a^J\" in buffer: *test-occur*
91 ;; * Test multi-line matches with 3 match lines.
100 2 matches for \"x^J.x^J\" in buffer: *test-occur*
108 ;; * Test non-overlapping context lines with matches at bob/eob.
119 3 matches for \"x\" in buffer: *test-occur*
130 ;; * Test non-overlapping context lines with matches not at bob/eob.
139 2 matches for \"x\" in buffer: *test-occur*
148 ;; * Test overlapping context lines with matches at bob/eob.
162 5 matches for \"x\" in buffer: *test-occur*
175 ;; * Test overlapping context lines with matches not at bob/eob.
187 2 matches for \"x\" in buffer: *test-occur*
198 ;; * Test overlapping context lines with empty first and last line..
210 2 matches for \"x\" in buffer: *test-occur*
221 ;; * Test multi-line overlapping context lines.
235 3 matches for \"x^J.x\" in buffer: *test-occur*
248 ;; * Test multi-line non-overlapping context lines.
259 2 matches for \"x^J.x\" in buffer: *test-occur*
270 ;; * Test non-overlapping negative (before-context) lines.
282 3 matches for \"x\" in buffer: *test-occur*
294 ;; * Test overlapping negative (before-context) lines.
305 3 matches for \"x\" in buffer: *test-occur*
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 (temp-buffer (get-buffer-create " *test-occur*")))
327 (save-window-excursion
328 (with-current-buffer temp-buffer
330 (insert input-buffer-string
)
331 (occur regexp nlines
)
332 (equal output-buffer-string
333 (with-current-buffer "*Occur*"
335 (and (buffer-name temp-buffer
)
336 (kill-buffer temp-buffer
)))))
338 (ert-deftest occur-tests
()
339 "Test the functionality of `occur'.
340 The test data is in the `occur-tests' constant."
341 (let ((occur-hook nil
))
342 (dolist (test occur-tests
)
343 (should (occur-test-case test
)))))
345 (provide 'occur-tests
)
347 ;;; occur-tests.el ends here