diff options
| author | Tino Calancha | 2018-05-26 12:45:55 +0900 |
|---|---|---|
| committer | Tino Calancha | 2018-05-26 12:51:53 +0900 |
| commit | 66c9ab90d5f8b566467549bf1d48c936bc6d296b (patch) | |
| tree | 691694b3ae86decc379e6df5d3f8e42cf3da4c4d | |
| parent | ea133e04f49afa7928e49a3ac4a85b47f6f13f01 (diff) | |
| download | emacs-66c9ab90d5f8b566467549bf1d48c936bc6d296b.tar.gz emacs-66c9ab90d5f8b566467549bf1d48c936bc6d296b.zip | |
replace-tests.el: Fix broken tests
After previous commit, all tests using helper function
`replace-tests-clauses' fail: during the expansion
of macro `replace-tests-with-undo', the function
`replace-tests-clauses' is unbound.
Delete those helpers and reimplement test
`query-replace-undo-bug31538'.
* test/lisp/replace-tests.el (query-replace-undo-bug31538):
Reimplement this test without using any helper function/macro.
| -rw-r--r-- | test/lisp/replace-tests.el | 155 |
1 files changed, 69 insertions, 86 deletions
diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el index 67372bf82fb..8123ff0a571 100644 --- a/test/lisp/replace-tests.el +++ b/test/lisp/replace-tests.el | |||
| @@ -23,7 +23,6 @@ | |||
| 23 | ;;; Code: | 23 | ;;; Code: |
| 24 | 24 | ||
| 25 | (require 'ert) | 25 | (require 'ert) |
| 26 | (eval-when-compile (require 'subr-x)) | ||
| 27 | 26 | ||
| 28 | (ert-deftest query-replace--split-string-tests () | 27 | (ert-deftest query-replace--split-string-tests () |
| 29 | (let ((sep (propertize "\0" 'separator t))) | 28 | (let ((sep (propertize "\0" 'separator t))) |
| @@ -359,75 +358,23 @@ Each element has the format: | |||
| 359 | (dotimes (i (length replace-occur-tests)) | 358 | (dotimes (i (length replace-occur-tests)) |
| 360 | (replace-occur-test-create i)) | 359 | (replace-occur-test-create i)) |
| 361 | 360 | ||
| 362 | |||
| 363 | ;;; Tests for `query-replace' undo feature. | ||
| 364 | (defun replace-tests-clauses (char-nums def-chr) | ||
| 365 | "Build the clauses of the `pcase' in `replace-tests-with-undo'. | ||
| 366 | CHAR-NUMS is a list of elements (CHAR . NUMS). | ||
| 367 | CHAR is one of the chars ?, ?\s ?u ?U ?E ?q. | ||
| 368 | NUMS is a list of integers; they are the patters to match, | ||
| 369 | while CHAR is the return value. | ||
| 370 | DEF-CHAR is the default character to return in the `pcase' | ||
| 371 | when any of the clauses match." | ||
| 372 | (append | ||
| 373 | (delq nil | ||
| 374 | (mapcar (lambda (chr) | ||
| 375 | (when-let (it (cadr (assq chr char-nums))) | ||
| 376 | (if (cdr it) | ||
| 377 | `(,(cons 'or it) ,chr) | ||
| 378 | `(,(car it) ,chr)))) | ||
| 379 | '(?, ?\s ?u ?U ?E ?q))) | ||
| 380 | `((_ ,def-chr)))) | ||
| 381 | |||
| 382 | (defvar replace-tests-bind-read-string nil | ||
| 383 | "A string to bind `read-string' and avoid the prompt.") | ||
| 384 | |||
| 385 | (defmacro replace-tests-with-undo (input from to char-nums def-chr &rest body) | ||
| 386 | "Helper to test `query-replace' undo feature. | ||
| 387 | INPUT is a string to insert in a temporary buffer. | ||
| 388 | FROM is the string to match for replace. | ||
| 389 | TO is the replacement string. | ||
| 390 | CHAR-NUMS is a list of elements (CHAR . NUMS). | ||
| 391 | CHAR is one of the chars ?, ?\s ?u ?U ?E ?q. | ||
| 392 | NUMS is a list of integers. | ||
| 393 | DEF-CHAR is the char ?\s or ?q. | ||
| 394 | BODY is a list of forms. | ||
| 395 | Return the last evaled form in BODY." | ||
| 396 | (declare (indent 5) (debug (stringp stringp stringp form characterp body))) | ||
| 397 | (let ((text (gensym "text")) | ||
| 398 | (count (gensym "count"))) | ||
| 399 | `(let* ((,text ,input) | ||
| 400 | (,count 0) | ||
| 401 | (inhibit-message t)) | ||
| 402 | (with-temp-buffer | ||
| 403 | (insert ,text) | ||
| 404 | (goto-char 1) | ||
| 405 | ;; Bind `read-event' to simulate user input. | ||
| 406 | ;; If `replace-tests-bind-read-string' is non-nil, then | ||
| 407 | ;; bind `read-string' as well. | ||
| 408 | (cl-letf (((symbol-function 'read-event) | ||
| 409 | (lambda (&rest args) | ||
| 410 | (cl-incf ,count) | ||
| 411 | (let ((val | ||
| 412 | (pcase ,count | ||
| 413 | ,@(replace-tests-clauses char-nums def-chr)))) | ||
| 414 | val))) | ||
| 415 | ((symbol-function 'read-string) | ||
| 416 | (if replace-tests-bind-read-string | ||
| 417 | (lambda (&rest args) replace-tests-bind-read-string) | ||
| 418 | (symbol-function 'read-string)))) | ||
| 419 | (perform-replace ,from ,to t t nil)) | ||
| 420 | ,@body)))) | ||
| 421 | |||
| 422 | (defun replace-tests--query-replace-undo (&optional comma) | 361 | (defun replace-tests--query-replace-undo (&optional comma) |
| 423 | (let ((input "111")) | 362 | (with-temp-buffer |
| 424 | (if comma | 363 | (insert "111") |
| 425 | (should | 364 | (goto-char 1) |
| 426 | (replace-tests-with-undo | 365 | (let ((count 0)) |
| 427 | input "1" "2" ((?, (2)) (?u (3)) (?q (4))) ?\s (buffer-string))) | 366 | ;; Don't wait for user input. |
| 428 | (should | 367 | (cl-letf (((symbol-function 'read-event) |
| 429 | (replace-tests-with-undo | 368 | (lambda (&rest args) |
| 430 | input "1" "2" ((?\s (2)) (?u (3)) (?q (4))) ?\s (buffer-string)))))) | 369 | (cl-incf count) |
| 370 | (let ((val (pcase count | ||
| 371 | ('2 (if comma ?, ?\s)) ; replace and: ',' no move; '\s' go next | ||
| 372 | ('3 ?u) ; undo | ||
| 373 | ('4 ?q) ; exit | ||
| 374 | (_ ?\s)))) ; replace current and go next | ||
| 375 | val)))) | ||
| 376 | (perform-replace "1" "2" t nil nil))) | ||
| 377 | (buffer-string))) | ||
| 431 | 378 | ||
| 432 | (ert-deftest query-replace--undo () | 379 | (ert-deftest query-replace--undo () |
| 433 | (should (string= "211" (replace-tests--query-replace-undo))) | 380 | (should (string= "211" (replace-tests--query-replace-undo))) |
| @@ -435,28 +382,64 @@ Return the last evaled form in BODY." | |||
| 435 | 382 | ||
| 436 | (ert-deftest query-replace-undo-bug31073 () | 383 | (ert-deftest query-replace-undo-bug31073 () |
| 437 | "Test for https://debbugs.gnu.org/31073 ." | 384 | "Test for https://debbugs.gnu.org/31073 ." |
| 438 | (let ((input "aaa aaa")) | 385 | (let ((text "aaa aaa") |
| 439 | (should | 386 | (count 0)) |
| 440 | (replace-tests-with-undo | 387 | (with-temp-buffer |
| 441 | input "a" "B" ((?\s (1 2 3)) (?U (4))) ?q | 388 | (insert text) |
| 442 | (string= input (buffer-string)))))) | 389 | (goto-char 1) |
| 390 | (cl-letf (((symbol-function 'read-event) | ||
| 391 | (lambda (&rest args) | ||
| 392 | (cl-incf count) | ||
| 393 | (let ((val (pcase count | ||
| 394 | ((or 1 2 3) ?\s) ; replace current and go next | ||
| 395 | (4 ?U) ; undo-all | ||
| 396 | (_ ?q)))) ; exit | ||
| 397 | val)))) | ||
| 398 | (perform-replace "a" "B" t nil nil)) | ||
| 399 | ;; After undo text must be the same. | ||
| 400 | (should (string= text (buffer-string)))))) | ||
| 443 | 401 | ||
| 444 | (ert-deftest query-replace-undo-bug31492 () | 402 | (ert-deftest query-replace-undo-bug31492 () |
| 445 | "Test for https://debbugs.gnu.org/31492 ." | 403 | "Test for https://debbugs.gnu.org/31492 ." |
| 446 | (let ((input "a\nb\nc\n")) | 404 | (let ((text "a\nb\nc\n") |
| 447 | (should | 405 | (count 0) |
| 448 | (replace-tests-with-undo | 406 | (inhibit-message t)) |
| 449 | input "^\\|\b\\|$" "foo" ((?\s (1 2)) (?U (3))) ?q | 407 | (with-temp-buffer |
| 450 | (string= input (buffer-string)))))) | 408 | (insert text) |
| 409 | (goto-char 1) | ||
| 410 | (cl-letf (((symbol-function 'read-event) | ||
| 411 | (lambda (&rest args) | ||
| 412 | (cl-incf count) | ||
| 413 | (let ((val (pcase count | ||
| 414 | ((or 1 2) ?\s) ; replace current and go next | ||
| 415 | (3 ?U) ; undo-all | ||
| 416 | (_ ?q)))) ; exit | ||
| 417 | val)))) | ||
| 418 | (perform-replace "^\\|\b\\|$" "foo" t t nil)) | ||
| 419 | ;; After undo text must be the same. | ||
| 420 | (should (string= text (buffer-string)))))) | ||
| 451 | 421 | ||
| 452 | (ert-deftest query-replace-undo-bug31538 () | 422 | (ert-deftest query-replace-undo-bug31538 () |
| 453 | "Test for https://debbugs.gnu.org/31538 ." | 423 | "Test for https://debbugs.gnu.org/31538 ." |
| 454 | (let ((input "aaa aaa") | 424 | (let ((text "aaa aaa") |
| 455 | (replace-tests-bind-read-string "Bfoo")) | 425 | (count 0) |
| 456 | (should | 426 | (inhibit-message t)) |
| 457 | (replace-tests-with-undo | 427 | (with-temp-buffer |
| 458 | input "a" "B" ((?\s (1 2 3)) (?E (4)) (?U (5))) ?q | 428 | (insert text) |
| 459 | (string= input (buffer-string)))))) | 429 | (goto-char 1) |
| 460 | 430 | (cl-letf (((symbol-function 'read-event) | |
| 431 | (lambda (&rest args) | ||
| 432 | (cl-incf count) | ||
| 433 | (let ((val (pcase count | ||
| 434 | ((or 1 2 3) ?\s) ; replace current and go next | ||
| 435 | (4 ?E) ; edit string | ||
| 436 | (5 ?U) ; undo-all | ||
| 437 | (_ ?q)))) ; exit | ||
| 438 | val))) | ||
| 439 | ((symbol-function 'read-string) | ||
| 440 | (lambda (&rest _) "Bfoo"))) | ||
| 441 | (perform-replace "a" "B" t t nil)) | ||
| 442 | ;; After undo text must be the same. | ||
| 443 | (should (string= text (buffer-string)))))) | ||
| 461 | 444 | ||
| 462 | ;;; replace-tests.el ends here | 445 | ;;; replace-tests.el ends here |