emacs/test/lisp/replace-tests.el

717 lines
19 KiB
EmacsLisp
Raw Normal View History

;;; replace-tests.el --- tests for replace.el. -*- lexical-binding:t -*-
;; Copyright (C) 2010-2025 Free Software Foundation, Inc.
;; Author: Nicolas Richard <youngfrog@members.fsf.org>
;; Author: Juri Linkov <juri@jurta.org>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Code:
(require 'ert)
(eval-when-compile (require 'subr-x))
(ert-deftest query-replace--split-string-tests ()
(let ((sep (propertize "\0" 'separator t)))
(dolist (before '("" "b"))
(dolist (after '("" "a"))
(should (equal
(query-replace--split-string (concat before sep after))
(cons before after)))
(should (equal
(query-replace--split-string (concat before "\0" after))
(concat before "\0" after)))))))
(defconst replace-occur-tests
'(
;; * Test one-line matches (at bob, eob, bol, eol).
("x" 0 "\
xa
b
cx
xd
xex
fx
" "\
6 matches in 5 lines for \"x\" in buffer: *test-occur*
1:xa
3:cx
4:xd
5:xex
6:fx
")
;; * Test multi-line matches, this is the first test from
;; https://lists.gnu.org/r/emacs-devel/2005-06/msg01008.html
;; where numbers are replaced with letters.
("a\na" 0 "\
a
a
a
a
a
" "\
2 matches for \"a\na\" in buffer: *test-occur*
1:a
:a
3:a
:a
")
;; * Test multi-line matches, this is the second test from
;; https://lists.gnu.org/r/emacs-devel/2005-06/msg01008.html
;; where numbers are replaced with letters.
("a\nb" 0 "\
a
b
c
a
b
" "\
2 matches for \"a\nb\" in buffer: *test-occur*
1:a
:b
4:a
:b
")
;; * Test line numbers for multi-line matches with empty last match line.
("a\n" 0 "\
a
c
a
" "\
2 matches for \"a\n\" in buffer: *test-occur*
1:a
:
4:a
:
")
;; * Test multi-line matches with 3 match lines.
("x\n.x\n" 0 "\
ax
bx
c
d
ex
fx
" "\
2 matches for \"x\n.x\n\" in buffer: *test-occur*
1:ax
:bx
:c
5:ex
:fx
:
")
;; * Test non-overlapping context lines with matches at bob/eob.
("x" 1 "\
ax
b
c
d
ex
f
g
hx
" "\
3 matches for \"x\" in buffer: *test-occur*
1:ax
:b
-------
:d
5:ex
:f
-------
:g
8:hx
")
;; * Test non-overlapping context lines with matches not at bob/eob.
("x" 1 "\
a
bx
c
d
ex
f
" "\
2 matches for \"x\" in buffer: *test-occur*
:a
2:bx
:c
-------
:d
5:ex
:f
")
;; * Test overlapping context lines with matches at bob/eob.
("x" 2 "\
ax
bx
c
dx
e
f
gx
h
i
j
kx
" "\
5 matches for \"x\" in buffer: *test-occur*
1:ax
2:bx
:c
4:dx
:e
:f
7:gx
:h
:i
:j
11:kx
")
;; * Test overlapping context lines with matches not at bob/eob.
("x" 2 "\
a
b
cx
d
e
f
gx
h
i
" "\
2 matches for \"x\" in buffer: *test-occur*
:a
:b
3:cx
:d
:e
:f
7:gx
:h
:i
")
;; * Test overlapping context lines with empty first and last line..
("x" 2 "\
b
cx
d
e
f
gx
h
" "\
2 matches for \"x\" in buffer: *test-occur*
:
:b
3:cx
:d
:e
:f
7:gx
:h
:
")
;; * Test multi-line overlapping context lines.
("x\n.x" 2 "\
ax
bx
c
d
ex
fx
g
h
i
jx
kx
" "\
3 matches for \"x\n.x\" in buffer: *test-occur*
1:ax
:bx
:c
:d
5:ex
:fx
:g
:h
:i
10:jx
:kx
")
;; * Test multi-line non-overlapping context lines.
("x\n.x" 2 "\
ax
bx
c
d
e
f
gx
hx
" "\
2 matches for \"x\n.x\" in buffer: *test-occur*
1:ax
:bx
:c
:d
-------
:e
:f
7:gx
:hx
")
;; * Test non-overlapping negative (before-context) lines.
("x" -2 "\
a
bx
c
d
e
fx
g
h
ix
" "\
3 matches for \"x\" in buffer: *test-occur*
:a
2:bx
-------
:d
:e
6:fx
-------
:g
:h
9:ix
")
;; * Test overlapping negative (before-context) lines.
("x" -3 "\
a
bx
c
dx
e
f
gx
h
" "\
3 matches for \"x\" in buffer: *test-occur*
:a
2:bx
:c
4:dx
:e
:f
7:gx
")
)
"List of tests for `occur'.
Each element has the format:
\(REGEXP NLINES INPUT-BUFFER-STRING OUTPUT-BUFFER-STRING).")
(defun replace-occur-test-case (test)
(let ((regexp (nth 0 test))
(nlines (nth 1 test))
(input-buffer-string (nth 2 test))
(temp-buffer (get-buffer-create " *test-occur*")))
(unwind-protect
(save-window-excursion
(with-current-buffer temp-buffer
(erase-buffer)
(insert input-buffer-string)
(occur regexp nlines)
(with-current-buffer "*Occur*"
(buffer-substring-no-properties (point-min) (point-max)))))
(and (buffer-name temp-buffer)
(kill-buffer temp-buffer)))))
(defun replace-occur-test-create (n)
"Create a test for element N of the `replace-occur-tests' constant."
(let ((testname (intern (format "occur-test-%.2d" n)))
(testdoc (format "Test element %d of `replace-occur-tests'." n)))
(eval
`(ert-deftest ,testname ()
,testdoc
(let (replace-occur-hook)
(should (equal (replace-occur-test-case (nth ,n replace-occur-tests))
(nth 3 (nth ,n replace-occur-tests)))))))))
(dotimes (i (length replace-occur-tests))
(replace-occur-test-create i))
(ert-deftest replace-occur-revert-bug32543 ()
"Test `occur-revert' with non-nil `list-matching-lines-jump-to-current-line'."
(let ((temp-buffer (get-buffer-create " *test-occur*")))
(unwind-protect
(save-window-excursion
(with-current-buffer temp-buffer
(erase-buffer)
(setq list-matching-lines-jump-to-current-line t)
(insert
";; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.
")
(occur "and")
(with-current-buffer "*Occur*"
(revert-buffer)
(goto-char (point-min))
(should (string-match "\\`2 matches for \"and\" in buffer: "
(buffer-substring-no-properties
Prefer pos-bol and pos-eol in tests * test/lisp/calendar/todo-mode-tests.el (todo-test-toggle-item-header02, todo-test-edit-item-date-month) (todo-test-multiline-item-indentation-1) (todo-test-multiline-item-indentation-2) (todo-test-multiline-item-indentation-3): * test/lisp/cedet/semantic-utest-ia.el (semantic-ia-utest-buffer) (semantic-sr-utest-buffer-refs): * test/lisp/cedet/semantic-utest.el (semantic-utest-kill-indicator) (semantic-utest-unkill-indicator): * test/lisp/dired-tests.el (dired-test-bug27968): * test/lisp/emacs-lisp/backtrace-tests.el (backtrace-tests--verify-single-and-multi-line): * test/lisp/emacs-lisp/find-func-tests.el (find-func-tests--find-library-verbose): * test/lisp/erc/erc-tests.el (erc-ring-previous-command) (erc-log-irc-protocol): * test/lisp/gnus/message-tests.el (message-mode-propertize): * test/lisp/info-xref-tests.el (info-xref-test-emacs-manuals): * test/lisp/mail/footnote-tests.el (footnote-tests-same-place): * test/lisp/progmodes/elisp-mode-tests.el (elisp-shorthand-completion-at-point): * test/lisp/progmodes/f90-tests.el (f90-test-bug38415): * test/lisp/progmodes/python-tests.el (python-indent-electric-comma-inside-multiline-string) (python-indent-electric-comma-after-multiline-string) (python-indent-electric-colon-1, python-indent-electric-colon-2) (python-indent-electric-colon-3, python-indent-electric-colon-4) (python-mark-defun-2, python-mark-defun-3, python-mark-defun-4) (python-mark-defun-5, python-nav-end-of-defun-2) (python-nav-end-of-statement-1, python-nav-end-of-block-1) (python-indent-dedent-line-backspace-2) (python-indent-dedent-line-backspace-3) (python-eldoc--get-symbol-at-point-1) (python-info-beginning-of-statement-p-1) (python-info-beginning-of-statement-p-2): * test/lisp/replace-tests.el (replace-occur-revert-bug32543) (replace-occur-revert-bug32987): * test/lisp/simple-tests.el (simple-delete-indentation-boundaries) (simple-delete-indentation-region) (line-number-at-pos-in-narrow-buffer) (line-number-at-pos-keeps-restriction): * test/lisp/textmodes/css-mode-tests.el (css-mode-test-selectors) (scss-mode-test-selectors): * test/lisp/textmodes/fill-tests.el (fill-test-unbreakable-paragraph) (fill-test-breakable-paragraph): * test/lisp/time-stamp-tests.el (time-stamp-custom-pattern): * test/src/lread-tests.el (lread-tests--last-message): * test/src/process-tests.el (set-process-filter-t): * test/src/undo-tests.el (undo-test-skip-invalidated-markers): Prefer pos-bol and pos-eol.
2022-08-21 17:33:55 +02:00
(point) (pos-eol)))))))
(and (buffer-name temp-buffer)
(kill-buffer temp-buffer)))))
(ert-deftest replace-occur-revert-bug32987 ()
"Test `occur-revert' with non-nil `list-matching-lines-jump-to-current-line'."
(let ((temp-buffer (get-buffer-create " *test-occur*")))
(unwind-protect
(save-window-excursion
(with-current-buffer temp-buffer
(erase-buffer)
(setq list-matching-lines-jump-to-current-line nil)
(insert
";; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.
")
(occur "and")
(with-current-buffer "*Occur*"
(revert-buffer)
(goto-char (point-min))
(should (string-match "\\`2 matches for \"and\" in buffer: "
(buffer-substring-no-properties
Prefer pos-bol and pos-eol in tests * test/lisp/calendar/todo-mode-tests.el (todo-test-toggle-item-header02, todo-test-edit-item-date-month) (todo-test-multiline-item-indentation-1) (todo-test-multiline-item-indentation-2) (todo-test-multiline-item-indentation-3): * test/lisp/cedet/semantic-utest-ia.el (semantic-ia-utest-buffer) (semantic-sr-utest-buffer-refs): * test/lisp/cedet/semantic-utest.el (semantic-utest-kill-indicator) (semantic-utest-unkill-indicator): * test/lisp/dired-tests.el (dired-test-bug27968): * test/lisp/emacs-lisp/backtrace-tests.el (backtrace-tests--verify-single-and-multi-line): * test/lisp/emacs-lisp/find-func-tests.el (find-func-tests--find-library-verbose): * test/lisp/erc/erc-tests.el (erc-ring-previous-command) (erc-log-irc-protocol): * test/lisp/gnus/message-tests.el (message-mode-propertize): * test/lisp/info-xref-tests.el (info-xref-test-emacs-manuals): * test/lisp/mail/footnote-tests.el (footnote-tests-same-place): * test/lisp/progmodes/elisp-mode-tests.el (elisp-shorthand-completion-at-point): * test/lisp/progmodes/f90-tests.el (f90-test-bug38415): * test/lisp/progmodes/python-tests.el (python-indent-electric-comma-inside-multiline-string) (python-indent-electric-comma-after-multiline-string) (python-indent-electric-colon-1, python-indent-electric-colon-2) (python-indent-electric-colon-3, python-indent-electric-colon-4) (python-mark-defun-2, python-mark-defun-3, python-mark-defun-4) (python-mark-defun-5, python-nav-end-of-defun-2) (python-nav-end-of-statement-1, python-nav-end-of-block-1) (python-indent-dedent-line-backspace-2) (python-indent-dedent-line-backspace-3) (python-eldoc--get-symbol-at-point-1) (python-info-beginning-of-statement-p-1) (python-info-beginning-of-statement-p-2): * test/lisp/replace-tests.el (replace-occur-revert-bug32543) (replace-occur-revert-bug32987): * test/lisp/simple-tests.el (simple-delete-indentation-boundaries) (simple-delete-indentation-region) (line-number-at-pos-in-narrow-buffer) (line-number-at-pos-keeps-restriction): * test/lisp/textmodes/css-mode-tests.el (css-mode-test-selectors) (scss-mode-test-selectors): * test/lisp/textmodes/fill-tests.el (fill-test-unbreakable-paragraph) (fill-test-breakable-paragraph): * test/lisp/time-stamp-tests.el (time-stamp-custom-pattern): * test/src/lread-tests.el (lread-tests--last-message): * test/src/process-tests.el (set-process-filter-t): * test/src/undo-tests.el (undo-test-skip-invalidated-markers): Prefer pos-bol and pos-eol.
2022-08-21 17:33:55 +02:00
(point) (pos-eol)))))))
(and (buffer-name temp-buffer)
(kill-buffer temp-buffer)))))
;;; General tests for `query-replace' and `query-replace-regexp'.
(defconst query-replace-tests
'(
;; query-replace
("aaa" "M-% a RET 1 RET !" "111")
("aaa" "M-% a RET 1 RET y n y" "1a1")
;; Empty inputs
("aaa" "M-% a RET RET !" "")
("aaa" "M-% RET 1 RET !" "1a1a1a")
("aaa" "M-% RET RET !" "aaa")
;; Reuse the previous default
("aaa" "M-% a RET 1 RET . M-% RET !" "111")
;; query-replace-regexp
("aaa" "C-M-% a* RET 1 RET !" "1")
;; Empty inputs
("aaa" "C-M-% a* RET RET !" "")
("aaa" "C-M-% RET 1 RET !" "1a1a1a")
("aaa" "C-M-% RET RET !" "aaa")
;; Empty matches
("aaa" "C-M-% b* RET 1 RET !" "1a1a1a")
;; Complete matches
("aaa" "C-M-% .* RET 1 RET !" "1")
;; Adjacent non-empty matches
("abaab" "C-M-% ab* RET 12 RET !" "121212")
;; Adjacent non-empty and empty matches
("abab" "C-M-% a* RET 1 RET !" "1b1b")
("abab" "C-M-% b* RET 1 RET !" "1a1a1")
;; Test case from commit 5632eb272c7
("a a a " "C-M-% \\ba SPC RET c RET !" "ccc") ; not "ca c"
))
(defun query-replace--run-tests (tests)
(with-temp-buffer
(save-window-excursion
;; `execute-kbd-macro' is applied to window only
(set-window-buffer nil (current-buffer))
(dolist (case tests)
;; Ensure empty input means empty string to replace:
(setq query-replace-defaults nil)
(delete-region (point-min) (point-max))
(insert (nth 0 case))
(goto-char (point-min))
(execute-kbd-macro (kbd (nth 1 case)))
(should (equal (buffer-string) (nth 2 case)))))))
(ert-deftest query-replace-tests ()
(query-replace--run-tests query-replace-tests))
(ert-deftest query-replace-search-function-tests ()
(let* ((replace-re-search-function #'re-search-forward))
(query-replace--run-tests query-replace-tests))
(let* ((pairs '((1 . 2) (3 . 4)))
(replace-re-search-function
(lambda (string &optional _bound noerror count)
(let (found)
(while (and (not found) pairs)
(goto-char (caar pairs))
(when (re-search-forward string (cdar pairs) noerror count)
(setq found t))
(pop pairs))
found)))
(tests
'(
;; FIXME: this test should pass after fixing bug#54733:
;; ("aaaa" "C-M-% .* RET 1 RET !" "1a1a")
)))
(query-replace--run-tests tests)))
;;; General tests for `perform-replace'.
(defconst perform-replace-tests
'(
;; Test case from commit 5632eb272c7
("a a a " "\\ba " "c" nil t nil nil nil nil nil nil nil "ccc") ; not "ca c"
;; The same with region inside the second match
;; FIXME: this test should pass after fixing bug#54733:
;; ("a a a " "\\ba " "c" nil t nil nil nil 1 4 nil nil "ca a ")
))
(defun perform-replace--run-tests (tests)
(with-temp-buffer
(dolist (case tests)
(delete-region (point-min) (point-max))
(insert (pop case))
(goto-char (point-min))
(apply 'perform-replace (butlast case))
(should (equal (buffer-string) (car (last case)))))))
(ert-deftest perform-replace-tests ()
(perform-replace--run-tests perform-replace-tests))
;;; Tests for `query-replace' undo feature.
(defvar replace-tests-bind-read-string nil
"A string to bind `read-string' and avoid the prompt.")
(defvar replace-tests-perform-replace-regexp-flag t
"Value for regexp-flag argument passed to `perform-replace' in undo tests.")
(defmacro replace-tests-with-undo (input from to char-nums def-chr &rest body)
"Helper to test `query-replace' undo feature.
INPUT is a string to insert in a temporary buffer.
FROM is the string to match and replace.
TO is the replacement string.
CHAR-NUMS is a list of elements (CHAR . NUMS), where CHAR is
one of the characters `,', `?\\s', `u', `U', `E' or `q'
and NUMS a list of integers.
DEF-CHAR is the character `?\\s' or `q'.
BODY is a list of forms to evaluate.
Use CHAR-NUMS and DEF-CHAR to temporary bind the function value of
`read-event', thus avoiding the prompt.
For instance, if CHAR-NUMS is the lists ((?\\s . (1 2 3)) (?u . (4))),
then replace 3 matches of FROM with TO, and undo the last replacement.
Return the last evalled form in BODY."
(declare (indent 5) (debug (stringp stringp stringp form characterp body)))
(cl-with-gensyms (text count)
`(let* ((,text ,input)
(,count 0)
(inhibit-message t))
(with-temp-buffer
(insert ,text)
(goto-char 1)
;; Bind `read-event' to simulate user input.
;; If `replace-tests-bind-read-string' is non-nil, then
;; bind `read-string' as well.
(cl-letf (((symbol-function 'read-key)
(lambda (&rest _args)
Prefer incf to cl-incf in tests * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-reify-function): * test/lisp/emacs-lisp/cl-extra-tests.el (cl-getf): * test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs-loop-for-as-arith-order-side-effects) (cl-macs-loop-for-as-equals-then, cl-macs-loop-do, cl-macs-loop-finally) (cl-macs-loop-in-ref, cl-macs-loop-being-elements-of-ref) (cl-macs-test--symbol-macrolet, cl-the): * test/lisp/emacs-lisp/cl-seq-tests.el (cl-lib-test-remove) (cl-lib-test-remove-if-not): * test/lisp/emacs-lisp/edebug-resources/edebug-test-code.el (edebug-test-code-range): * test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-deduplicate): * test/lisp/emacs-lisp/generator-tests.el (cps-while-incf): (cps-test-iter-cleanup-once-only): * test/lisp/emacs-lisp/hierarchy-tests.el (hierarchy-labelfn-button-if-does-not-button-unless-condition) (hierarchy-labelfn-button-if-does-button-when-condition): * test/lisp/emacs-lisp/let-alist-tests.el (let-alist-evaluate-once): * test/lisp/emacs-lisp/lisp-mode-tests.el (indent-sexp, lisp-indent-region): * test/lisp/emacs-lisp/map-tests.el (test-map-elt-gv) (test-setf-map-with-function): * test/lisp/emacs-lisp/multisession-tests.el (multi-test-sqlite-simple) (multi-test-sqlite-busy, multi-test-files-simple) (multi-test-files-busy): * test/lisp/emacs-lisp/oclosure-tests.el (oclosure-test, oclosure-test-mutate): * test/lisp/emacs-lisp/track-changes-tests.el (track-changes-tests--random): * test/lisp/files-tests.el (files-tests--with-buffer-offer-save): * test/lisp/net/shr-tests.el (shr-test/zoom-image): * test/lisp/replace-tests.el (replace-tests-with-undo): * test/src/buffer-tests.el (test-overlay-randomly): * test/src/data-tests.el (test-bool-vector-bv-from-hex-string): * test/src/fns-tests.el (fns-tests-sort): * test/src/json-tests.el (json-insert/signal, json-insert/throw): * test/src/minibuf-tests.el (minibuf-tests--strings-to-symbol-alist) (minibuf-tests--strings-to-string-alist) (minibuf-tests--strings-to-string-hashtable) (minibuf-tests--strings-to-symbol-hashtable): * test/src/process-tests.el (make-process/file-handler/found): Prefer incf to cl-incf.
2025-02-22 19:14:51 +01:00
(incf ,count)
(pcase ,count ; Build the clauses from CHAR-NUMS
,@(append
(delq nil
(mapcar
(lambda (chr)
Mark if-let and when-let obsolete * lisp/subr.el (if-let*, when-let*, if-let, when-let): Mark if-let and when-let obsolete (bug#73853 and elsewhere). Move docstring text around so that if-let* and when-let* descriptions no longer refer to if-let and when-let. * etc/NEWS: Announce the change. * admin/admin.el (reminder-for-release-blocking-bugs): * doc/misc/erc.texi (display-buffer): * lisp/ansi-color.el (ansi-color-apply) (ansi-color--face-vec-face): * lisp/ansi-osc.el (ansi-osc-apply-on-region) (ansi-osc-hyperlink): * lisp/arc-mode.el (archive-goto-file) (archive-next-file-displayer): * lisp/auth-source-pass.el (auth-source-pass-search) (auth-source-pass--parse-data) (auth-source-pass--find-match-many): * lisp/autorevert.el (auto-revert-notify-rm-watch): * lisp/buff-menu.el (Buffer-menu-unmark-all-buffers) (Buffer-menu-group-by-root): * lisp/calendar/parse-time.el (parse-iso8601-time-string): * lisp/cedet/pulse.el (pulse-tick): * lisp/comint.el (comint--fontify-input-ppss-flush-indirect) (comint--intersect-regions): * lisp/completion-preview.el (completion-preview--try-table) (completion-preview--capf-wrapper, completion-preview--update): * lisp/cus-edit.el (setopt--set) (custom-dirlocals-maybe-update-cons, custom-dirlocals-validate): * lisp/custom.el (load-theme): * lisp/descr-text.el (describe-char): * lisp/desktop.el (desktop--emacs-pid-running-p): * lisp/dired-x.el (menu): * lisp/dired.el (dired-font-lock-keywords) (dired-insert-directory, dired--insert-disk-space, dired-mode): * lisp/dnd.el (dnd-handle-multiple-urls): * lisp/dom.el (dom-remove-attribute): * lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): * lisp/emacs-lisp/bytecomp.el (bytecomp--custom-declare): * lisp/emacs-lisp/comp-common.el (comp-function-type-spec): * lisp/emacs-lisp/comp-cstr.el (comp--all-classes) (comp-cstr-set-range-for-arithm, comp--cstr-union-1-no-mem) (comp-cstr-intersection-no-mem, comp-cstr-fixnum-p) (comp-cstr-type-p): * lisp/emacs-lisp/comp-run.el (comp-subr-trampoline-install) (native--compile-async): * lisp/emacs-lisp/comp.el (comp--get-function-cstr) (comp--function-pure-p, comp--intern-func-in-ctxt) (comp--addr-to-bb-name, comp--emit-assume, comp--maybe-add-vmvar) (comp--add-call-cstr, comp--compute-dominator-tree) (comp--dom-tree-walker, comp--ssa-rename) (comp--function-call-maybe-fold, comp--fwprop-call) (comp--call-optim-func): * lisp/emacs-lisp/edebug.el (edebug-global-prefix) (edebug-remove-instrumentation): * lisp/emacs-lisp/eieio.el (initialize-instance): * lisp/emacs-lisp/ert-x.el (ert-resource-directory): * lisp/emacs-lisp/ert.el (ert--expand-should-1) (ert-test-location, ert-write-junit-test-report) (ert-test--erts-test): * lisp/emacs-lisp/icons.el (icon-complete-spec, icon-string) (icons--create): * lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p): * lisp/emacs-lisp/loaddefs-gen.el (loaddefs-generate--make-autoload) (loaddefs-generate--parse-file): * lisp/emacs-lisp/multisession.el (multisession-edit-mode--revert, multisession-edit-value): * lisp/emacs-lisp/package-vc.el (package-vc--read-archive-data) (package-vc--version, package-vc--clone): * lisp/emacs-lisp/package.el (package--reload-previously-loaded): * lisp/emacs-lisp/pp.el (pp--insert-lisp): * lisp/emacs-lisp/subr-x.el (add-display-text-property): * lisp/emacs-lisp/tabulated-list.el (tabulated-list-print): * lisp/emacs-lisp/timer.el (run-at-time): * lisp/emacs-lisp/vtable.el (vtable-goto-table) (vtable-goto-column, vtable-update-object, vtable--insert-line) (vtable--compute-widths, vtable--make-keymap): * lisp/emacs-lisp/warnings.el (display-warning): * lisp/epa-file.el (epa-file-insert-file-contents): * lisp/epa.el (epa-show-key): * lisp/erc/erc-backend.el (erc--split-line, erc--conceal-prompt) (PRIVMSG, erc--get-isupport-entry): * lisp/erc/erc-button.el (erc-button-add-nickname-buttons) (erc--button-next): * lisp/erc/erc-common.el (erc--find-group): * lisp/erc/erc-fill.el (erc-fill, erc-fill-static) (erc-fill--wrap-escape-hidden-speaker) (erc-fill--wrap-unmerge-on-date-stamp) (erc-fill--wrap-massage-initial-message-post-clear) (erc-fill-wrap, erc-fill--wrap-rejigger-region): * lisp/erc/erc-goodies.el (erc--scrolltobottom-all) (erc--keep-place-indicator-on-window-buffer-change) (keep-place-indicator, erc--keep-place-indicator-adjust-on-clear) (erc-keep-place-move, erc--command-indicator-display): * lisp/erc/erc-ibuffer.el (erc-members): * lisp/erc/erc-join.el (erc-join--remove-requested-channel) (erc-autojoin--join): * lisp/erc/erc-networks.el (erc-networks--id-qualifying-init-parts, erc-networks--id-reload) (erc-networks--id-ensure-comparable) (erc-networks--reclaim-orphaned-target-buffers) (erc-networks--server-select): * lisp/erc/erc-nicks.el (erc-nicks-invert) (erc-nicks--redirect-face-widget-link, erc-nicks--highlight) (erc-nicks--highlight-button) (erc-nicks--list-faces-help-button-action, erc-nicks-list-faces) (erc-nicks-refresh, erc-nicks--colors-from-faces) (erc-nicks--track-prioritize) (erc-nicks--remember-face-for-track): * lisp/erc/erc-notify.el (querypoll, erc--querypoll-get-next) (erc--querypoll-on-352, erc--querypoll-send): * lisp/erc/erc-sasl.el (erc-sasl--read-password): * lisp/erc/erc-services.el (erc-services-issue-ghost-and-retry-nick): * lisp/erc/erc-speedbar.el (erc-speedbar--ensure, nickbar) (erc-speedbar-toggle-nicknames-window-lock) (erc-speedbar--compose-nicks-face): * lisp/erc/erc-stamp.el (erc-stamp--recover-on-reconnect) (erc-stamp-prefix-log-filter, erc--conceal-prompt) (erc--insert-timestamp-left, erc-insert-timestamp-right) (erc-stamp--defer-date-insertion-on-post-modify) (erc-insert-timestamp-left-and-right) (erc-stamp--redo-right-stamp-post-clear) (erc-stamp--reset-on-clear, erc-stamp--dedupe-date-stamps): * lisp/erc/erc-status-sidebar.el (bufbar) (erc-status-sidebar-prefer-target-as-name) (erc-status-sidebar-default-allsort, erc-status-sidebar-click): * lisp/erc/erc-track.el (erc-track--shortened-names-get) (erc-track--setup, erc-track--select-mode-line-face) (erc-track-modified-channels, erc-track--collect-faces-in) (erc-track--switch-buffer, erc-track--replace-killed-buffer): * lisp/erc/erc-truncate.el (erc-truncate--setup) (erc-truncate-buffer): * lisp/erc/erc.el (erc--ensure-query-member) (erc--ensure-query-members, erc--remove-channel-users-but) (erc--cusr-change-status, erc--find-mode, erc--update-modules) (erc-log-irc-protocol, erc--refresh-prompt) (erc--restore-important-text-props) (erc--order-text-properties-from-hash, erc-send-input-line) (erc-cmd-IGNORE, erc--unignore-user, erc-cmd-QUERY) (erc-cmd-BANLIST, erc--speakerize-nick) (erc--format-speaker-input-message, erc-channel-receive-names) (erc-send-current-line, erc-format-target-and/or-network) (erc-kill-buffer-function, erc-restore-text-properties) (erc--get-eq-comparable-cmd): * lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias--which) (eshell-maybe-replace-by-alias): * lisp/eshell/em-glob.el (eshell-glob-convert): * lisp/eshell/em-pred.el (eshell-pred-user-or-group) (eshell-pred-file-time, eshell-pred-file-type) (eshell-pred-file-mode, eshell-pred-file-links) (eshell-pred-file-size): * lisp/eshell/em-prompt.el (eshell-forward-paragraph) (eshell-next-prompt): * lisp/eshell/esh-arg.el (eshell-resolve-current-argument): * lisp/eshell/esh-cmd.el (eshell-do-eval, eshell/which) (eshell-plain-command--which, eshell-plain-command): * lisp/eshell/esh-io.el (eshell-duplicate-handles) (eshell-protect-handles, eshell-get-target, eshell-close-target): * lisp/eshell/esh-proc.el (eshell-sentinel): * lisp/eshell/esh-var.el (eshell-parse-variable-ref) (eshell-get-variable, eshell-set-variable): * lisp/faces.el (face-at-point): * lisp/ffap.el (ffap-in-project): * lisp/filenotify.el (file-notify--rm-descriptor): * lisp/files-x.el (read-dir-locals-file) (connection-local-update-profile-variables) (connection-local-value): * lisp/files.el (file-remote-p, abbreviate-file-name) (set-auto-mode, hack-local-variables) (revert-buffer-restore-read-only): * lisp/find-dired.el (find-dired-sort-by-filename): * lisp/font-lock.el (font-lock--filter-keywords): * lisp/gnus/gnus-art.el (article-emojize-symbols): * lisp/gnus/gnus-int.el (gnus-close-server): * lisp/gnus/gnus-search.el (gnus-search-transform) (gnus-search-indexed-parse-output, gnus-search-server-to-engine): * lisp/gnus/gnus-sum.el (gnus-collect-urls, gnus-shorten-url): * lisp/gnus/gnus.el (gnus-check-backend-function): * lisp/gnus/message.el (message-send-mail): * lisp/gnus/mml.el (mml-generate-mime, mml-insert-mime-headers): * lisp/gnus/nnatom.el (nnatom--read-feed, nnatom--read-article) (nnatom--read-article-or-group-authors, nnatom--read-publish) (nnatom--read-update, nnatom--read-links): * lisp/gnus/nnfeed.el (nnfeed--read-server, nnfeed--write-server) (nnfeed--parse-feed, nnfeed--group-data, nnfeed-retrieve-article) (nnfeed-retrieve-headers, nnfeed--print-part) (nnfeed-request-article, nnfeed-request-group) (nnfeed-request-list, nnfeed--group-description) (nnfeed-request-group-description) (nnfeed-request-list-newsgroups, nnfeed-request-rename-group): * lisp/gnus/nnmh.el (nnmh-update-gnus-unreads): * lisp/help-fns.el (help-find-source) (help-fns--insert-menu-bindings, help-fns--mention-first-release) (help-fns--mention-shortdoc-groups) (help-fns--customize-variable-version) (help-fns--face-custom-version-info, describe-mode): * lisp/help-mode.el (help-make-xrefs): * lisp/help.el (help-key-description, help--describe-command): * lisp/hfy-cmap.el (htmlfontify-load-rgb-file): * lisp/ibuf-ext.el (ibuffer-jump-to-filter-group) (ibuffer-kill-filter-group, ibuffer-kill-line) (ibuffer-save-filter-groups, ibuffer-save-filters, filename) (basename, file-extension, ibuffer-diff-buffer-with-file-1) (ibuffer-mark-by-file-name-regexp) (ibuffer-mark-by-content-regexp): * lisp/ibuf-macs.el (ibuffer-aif, ibuffer-awhen): * lisp/ibuffer.el (ibuffer-mouse-toggle-mark) (ibuffer-toggle-marks, ibuffer-mark-interactive) (ibuffer-compile-format, process, ibuffer-map-lines): * lisp/image.el (image--compute-map) (image--compute-original-map): * lisp/image/exif.el (exif-parse-buffer): * lisp/image/image-converter.el (image-convert-p, image-convert) (image-converter--find-converter): * lisp/image/image-dired-util.el (image-dired-file-name-at-point): * lisp/image/image-dired.el (image-dired-track-original-file) (image-dired--on-file-in-dired-buffer) (image-dired--with-thumbnail-buffer) (image-dired-jump-original-dired-buffer) (image-dired--slideshow-step, image-dired-display-image): * lisp/image/wallpaper.el (wallpaper--init-action-kill) (wallpaper--find-setter, wallpaper--find-command) (wallpaper--find-command-args, wallpaper--x-monitor-name): * lisp/info-look.el (info-lookup-interactive-arguments) (info-complete)::(:mode): * lisp/info.el (info-pop-to-buffer, Info-read-node-name-1): * lisp/international/emoji.el (emoji--adjust-displayable-1) (emoji--add-recent): * lisp/jsonrpc.el (jsonrpc--call-deferred) (jsonrpc--process-sentinel, jsonrpc--remove): * lisp/keymap.el (keymap-local-lookup): * lisp/mail/emacsbug.el (report-emacs-bug-hook) (submit-emacs-patch): * lisp/mail/ietf-drums.el (ietf-drums-parse-addresses): * lisp/mail/mailclient.el (mailclient-send-it): * lisp/mail/rfc6068.el (rfc6068-parse-mailto-url): * lisp/mail/undigest.el (rmail-digest-parse-mixed-mime): * lisp/minibuffer.el (completion-metadata-get) (completions--after-change) (minibuffer-visible-completions--filter): * lisp/net/browse-url.el (browse-url-url-at-point) (browse-url-file-url, browse-url-emacs): * lisp/net/dbus.el (dbus-byte-array-to-string) (dbus-monitor-goto-serial): * lisp/net/dictionary.el (dictionary-search): * lisp/net/eww.el (eww--download-directory) (eww-auto-rename-buffer, eww-open-in-new-buffer, eww-submit) (eww-follow-link, eww-read-alternate-url) (eww-copy-alternate-url): * lisp/net/goto-addr.el (goto-address-at-point): * lisp/net/mailcap.el (mailcap-mime-info): * lisp/net/rcirc.el (rcirc, rcirc-connect, rcirc-send-string) (rcirc-kill-buffer-hook, rcirc-print, rcirc-when) (rcirc-color-attributes, rcirc-handler-NICK) (rcirc-handler-TAGMSG, rcirc-handler-BATCH): * lisp/net/shr.el (shr-descend, shr-adaptive-fill-function) (shr-correct-dom-case, shr-tag-a): * lisp/net/sieve.el (sieve-manage-quit): * lisp/outline.el (outline-cycle-buffer): * lisp/pcmpl-git.el (pcmpl-git--tracked-file-predicate): * lisp/proced.el (proced-auto-update-timer): * lisp/progmodes/bug-reference.el (bug-reference-try-setup-from-vc): * lisp/progmodes/c-ts-common.el (c-ts-common--fill-paragraph): * lisp/progmodes/c-ts-mode.el (c-ts-mode--preproc-offset) (c-ts-mode--anchor-prev-sibling, c-ts-mode-indent-defun): * lisp/progmodes/compile.el (compilation-error-properties) (compilation-find-file-1): * lisp/progmodes/eglot.el (eglot--check-object) (eglot--read-server, eglot-upgrade-eglot) (eglot-handle-notification, eglot--CompletionParams) (eglot-completion-at-point, eglot--sig-info) (eglot-register-capability): * lisp/progmodes/elisp-mode.el (emacs-lisp-native-compile-and-load) (elisp-eldoc-var-docstring-with-value): * lisp/progmodes/erts-mode.el (erts-mode--goto-start-of-test): * lisp/progmodes/flymake.el (flymake--update-eol-overlays) (flymake-eldoc-function): * lisp/progmodes/gdb-mi.el (gdb-breakpoints-list-handler-custom) (gdb-frame-handler): * lisp/progmodes/go-ts-mode.el (go-ts-mode-docstring) (go-ts-mode--comment-on-previous-line-p) (go-ts-mode--get-test-regexp-at-point) (go-ts-mode-test-this-file): * lisp/progmodes/grep.el (lgrep, rgrep-default-command) (grep-file-at-point): * lisp/progmodes/perl-mode.el (perl--end-of-format-p): * lisp/progmodes/php-ts-mode.el (php-ts-mode--anchor-prev-sibling, php-ts-mode--indent-defun): * lisp/progmodes/project.el (project--other-place-command) (project--find-default-from, project--transplant-file-name) (project-prefixed-buffer-name, project--remove-from-project-list) (project-prompt-project-name, project-remember-projects-under) (project--switch-project-command) (project-uniquify-dirname-transform, project-mode-line-format): * lisp/progmodes/python.el (python-font-lock-keywords-maximum-decoration) (python--treesit-fontify-union-types) (python-shell-get-process-name, python-shell-restart) (python-shell-completion-at-point, python-ffap-module-path) (python-util-comint-end-of-output-p, python--import-sources) (python-add-import, python-remove-import, python-fix-imports): * lisp/progmodes/xref.el (xref--add-log-current-defun): * lisp/repeat.el (repeat-echo-message-string): * lisp/saveplace.el (save-place-dired-hook): * lisp/server.el (server-save-buffers-kill-terminal): * lisp/shadowfile.el (shadow-make-fullname) (shadow-contract-file-name, shadow-define-literal-group): * lisp/shell.el (shell-highlight-undef-mode): * lisp/simple.el (command-completion-using-modes-p) (command-execute, file-user-uid, file-group-gid) (first-completion, last-completion, switch-to-completions): * lisp/startup.el (startup--load-user-init-file): * lisp/tab-line.el (tab-line-tabs-buffer-group-by-project): * lisp/tar-mode.el (tar-goto-file, tar-next-file-displayer): * lisp/term/android-win.el (android-encode-select-string) (gui-backend-set-selection): * lisp/term/haiku-win.el (haiku-dnd-convert-string) (haiku-select-encode-xstring, haiku-select-encode-utf-8-string): * lisp/textmodes/emacs-news-mode.el (emacs-news--buttonize): * lisp/textmodes/ispell.el (ispell-completion-at-point): * lisp/textmodes/sgml-mode.el (sgml-validate) (html-mode--complete-at-point): * lisp/textmodes/tex-mode.el (tex-recenter-output-buffer) (xref-backend-references): * lisp/thingatpt.el (thing-at-point-file-at-point) (thing-at-point-face-at-point): * lisp/thread.el (thread-list--get-status): * lisp/time.el (world-clock-copy-time-as-kill, world-clock): * lisp/touch-screen.el (touch-screen-handle-touch): * lisp/treesit.el (treesit-language-at, treesit-node-at) (treesit-node-on, treesit-buffer-root-node) (treesit-node-field-name, treesit-local-parsers-at) (treesit-local-parsers-on, treesit--cleanup-local-range-overlays) (treesit-font-lock-recompute-features) (treesit-font-lock-fontify-region, treesit-transpose-sexps) (treesit-add-log-current-defun, treesit-major-mode-setup) (treesit--explorer-refresh, treesit-install-language-grammar): * lisp/url/url.el (url-retrieve-synchronously): * lisp/vc/smerge-mode.el (smerge-diff): * lisp/vc/vc-dir.el (vc-dir): * lisp/vc/vc-dispatcher.el (vc-do-async-command): * lisp/vc/vc-git.el (vc-git-dir--branch-headers) (vc-git-dir--stash-headers, vc-git--log-edit-summary-check) (vc-git-stash-list): * lisp/vc/vc.el (vc-responsible-backend, vc-buffer-sync-fileset) (vc-clone): * lisp/visual-wrap.el (visual-wrap--apply-to-line): * lisp/wid-edit.el (widget-text) (widget-editable-list-insert-before): * lisp/window-tool-bar.el (window-tool-bar--keymap-entry-to-string): * lisp/window.el (display-buffer, display-buffer-full-frame) (window-point-context-set, window-point-context-use) (window-point-context-use-default-function): * lisp/xdg.el (xdg-current-desktop): * lisp/xwidget.el (xwidget-webkit-callback): * lisp/yank-media.el (yank-media--get-selection) (yank-media-types): * test/lisp/comint-tests.el (comint-tests/test-password-function): * test/lisp/completion-preview-tests.el (completion-preview-tests--capf): * test/lisp/cus-edit-tests.el (with-cus-edit-test): * test/lisp/erc/erc-scenarios-base-local-modules.el (-phony-sblm-): * test/lisp/erc/erc-scenarios-stamp.el (erc-scenarios-stamp--on-post-modify): * test/lisp/erc/erc-services-tests.el (erc-services-tests--asp-parse-entry): * test/lisp/erc/erc-tests.el (erc-modules--internal-property) (erc--find-mode, erc-tests--update-modules): * test/lisp/erc/resources/erc-d/erc-d-i.el (erc-d-i--parse-message): * test/lisp/erc/resources/erc-d/erc-d-t.el (erc-d-t-kill-related-buffers, erc-d-t-with-cleanup): * test/lisp/erc/resources/erc-d/erc-d-tests.el (erc-d-i--parse-message--irc-parser-tests): * test/lisp/erc/resources/erc-d/erc-d-u.el (erc-d-u--read-exchange-slowly): * test/lisp/erc/resources/erc-d/erc-d.el (erc-d--expire) (erc-d--finalize-done, erc-d--command-handle-all): * test/lisp/erc/resources/erc-scenarios-common.el (erc-scenarios-common-with-cleanup): * test/lisp/erc/resources/erc-tests-common.el (erc-tests--common-display-message) (erc-tests-common-create-subprocess): * test/lisp/ibuffer-tests.el (ibuffer-test-Bug25058): * test/lisp/international/mule-tests.el (mule-cmds-tests--ucs-names-missing-names): * test/lisp/progmodes/python-tests.el (python-tests-get-shell-interpreter) (python-tests--get-interpreter-info): * test/lisp/progmodes/ruby-ts-mode-tests.el (ruby-ts-resource-file): * test/lisp/replace-tests.el (replace-tests-with-undo): * test/src/emacs-tests.el (emacs-tests--seccomp-debug): * test/src/process-tests.el (process-tests--emacs-command) (process-tests--emacs-binary, process-tests--dump-file): * test/src/treesit-tests.el (treesit--ert-test-defun-navigation): Replace use of the now-obsolete if-let and when-let.
2024-10-24 16:50:07 +08:00
(when-let* ((it (alist-get chr char-nums)))
(if (cdr it)
`(,(cons 'or it) ,chr)
`(,(car it) ,chr))))
'(?, ?\s ?u ?U ?E ?q)))
`((_ ,def-chr))))))
((symbol-function 'read-string)
(if replace-tests-bind-read-string
(lambda (&rest _args) replace-tests-bind-read-string)
(symbol-function 'read-string)))
;; Emulate replace-highlight clobbering match-data via
;; isearch-lazy-highlight-new-loop and sit-for (bug#36328)
((symbol-function 'replace-highlight)
(lambda (&rest _args)
(string-match "[A-Z ]" "ForestGreen")))
;; Override `sit-for' and `ding' so that we don't have
;; to wait and listen to bells when running the test.
((symbol-function 'sit-for)
(lambda (&rest _args) (redisplay)))
((symbol-function 'ding) 'ignore))
(perform-replace ,from ,to t replace-tests-perform-replace-regexp-flag nil))
,@body))))
(defun replace-tests--query-replace-undo (&optional comma)
(let ((input "111"))
(if comma
(should
(replace-tests-with-undo
input "1" "2" ((?, . (2)) (?u . (3)) (?q . (4))) ?\s (buffer-string)))
(should
(replace-tests-with-undo
input "1" "2" ((?\s . (2)) (?u . (3)) (?q . (4))) ?\s (buffer-string))))))
(ert-deftest query-replace--undo ()
(should (string= "211" (replace-tests--query-replace-undo)))
(should (string= "211" (replace-tests--query-replace-undo 'comma))))
(ert-deftest query-replace-undo-bug31073 ()
"Test for https://debbugs.gnu.org/31073 ."
(let ((input "aaa aaa"))
(should
(replace-tests-with-undo
input "a" "B" ((?\s . (1 2 3)) (?U . (4))) ?q
(string= input (buffer-string))))))
(ert-deftest query-replace-undo-bug31492 ()
"Test for https://debbugs.gnu.org/31492 ."
(let ((input "a\nb\nc\n"))
(should
(replace-tests-with-undo
input "^\\|\b\\|$" "foo" ((?\s . (1 2)) (?U . (3))) ?q
(string= input (buffer-string))))))
(ert-deftest query-replace-undo-bug31538 ()
"Test for https://debbugs.gnu.org/31538 ."
(let ((input "aaa aaa")
(replace-tests-bind-read-string "Bfoo"))
(should
(replace-tests-with-undo
input "a" "B" ((?\s . (1 2 3)) (?E . (4)) (?U . (5))) ?q
(string= input (buffer-string))))))
(ert-deftest query-replace-undo-bug37073 ()
"Test for https://debbugs.gnu.org/37073 ."
(let ((input "theorem 1\ntheorem 2\ntheorem 3"))
(should
(replace-tests-with-undo
input "theorem \\([0-9]+\\)"
'(replace-eval-replacement
replace-quote
(format "theorem \\\\ref{theo_%d}" (1+ (string-to-number (match-string 1)))))
((?\s . (1 2)) (?U . (3)))
?q
(string= input (buffer-string)))))
;; Now run a test with regexp-flag arg in `perform-replace' set to nil
(let ((input " ^theorem$ 1\n ^theorem$ 2\n ^theorem$ 3")
(replace-tests-perform-replace-regexp-flag nil)
(expected " theo 1\n ^theorem$ 2\n ^theorem$ 3"))
(should
(replace-tests-with-undo
input "^theorem$"
"theo"
((?\s . (1 2 4)) (?U . (3)))
?q
(string= expected (buffer-string))))))
(ert-deftest query-replace-undo-bug37287 ()
"Test for https://debbugs.gnu.org/37287 ."
(let ((input "foo-1\nfoo-2\nfoo-3")
(expected "foo-2\nfoo-2\nfoo-3"))
(should
(replace-tests-with-undo
input "\\([0-9]\\)"
'(replace-eval-replacement
replace-quote
(format "%d" (1+ (string-to-number (match-string 1)))))
((?\s . (1 2 4)) (?U . (3)))
?q
(string= expected (buffer-string))))))
(defmacro replace-tests-with-highlighted-occurrence (highlight-locus &rest body)
"Helper macro to test the highlight of matches when navigating occur buffer.
Eval BODY with `next-error-highlight' and `next-error-highlight-no-select'
bound to HIGHLIGHT-LOCUS."
(declare (indent 1) (debug (form body)))
`(let ((regexp "foo")
(next-error-highlight ,highlight-locus)
(next-error-highlight-no-select ,highlight-locus)
(buffer (generate-new-buffer "test"))
(inhibit-message t))
(unwind-protect
;; Local bind to disable the deletion of `occur-highlight-overlay'
(cl-letf (((symbol-function 'occur-goto-locus-delete-o) (lambda ())))
(with-current-buffer buffer (dotimes (_ 3) (insert regexp ?\n)))
(pop-to-buffer buffer)
(occur regexp)
(pop-to-buffer "*Occur*")
(occur-next)
,@body)
(kill-buffer buffer)
(kill-buffer "*Occur*"))))
(ert-deftest occur-highlight-occurrence ()
"Test for https://debbugs.gnu.org/39121 ."
(let ((alist '((nil . nil) (0.5 . t) (t . t) (fringe-arrow . nil)))
(check-overlays
(lambda (has-ov)
(eq has-ov (not (null (overlays-in (point-min) (point-max))))))))
(pcase-dolist (`(,highlight-locus . ,has-overlay) alist)
;; Visiting occurrences
(replace-tests-with-highlighted-occurrence highlight-locus
(occur-mode-goto-occurrence)
(should (funcall check-overlays has-overlay)))
;; Displaying occurrences
(replace-tests-with-highlighted-occurrence highlight-locus
(occur-mode-display-occurrence)
(with-current-buffer (marker-buffer
(caar (get-text-property (point) 'occur-target)))
(should (funcall check-overlays has-overlay)))))))
(ert-deftest replace-regexp-bug45973 ()
"Test for https://debbugs.gnu.org/45973 ."
(let ((before "1RB 1LC 1RC 1RB 1RD 0LE 1LA 1LD 1RH 0LA")
(after "1LB 1RC 1LC 1LB 1LD 0RE 1RA 1RD 1LH 0RA"))
(with-temp-buffer
(insert before)
(goto-char (point-min))
(with-suppressed-warnings ((interactive-only replace-regexp))
(replace-regexp
"\\(\\(L\\)\\|\\(R\\)\\)"
'(replace-eval-replacement
replace-quote
(if (match-string 2) "R" "L"))))
(should (equal (buffer-string) after)))))
(ert-deftest test-count-matches ()
(with-temp-buffer
(insert "oooooooooo")
(goto-char (point-min))
(should (= (count-matches "oo") 5))
(should (= (count-matches "o+") 1)))
(with-temp-buffer
(insert "o\n\n\n\no\n\n")
(goto-char (point-min))
(should (= (count-matches "^$") 4))))
;;; replace-tests.el ends here