diff options
| author | Stefan Monnier | 2025-02-28 17:10:56 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2025-02-28 17:10:56 -0500 |
| commit | 1cfbbcfaf657e767ed5743565b62eeecde3a4ef5 (patch) | |
| tree | 187539469d00d0f8895351c6a78c7398d286fa61 | |
| parent | 5f165caf316f9da6f04f4d6c5a0fa786f6f197b9 (diff) | |
| download | emacs-1cfbbcfaf657e767ed5743565b62eeecde3a4ef5.tar.gz emacs-1cfbbcfaf657e767ed5743565b62eeecde3a4ef5.zip | |
* test/src/editfns-tests.el (editfns--replace-region): New test
This test fails, sadly, because `replace-buffer-contents` is not
careful enough to something like `replace_range`.
| -rw-r--r-- | src/editfns.c | 2 | ||||
| -rw-r--r-- | test/src/editfns-tests.el | 35 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/editfns.c b/src/editfns.c index 3dff49fb00c..12700527ef3 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2050,6 +2050,7 @@ nil. */) | |||
| 2050 | 2050 | ||
| 2051 | if (early_abort) | 2051 | if (early_abort) |
| 2052 | { | 2052 | { |
| 2053 | /* FIXME: Use 'replace_range'! */ | ||
| 2053 | del_range (min_a, ZV); | 2054 | del_range (min_a, ZV); |
| 2054 | Finsert_buffer_substring (source, Qnil,Qnil); | 2055 | Finsert_buffer_substring (source, Qnil,Qnil); |
| 2055 | SAFE_FREE_UNBIND_TO (count, Qnil); | 2056 | SAFE_FREE_UNBIND_TO (count, Qnil); |
| @@ -2099,6 +2100,7 @@ nil. */) | |||
| 2099 | eassert (beg_a <= end_a); | 2100 | eassert (beg_a <= end_a); |
| 2100 | eassert (beg_b <= end_b); | 2101 | eassert (beg_b <= end_b); |
| 2101 | eassert (beg_a < end_a || beg_b < end_b); | 2102 | eassert (beg_a < end_a || beg_b < end_b); |
| 2103 | /* FIXME: Use 'replace_range'! */ | ||
| 2102 | if (beg_a < end_a) | 2104 | if (beg_a < end_a) |
| 2103 | del_range (beg_a, end_a); | 2105 | del_range (beg_a, end_a); |
| 2104 | if (beg_b < end_b) | 2106 | if (beg_b < end_b) |
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index 29b7a850838..09af179a180 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el | |||
| @@ -320,6 +320,41 @@ | |||
| 320 | (should (equal (buffer-substring-no-properties (point-min) (point-max)) | 320 | (should (equal (buffer-substring-no-properties (point-min) (point-max)) |
| 321 | (concat (string (char-from-name "SMILE")) "1234")))) | 321 | (concat (string (char-from-name "SMILE")) "1234")))) |
| 322 | 322 | ||
| 323 | (defun editfns--replace-region (from to string) | ||
| 324 | (save-excursion | ||
| 325 | (save-restriction | ||
| 326 | (narrow-to-region from to) | ||
| 327 | (let ((buf (current-buffer))) | ||
| 328 | (with-temp-buffer | ||
| 329 | (let ((str-buf (current-buffer))) | ||
| 330 | (insert string) | ||
| 331 | (with-current-buffer buf | ||
| 332 | (replace-buffer-contents str-buf)))))))) | ||
| 333 | |||
| 334 | (ert-deftest editfns-tests--replace-region () | ||
| 335 | :expected-result :failed | ||
| 336 | (with-temp-buffer | ||
| 337 | (insert "here is some text") | ||
| 338 | (let ((m5n (copy-marker (+ (point-min) 5))) | ||
| 339 | (m5a (copy-marker (+ (point-min) 5) t)) | ||
| 340 | (m6n (copy-marker (+ (point-min) 6))) | ||
| 341 | (m6a (copy-marker (+ (point-min) 6) t)) | ||
| 342 | (m7n (copy-marker (+ (point-min) 7))) | ||
| 343 | (m7a (copy-marker (+ (point-min) 7) t))) | ||
| 344 | (editfns--replace-region (+ (point-min) 5) (+ (point-min) 7) "be") | ||
| 345 | (should (equal (buffer-string) "here be some text")) | ||
| 346 | (should (equal (point) (point-max))) | ||
| 347 | ;; Markers before the replaced text stay before. | ||
| 348 | (should (= m5n (+ (point-min) 5))) | ||
| 349 | (should (= m5a (+ (point-min) 5))) | ||
| 350 | ;; Markers in the replaced text can end up at either end, depending | ||
| 351 | ;; on whether they're advance-after-insert or not. | ||
| 352 | (should (= m6n (+ (point-min) 5))) | ||
| 353 | (should (<= (+ (point-min) 5) m6a (+ (point-min) 7))) | ||
| 354 | ;; Markers after the replaced text stay after. | ||
| 355 | (should (= m7n (+ (point-min) 7))) | ||
| 356 | (should (= m7a (+ (point-min) 7)))))) | ||
| 357 | |||
| 323 | (ert-deftest delete-region-undo-markers-1 () | 358 | (ert-deftest delete-region-undo-markers-1 () |
| 324 | "Make sure we don't end up with freed markers reachable from Lisp." | 359 | "Make sure we don't end up with freed markers reachable from Lisp." |
| 325 | ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#40 | 360 | ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#40 |