summaryrefslogtreecommitdiff
path: root/test/lisp/replace-tests.el
diff options
context:
space:
mode:
authorTino Calancha <tino.calancha@gmail.com>2018-05-23 18:20:36 +0900
committerTino Calancha <tino.calancha@gmail.com>2018-05-23 18:20:36 +0900
commitbab73230d1be1fe394b7269c1365ef6fb1a5d9b3 (patch)
tree6a72e3b835d74781cfb878278aa5e944f90bf3b1 /test/lisp/replace-tests.el
parentcc130d13d4b2b4c20d22401364f9814871819791 (diff)
downloademacs-bab73230d1be1fe394b7269c1365ef6fb1a5d9b3.tar.gz
Fix corner case in query-replace-regexp undo
This commit fixes Bug#31492. * lisp/replace.el (replace-match-maybe-edit): Preserve match data. * test/lisp/replace-tests.el (query-replace-undo-bug31492): Add test.
Diffstat (limited to 'test/lisp/replace-tests.el')
-rw-r--r--test/lisp/replace-tests.el20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el
index 40a1a31cf7c..40ee838e679 100644
--- a/test/lisp/replace-tests.el
+++ b/test/lisp/replace-tests.el
@@ -399,5 +399,25 @@ Each element has the format:
;; After undo text must be the same.
(should (string= text (buffer-string))))))
+(ert-deftest query-replace-undo-bug31492 ()
+ "Test for https://debbugs.gnu.org/31492 ."
+ (let ((text "a\nb\nc\n")
+ (count 0)
+ (inhibit-message t))
+ (with-temp-buffer
+ (insert text)
+ (goto-char 1)
+ (cl-letf (((symbol-function 'read-event)
+ (lambda (&rest args)
+ (cl-incf count)
+ (let ((val (pcase count
+ ((or 1 2) ?\s) ; replace current and go next
+ (3 ?U) ; undo-all
+ (_ ?q)))) ; exit
+ val))))
+ (perform-replace "^\\|\b\\|$" "foo" t t nil))
+ ;; After undo text must be the same.
+ (should (string= text (buffer-string))))))
+
;;; replace-tests.el ends here