Handle default value
[emacs.git] / test / occur-testsuite.el
blobd817805dd67fb272fc5b5fbdd309e6798a9886e5
1 ;;; occur-testsuite.el --- Test suite for occur.
3 ;; Copyright (C) 2010 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 ;;; Commentary:
25 ;; Type M-x test-occur RET to test the functionality of `occur'.
27 ;;; Code:
29 (defconst occur-tests
31 ;; * Test one-line matches (at bob, eob, bol, eol).
32 ("x" 0 "\
37 xex
39 " "\
40 5 matches for \"x\" in buffer: *temp*
41 1:xa
42 3:cx
43 4:xd
44 5:xex
45 6:fx
47 ;; * Test multi-line matches, this is the first test from
48 ;; http://lists.gnu.org/archive/html/emacs-devel/2005-06/msg01008.html
49 ;; where numbers are replaced with letters.
50 ("a\na" 0 "\
56 " "\
57 2 matches for \"a^Ja\" in buffer: *temp*
58 1:a
60 3:a
63 ;; * Test multi-line matches, this is the second test from
64 ;; http://lists.gnu.org/archive/html/emacs-devel/2005-06/msg01008.html
65 ;; where numbers are replaced with letters.
66 ("a\nb" 0 "\
72 " "\
73 2 matches for \"a^Jb\" in buffer: *temp*
74 1:a
76 4:a
79 ;; * Test line numbers for multi-line matches with empty last match line.
80 ("a\n" 0 "\
86 " "\
87 2 matches for \"a^J\" in buffer: *temp*
88 1:a
90 4:a
93 ;; * Test multi-line matches with 3 match lines.
94 ("x\n.x\n" 0 "\
101 " "\
102 2 matches for \"x^J.x^J\" in buffer: *temp*
103 1:ax
106 5:ex
111 "List of tests for `occur'.
112 Each element has the format:
113 \(REGEXP NLINES INPUT-BUFFER-STRING OUTPUT-BUFFER-STRING).")
115 (defun test-occur ()
116 (interactive)
117 (let ((count 1)
118 failed
119 (occur-hook nil))
120 (dolist (test occur-tests)
121 (let ((regexp (nth 0 test))
122 (nlines (nth 1 test))
123 (input-buffer-string (nth 2 test))
124 (output-buffer-string (nth 3 test)))
125 (save-excursion
126 (with-temp-buffer
127 (insert input-buffer-string)
128 (occur regexp nlines)
129 (unless (equal output-buffer-string
130 (with-current-buffer "*Occur*"
131 (buffer-string)))
132 (setq failed (cons count failed))))))
133 (setq count (1+ count)))
134 (if failed
135 (message "FAILED TESTS: %S" (reverse failed))
136 (message "SUCCESS"))))
138 (provide 'occur-testsuite)
140 ;;; occur-testsuite.el ends here