branch: elpa/iedit commit b8bcf521ce27d7836a6533ebb53a2a63f43cca9d Author: Pierre Rouleau <prouleau...@gmail.com> Commit: Victor Ren <victor...@gmail.com>
Fix test regressions and errors Fix regression introduced earlier by replacing delete-backward-char by delete-char and not specifying a negative value: * Fix `iedit-occurrence-update-test' : the 1 deleted is before point, therefore `delete-char 1) must be replaced by (delete-char -1) * Fix `iedit-toggle-buffering-test': in the 3rd test, delete-char needs a negative number to delete on the left. --- iedit-tests.el | 126 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 44 deletions(-) diff --git a/iedit-tests.el b/iedit-tests.el index 70ac59b58e1..7059924574d 100644 --- a/iedit-tests.el +++ b/iedit-tests.el @@ -37,15 +37,26 @@ (require 'elp) ; use: `elp-function-list' (require 'sgml-mode) ; use: `sgml-electric-tag-pair-mode' +(defvar iedit-test--buffer-file-name buffer-file-truename + "Remember current buffer file name.") + (ert-deftest iedit-batch-compile-test () + "First byte compile all files to verify code validity." (with-temp-buffer - (cd (file-name-directory (locate-library "iedit-tests"))) - (call-process-shell-command "emacs -L . -Q --batch -f batch-byte-compile *.el" nil (current-buffer)) + (cd (file-name-directory (or (locate-library "iedit-tests") + (expand-file-name iedit-test--buffer-file-name)))) + (call-process-shell-command + "emacs -L . -Q --batch -f batch-byte-compile *.el" nil (current-buffer)) + ;; When loading iedit.el, if `iedit-mode' is not bound, iedit.el binds it + ;; an issue a message describing the binding. + ;; Check that the expected message is issued. (should (string= (buffer-string) "")) - (delete-file (byte-compile-dest-file "iedit-lib.el") nil) - (delete-file (byte-compile-dest-file "iedit-rect.el") nil) - (delete-file (byte-compile-dest-file "iedit-tests.el") nil) - (delete-file (byte-compile-dest-file "iedit.el") nil))) + (should (file-exists-p (byte-compile-dest-file "iedit-lib.el"))) + (should (file-exists-p (byte-compile-dest-file "iedit-rect.el"))) + (should (file-exists-p (byte-compile-dest-file "iedit.el"))) + (should (file-exists-p (byte-compile-dest-file "iedit-tests.el"))))) + +;; -- (defmacro with-iedit-test-buffer (buffer-name &rest body) (declare (indent 1) (debug t)) @@ -59,20 +70,22 @@ ,@body)))) (defun marker-position-list (l) - "convert list of markers to positions" + "Convert list of markers L to positions." (mapcar (lambda (m) (marker-position m)) l)) (defun goto-word (word &optional beginning) - (goto-char (point-min)) + "Move point to the end or BEGINNING of the specified WORD." + (goto-char 1) (search-forward word) (when beginning (goto-char (- (point) (length word))))) (defun goto-word-beginning (word) + "Move point to the beginning of specified WORD." (goto-word word t)) (defun with-iedit-test-fixture (input-buffer-string body) - "iedit test fixture" + "Setup iedit test environment, using INPUT-BUFFER-STRING to run BODY." (let ((old-transient-mark-mode transient-mark-mode) (old-iedit-transient-sensitive iedit-transient-mark-sensitive) (old-iedit-auto-buffering iedit-auto-buffering) @@ -98,28 +111,39 @@ (iedit-mode) (funcall body))) (transient-mark-mode old-transient-mark-mode) - (setq iedit-transient-mark-sensitive old-transient-mark-mode) + (setq iedit-transient-mark-sensitive old-iedit-transient-sensitive) (setq iedit-auto-buffering old-iedit-auto-buffering) (setq iedit-case-sensitive old-iedit-case-sensitive)))) (ert-deftest iedit-mode-base-test () + "Test base iedit selection." (with-iedit-test-fixture "foo foo barfoo foo" (lambda () + ;; after selecting iedit-mode on the first word, "foo", there + ;; should be 3 instances selected. (should (= 3 (length iedit-occurrences-overlays))) (should (string= iedit-initial-string-local "foo")) + ;; We can limit the number of occurrences my only marking the + ;; first 2 lines and executing `iedit-mode' again. Now only + ;; the first 2 occurrences (inside the marked area) should be + ;; selected. (set-mark-command nil) (forward-line 2) (iedit-mode) (should (= 2 (length iedit-occurrences-overlays))) (should (string= iedit-initial-string-local "foo")) + ;; Issuing the command on blank area should stop the selections. + ;; It also clears `iedit-initial-string-local'. (iedit-mode) - (should (null iedit-occurrences-overlays))))) + (should (null iedit-occurrences-overlays)) + (should (null iedit-initial-string-local))))) (ert-deftest iedit-mode-with-region-test () + "Test iedit when are is marked." (with-iedit-test-fixture "foobar foo @@ -127,6 +151,10 @@ bar foo" (lambda () + ;; Turn `iedit-mode' off (the test-fixture turned it on). + ;; Select the first 3 characters of "foobar" then turn `iedit-mode' on. + ;; There should be 4 matches as matching is done on the selected string, + ;; not words, symbols or other types of matches. (iedit-mode) (goto-char 1) (set-mark-command nil) @@ -135,6 +163,8 @@ foo" (should (= 4 (length iedit-occurrences-overlays))) (should (string= iedit-initial-string-local "foo")) (should (eq 'selection iedit-occurrence-type-local)) + ;; Mark the region of first 3 lines, with iedit-mode 4 + ;; select only what is outside the region. (goto-char 1) (set-mark-command nil) (forward-line 3) @@ -204,7 +234,7 @@ foo" foo" (lambda () (iedit-mode) - (goto-char (point-min)) + (goto-char 1) (goto-char (line-end-position)) (iedit-mode) (delete-region (point) (1- (point))) @@ -265,8 +295,11 @@ foo (isearch-process-search-char ?b) (call-interactively 'iedit-mode-from-isearch) (should (null iedit-occurrences-overlays)) - (should (null iedit-mode)) ;; (should (string= (current-message) "Matches are not the same length.")) - (goto-char (point-min)) + (should (null iedit-mode)) + ;; [:todo 2025-09-27, by Pierre Rouleau: check why this passes inside + ;; Emacs, fails at 'make test'.] + ;; (should (string= (current-message) "Matches are not the same length.")) + (goto-char 1) (call-interactively 'isearch-forward-regexp) (isearch-process-search-char ?f) (isearch-process-search-char ?o) @@ -343,10 +376,12 @@ foo (should (= (point) 24)) (should (= iedit-occurrence-index 3)) (iedit-next-occurrence 1) - (should (= (point) 24)) ;; (should (string= (current-message) "This is the last occurrence.")) + (should (= (point) 24)) + ;; (should (string= (current-message) "This is the last occurrence.")) (should (= iedit-occurrence-index 3)) (iedit-next-occurrence 1) - (should (= (point) 1)) ;; (should (string= (current-message) "Located the first occurrence.")) + (should (= (point) 1)) + ;; (should (string= (current-message) "Located the first occurrence.")) (should (= iedit-occurrence-index 1)) (iedit-next-occurrence 1) (should (= (point) 7)) @@ -360,12 +395,15 @@ foo (iedit-prev-occurrence 1) (should (= (point) 1)) (iedit-prev-occurrence 1) - (should (= (point) 1)) ;; (should (string= (current-message) "This is the first occurrence.")) + (should (= (point) 1)) + ;; (should (string= (current-message) "This is the first occurrence.")) (iedit-prev-occurrence 1) - (should (= (point) 24)) ;; (should (string= (current-message) "Located the last occurrence.")) + (should (= (point) 24)) + ;; (should (string= (current-message) "Located the last occurrence.")) ))) (ert-deftest iedit-occurrence-update-test () + "Test change done on matches." (with-iedit-test-fixture "foo foo @@ -379,7 +417,7 @@ foo 1foo barfoo 1foo")) - (delete-char 1) + (delete-char -1) (run-hooks 'post-command-hook) (should (string= (buffer-string) "foo @@ -488,7 +526,7 @@ foo barFoo FOO" (lambda () - (iedit-mode) + (iedit-mode) ; turn off iedit (goto-char 1) (set-mark-command nil) (forward-char 3) @@ -575,6 +613,7 @@ foo (iedit-delete-occurrences) (should (string= (buffer-string) " barfoo "))))) + (ert-deftest iedit-toggle-buffering-test () (with-iedit-test-fixture "foo @@ -598,13 +637,13 @@ foo barfoo")) (should (= (point) 4)) (iedit-toggle-buffering) - (delete-char 3) + (delete-char -3) (should (string= (buffer-string) "foo barfoo barfoo barfoo")) - (goto-char 15) ;not in an occurrence + (goto-char 15) ;not in an occurrence (should (null (iedit-find-current-occurrence-overlay))) (iedit-toggle-buffering) (should (string= (buffer-string) @@ -620,7 +659,7 @@ foo barfoo foo" (lambda () - (iedit-mode) ;turnoff + (iedit-mode) ;turnoff (setq iedit-auto-buffering t) (push nil buffer-undo-list) (call-interactively 'iedit-mode) @@ -645,8 +684,7 @@ foo "foo foo barfoo - foo")) - ))) + foo"))))) (ert-deftest iedit-buffering-quit-test () (with-iedit-test-fixture @@ -655,7 +693,7 @@ foo barfoo foo" (lambda () - (iedit-mode) ;turnoff + (iedit-mode) ;turnoff (setq iedit-auto-buffering t) (push nil buffer-undo-list) (call-interactively 'iedit-mode) @@ -680,8 +718,8 @@ foo "foo foo barfoo - foo")) - ))) + foo"))))) + (ert-deftest iedit-rectangle-start-test () (with-iedit-test-fixture @@ -697,7 +735,7 @@ foo (call-interactively 'iedit-rectangle-mode) (should (equal (marker-position-list iedit-rectangle) '(1 19))) (call-interactively 'iedit-rectangle-mode) - (goto-char (point-min)) + (goto-char 1) (set-mark-command nil) (goto-char (point-max)) (call-interactively 'iedit-rectangle-mode) @@ -913,21 +951,21 @@ foo" (should (equal (iedit-hide-occurrence-lines) '((74 77) (55 63) (39 46) (25 32) (11 20) (1 8))))))) ;; todo add a auto performance test -(setq elp-function-list '(;; insert-and-inherit - ;; delete-region - ;; goto-char - ;; iedit-occurrence-update - ;; buffer-substring-no-properties - ;; string= - re-search-forward - ;; replace-match - text-property-not-all - iedit-make-occurrence-overlay - iedit-make-occurrences-overlays - match-beginning - match-end - push - )) +;; (setq elp-function-list '(;; insert-and-inherit +;; ;; delete-region +;; ;; goto-char +;; ;; iedit-occurrence-update +;; ;; buffer-substring-no-properties +;; ;; string= +;; re-search-forward +;; ;; replace-match +;; text-property-not-all +;; iedit-make-occurrence-overlay +;; iedit-make-occurrences-overlays +;; match-beginning +;; match-end +;; push +;; )) ;;; iedit-tests.el ends here