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 /test | |
| 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`.
Diffstat (limited to 'test')
| -rw-r--r-- | test/src/editfns-tests.el | 35 |
1 files changed, 35 insertions, 0 deletions
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 |