1 ;;; replace-tests.el --- tests for replace.el.
3 ;; Copyright (C) 2010-2017 Free Software Foundation, Inc.
5 ;; Author: Nicolas Richard <youngfrog@members.fsf.org>
6 ;; Author: Juri Linkov <juri@jurta.org>
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/>.
27 (ert-deftest query-replace--split-string-tests
()
28 (let ((sep (propertize "\0" 'separator t
)))
29 (dolist (before '("" "b"))
30 (dolist (after '("" "a"))
32 (query-replace--split-string (concat before sep after
))
35 (query-replace--split-string (concat before
"\0" after
))
36 (concat before
"\0" after
)))))))
38 (defconst replace-occur-tests
40 ;; * Test one-line matches (at bob, eob, bol, eol).
49 6 matches in 5 lines for \"x\" in buffer: *test-occur*
56 ;; * Test multi-line matches, this is the first test from
57 ;; http://lists.gnu.org/archive/html/emacs-devel/2005-06/msg01008.html
58 ;; where numbers are replaced with letters.
66 2 matches for \"a\na\" in buffer: *test-occur*
72 ;; * Test multi-line matches, this is the second test from
73 ;; http://lists.gnu.org/archive/html/emacs-devel/2005-06/msg01008.html
74 ;; where numbers are replaced with letters.
82 2 matches for \"a\nb\" in buffer: *test-occur*
88 ;; * Test line numbers for multi-line matches with empty last match line.
96 2 matches for \"a\n\" in buffer: *test-occur*
102 ;; * Test multi-line matches with 3 match lines.
111 2 matches for \"x\n.x\n\" in buffer: *test-occur*
119 ;; * Test non-overlapping context lines with matches at bob/eob.
130 3 matches for \"x\" in buffer: *test-occur*
141 ;; * Test non-overlapping context lines with matches not at bob/eob.
150 2 matches for \"x\" in buffer: *test-occur*
159 ;; * Test overlapping context lines with matches at bob/eob.
173 5 matches for \"x\" in buffer: *test-occur*
186 ;; * Test overlapping context lines with matches not at bob/eob.
198 2 matches for \"x\" in buffer: *test-occur*
209 ;; * Test overlapping context lines with empty first and last line..
221 2 matches for \"x\" in buffer: *test-occur*
232 ;; * Test multi-line overlapping context lines.
246 3 matches for \"x\n.x\" in buffer: *test-occur*
259 ;; * Test multi-line non-overlapping context lines.
270 2 matches for \"x\n.x\" in buffer: *test-occur*
281 ;; * Test non-overlapping negative (before-context) lines.
293 3 matches for \"x\" in buffer: *test-occur*
305 ;; * Test overlapping negative (before-context) lines.
316 3 matches for \"x\" in buffer: *test-occur*
327 "List of tests for `occur'.
328 Each element has the format:
329 \(REGEXP NLINES INPUT-BUFFER-STRING OUTPUT-BUFFER-STRING).")
331 (defun replace-occur-test-case (test)
332 (let ((regexp (nth 0 test
))
333 (nlines (nth 1 test
))
334 (input-buffer-string (nth 2 test
))
335 (temp-buffer (get-buffer-create " *test-occur*")))
337 (save-window-excursion
338 (with-current-buffer temp-buffer
340 (insert input-buffer-string
)
341 (occur regexp nlines
)
342 (with-current-buffer "*Occur*"
343 (buffer-substring-no-properties (point-min) (point-max)))))
344 (and (buffer-name temp-buffer
)
345 (kill-buffer temp-buffer
)))))
347 (defun replace-occur-test-create (n)
348 "Create a test for element N of the `replace-occur-tests' constant."
349 (let ((testname (intern (format "occur-test-%.2d" n
)))
350 (testdoc (format "Test element %d of `replace-occur-tests'." n
)))
352 `(ert-deftest ,testname
()
354 (let (replace-occur-hook)
355 (should (equal (replace-occur-test-case (nth ,n replace-occur-tests
))
356 (nth 3 (nth ,n replace-occur-tests
)))))))))
358 (dotimes (i (length replace-occur-tests
))
359 (replace-occur-test-create i
))
361 ;;; replace-tests.el ends here