aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorKévin Le Gouguec2022-09-11 19:55:01 +0200
committerLars Ingebrigtsen2022-09-11 19:55:36 +0200
commitd8f392bccd46cdb238ec96964f220ffb9d81cc44 (patch)
treee848ea4af2352a30411d4fe5ef1797fc87e87441 /test
parentcba83d989359d667e52dad4e0e9eadf6f77cc38f (diff)
downloademacs-d8f392bccd46cdb238ec96964f220ffb9d81cc44.tar.gz
emacs-d8f392bccd46cdb238ec96964f220ffb9d81cc44.zip
Restrict replace-*-in-region to the bounds defined by caller
* lisp/subr.el (replace-string-in-region, replace-regexp-in-region): Narrow to region before iterating over matches, instead of giving a bound to the search functions. * test/lisp/subr-tests.el (test-replace-string-in-region): Add regression tests (bug#57733).
Diffstat (limited to 'test')
-rw-r--r--test/lisp/subr-tests.el32
1 files changed, 30 insertions, 2 deletions
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 4310b7291ad..30117132101 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -968,7 +968,21 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
968 (insert "Foo bar zot foobar") 968 (insert "Foo bar zot foobar")
969 (should (= (replace-string-in-region "Foo" "new" (point-min)) 969 (should (= (replace-string-in-region "Foo" "new" (point-min))
970 1)) 970 1))
971 (should (equal (buffer-string) "new bar zot foobar")))) 971 (should (equal (buffer-string) "new bar zot foobar")))
972
973 (with-temp-buffer
974 (insert "foo bar baz")
975 (should (= (replace-string-in-region "ba" "quux corge grault" (point-min))
976 2))
977 (should (equal (buffer-string)
978 "foo quux corge graultr quux corge graultz")))
979
980 (with-temp-buffer
981 (insert "foo bar bar")
982 (should (= (replace-string-in-region " bar" "" (point-min) 8)
983 1))
984 (should (equal (buffer-string)
985 "foo bar"))))
972 986
973(ert-deftest test-replace-regexp-in-region () 987(ert-deftest test-replace-regexp-in-region ()
974 (with-temp-buffer 988 (with-temp-buffer
@@ -991,7 +1005,21 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
991 (insert "Foo bar zot foobar") 1005 (insert "Foo bar zot foobar")
992 (should (= (replace-regexp-in-region "Fo+" "new" (point-min)) 1006 (should (= (replace-regexp-in-region "Fo+" "new" (point-min))
993 1)) 1007 1))
994 (should (equal (buffer-string) "new bar zot foobar")))) 1008 (should (equal (buffer-string) "new bar zot foobar")))
1009
1010 (with-temp-buffer
1011 (insert "foo bar baz")
1012 (should (= (replace-regexp-in-region "ba." "quux corge grault" (point-min))
1013 2))
1014 (should (equal (buffer-string)
1015 "foo quux corge grault quux corge grault")))
1016
1017 (with-temp-buffer
1018 (insert "foo bar bar")
1019 (should (= (replace-regexp-in-region " bar" "" (point-min) 8)
1020 1))
1021 (should (equal (buffer-string)
1022 "foo bar"))))
995 1023
996(ert-deftest test-with-existing-directory () 1024(ert-deftest test-with-existing-directory ()
997 (let ((dir (make-temp-name "/tmp/not-exist-"))) 1025 (let ((dir (make-temp-name "/tmp/not-exist-")))