diff options
| author | Stefan Kangas | 2022-12-22 06:30:09 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2022-12-22 06:30:09 +0100 |
| commit | 08bb91c7df4ebf0dd9de4d55575aaaed87a9b339 (patch) | |
| tree | 245f7772c6466026384bed6c7f95af1b78235bb3 /test | |
| parent | ad5a67996ddf23df904c09165475759e2e0a68b1 (diff) | |
| parent | e59216d3be86918b995bd63273c851ebc6176a83 (diff) | |
| download | emacs-08bb91c7df4ebf0dd9de4d55575aaaed87a9b339.tar.gz emacs-08bb91c7df4ebf0dd9de4d55575aaaed87a9b339.zip | |
Merge from origin/emacs-29
e59216d3be8 * Invoke spawed Emacs processes with '-Q' when native com...
777b383dd0f Fix Eshell electric slash when used from the root directo...
c088cdad9e9 Fix the --without-all build with tree-sitter
ec9fbad908d Fix write-region to null device on MS-Windows
f35da111990 message: Do not default to eudc-capf-complete yet
98c16a8c883 ; * lisp/tab-bar.el: Remaining renaming of "fixed-width" ...
d76d7a3bebf whitespace: Avoid mutating original buffer's markers in c...
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/whitespace-tests.el | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/test/lisp/whitespace-tests.el b/test/lisp/whitespace-tests.el index 3e94d7e921b..12f6cb99a23 100644 --- a/test/lisp/whitespace-tests.el +++ b/test/lisp/whitespace-tests.el | |||
| @@ -42,6 +42,13 @@ nil, `whitespace-mode' is left disabled." | |||
| 42 | '(whitespace-mode 1)) | 42 | '(whitespace-mode 1)) |
| 43 | ,@body))) | 43 | ,@body))) |
| 44 | 44 | ||
| 45 | (defmacro whitespace--with-buffer-selected (buffer-or-name &rest body) | ||
| 46 | (declare (debug (form body)) (indent 1)) | ||
| 47 | `(save-window-excursion | ||
| 48 | (with-current-buffer (or ,buffer-or-name (current-buffer)) | ||
| 49 | (with-selected-window (display-buffer (current-buffer)) | ||
| 50 | ,@body)))) | ||
| 51 | |||
| 45 | (defun whitespace-tests--faceup (&rest lines) | 52 | (defun whitespace-tests--faceup (&rest lines) |
| 46 | "Convenience wrapper around `faceup-test-font-lock-buffer'. | 53 | "Convenience wrapper around `faceup-test-font-lock-buffer'. |
| 47 | Returns non-nil if the concatenated LINES match the current | 54 | Returns non-nil if the concatenated LINES match the current |
| @@ -337,6 +344,74 @@ buffer's content." | |||
| 337 | (whitespace-mode 1) | 344 | (whitespace-mode 1) |
| 338 | (should (not (buffer-modified-p)))))) | 345 | (should (not (buffer-modified-p)))))) |
| 339 | 346 | ||
| 347 | (ert-deftest whitespace-tests--indirect-clone-breaks-base-markers () | ||
| 348 | "Specific regression test for Bug#59618." | ||
| 349 | (whitespace-tests--with-test-buffer '(face empty) | ||
| 350 | (insert "\nx\n\n") | ||
| 351 | (let ((base (current-buffer)) | ||
| 352 | ;; `unwind-protect' is not used to clean up `indirect' | ||
| 353 | ;; because the buffer should only be killed on success. | ||
| 354 | (indirect (clone-indirect-buffer (buffer-name) nil))) | ||
| 355 | (should (eq (marker-buffer whitespace-bob-marker) base)) | ||
| 356 | (should (eq (marker-buffer whitespace-eob-marker) base)) | ||
| 357 | (whitespace--with-buffer-selected indirect | ||
| 358 | ;; Mutate the indirect buffer to update its bob/eob markers. | ||
| 359 | (execute-kbd-macro (kbd "z RET M-< a"))) | ||
| 360 | ;; With Bug#59618, the above mutation would cause the base | ||
| 361 | ;; buffer's markers to point inside the indirect buffer because | ||
| 362 | ;; the indirect buffer erroneously shared marker objects with | ||
| 363 | ;; the base buffer. Killing the indirect buffer would then | ||
| 364 | ;; invalidate those markers (make them point nowhere). | ||
| 365 | (kill-buffer indirect) | ||
| 366 | (should (eq (marker-buffer whitespace-bob-marker) base)) | ||
| 367 | (should (eq (marker-buffer whitespace-eob-marker) base))))) | ||
| 368 | |||
| 369 | (defun whitespace-tests--check-markers (buf bpos epos) | ||
| 370 | (with-current-buffer buf | ||
| 371 | (should (eq (marker-buffer whitespace-bob-marker) buf)) | ||
| 372 | (should (eq (marker-position whitespace-bob-marker) bpos)) | ||
| 373 | (should (eq (marker-buffer whitespace-eob-marker) buf)) | ||
| 374 | (should (eq (marker-position whitespace-eob-marker) epos)))) | ||
| 375 | |||
| 376 | (ert-deftest whitespace-tests--indirect-clone-markers () | ||
| 377 | "Test `whitespace--clone' on indirect clones." | ||
| 378 | (whitespace-tests--with-test-buffer '(face empty) | ||
| 379 | (insert "\nx\n\n") | ||
| 380 | (let ((base (current-buffer)) | ||
| 381 | ;; `unwind-protect' is not used to clean up `indirect' | ||
| 382 | ;; because the buffer should only be killed on success. | ||
| 383 | (indirect (clone-indirect-buffer nil nil))) | ||
| 384 | (whitespace-tests--check-markers base 2 4) | ||
| 385 | (whitespace--with-buffer-selected indirect | ||
| 386 | (whitespace-tests--check-markers indirect 2 4) | ||
| 387 | ;; Mutate the buffer to trigger `after-change-functions' and | ||
| 388 | ;; thus `whitespace--update-bob-eob'. | ||
| 389 | (execute-kbd-macro (kbd "z RET M-< a")) | ||
| 390 | (whitespace-tests--check-markers indirect 1 8)) | ||
| 391 | (kill-buffer indirect) | ||
| 392 | ;; When the buffer was modified above, the new "a" character at | ||
| 393 | ;; the beginning moved the base buffer's markers by one. Emacs | ||
| 394 | ;; did not run the base buffer's `after-change-functions' after | ||
| 395 | ;; the indirect buffer was edited (Bug#46982), so the end result | ||
| 396 | ;; is just the shift by one. | ||
| 397 | (whitespace-tests--check-markers base 3 5)))) | ||
| 398 | |||
| 399 | (ert-deftest whitespace-tests--regular-clone-markers () | ||
| 400 | "Test `whitespace--clone' on regular clones." | ||
| 401 | (whitespace-tests--with-test-buffer '(face empty) | ||
| 402 | (insert "\nx\n\n") | ||
| 403 | (let ((orig (current-buffer)) | ||
| 404 | ;; `unwind-protect' is not used to clean up `clone' because | ||
| 405 | ;; the buffer should only be killed on success. | ||
| 406 | (clone (clone-buffer))) | ||
| 407 | (whitespace-tests--check-markers orig 2 4) | ||
| 408 | (whitespace--with-buffer-selected clone | ||
| 409 | (whitespace-tests--check-markers clone 2 4) | ||
| 410 | (execute-kbd-macro (kbd "z RET M-< a")) | ||
| 411 | (whitespace-tests--check-markers clone 1 8)) | ||
| 412 | (kill-buffer clone) | ||
| 413 | (whitespace-tests--check-markers orig 2 4)))) | ||
| 414 | |||
| 340 | (provide 'whitespace-tests) | 415 | (provide 'whitespace-tests) |
| 341 | 416 | ||
| 342 | ;;; whitespace-tests.el ends here | 417 | ;;; whitespace-tests.el ends here |