summaryrefslogtreecommitdiff
path: root/test/lisp/replace-tests.el
diff options
context:
space:
mode:
authorTino Calancha <tino.calancha@gmail.com>2017-08-08 10:25:27 +0900
committerTino Calancha <tino.calancha@gmail.com>2017-08-08 10:25:27 +0900
commit919ac3ae1635bf2b99eb1f3efc7476826359e92a (patch)
tree0b2b85d5bce21bad1d83ff18dc33b5143a097fb0 /test/lisp/replace-tests.el
parentbec5b602597b8b6f596067167f3b3fe0e6eff285 (diff)
downloademacs-919ac3ae1635bf2b99eb1f3efc7476826359e92a.tar.gz
query-replace: Undo replacements performed with 'comma
During a `query-replace', the char ',' replaces the character at point and doesn't move point; right after, the char 'u' must undo such replacement (Bug#27268). * lisp/replace.el (replace--push-stack): New macro extracted from `perform-replace'. (perform-replace): Use it. * test/lisp/replace-tests.el (query-replace--undo): Add test.
Diffstat (limited to 'test/lisp/replace-tests.el')
-rw-r--r--test/lisp/replace-tests.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el
index adef5a3f3dc..a8bc5407f42 100644
--- a/test/lisp/replace-tests.el
+++ b/test/lisp/replace-tests.el
@@ -358,4 +358,26 @@ Each element has the format:
(dotimes (i (length replace-occur-tests))
(replace-occur-test-create i))
+(defun replace-tests--query-replace-undo (&optional comma)
+ (with-temp-buffer
+ (insert "111")
+ (goto-char 1)
+ (let ((count 0))
+ ;; Don't wait for user input.
+ (cl-letf (((symbol-function 'read-event)
+ (lambda (&rest args)
+ (cl-incf count)
+ (let ((val (pcase count
+ ('2 (if comma ?, ?\s)) ; replace and: ',' no move; '\s' go next
+ ('3 ?u) ; undo
+ ('4 ?q) ; exit
+ (_ ?\s)))) ; replace current and go next
+ val))))
+ (perform-replace "1" "2" t nil nil)))
+ (buffer-string)))
+
+(ert-deftest query-replace--undo ()
+ (should (string= "211" (replace-tests--query-replace-undo)))
+ (should (string= "211" (replace-tests--query-replace-undo 'comma))))
+
;;; replace-tests.el ends here