diff options
| author | Matthias Meulien | 2025-05-08 16:51:46 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2025-05-31 15:21:21 +0300 |
| commit | 6f8cee03316e166e4204ba49fbb9964a075968ca (patch) | |
| tree | 189b3e11f5281d9763376f30c0bd2453bdca1dd8 /test | |
| parent | 32d911cddfd6ccdf288247a5d7eaf3d9a977b87c (diff) | |
| download | emacs-6f8cee03316e166e4204ba49fbb9964a075968ca.tar.gz emacs-6f8cee03316e166e4204ba49fbb9964a075968ca.zip | |
ansi-osc.el: Use marker (bug#78184)
* lisp/ansi-osc.el (ansi-osc-apply-on-region)
(ansi-osc-filter-region): Use marker to properly handle
unfinished escape sequence.
* test/lisp/ansi-osc-tests.el (ansi-osc-tests--strings)
(ansi-osc-tests-apply-region-no-handlers)
(ansi-osc-tests-apply-region-no-handlers-multiple-calls)
(ansi-osc-tests-filter-region)
(ansi-osc-tests-filter-region-with-multiple-calls): Cover
bug#78184.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/ansi-osc-tests.el | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/test/lisp/ansi-osc-tests.el b/test/lisp/ansi-osc-tests.el index d2fb130e518..d083626f3f9 100644 --- a/test/lisp/ansi-osc-tests.el +++ b/test/lisp/ansi-osc-tests.el | |||
| @@ -30,8 +30,7 @@ | |||
| 30 | (require 'ert) | 30 | (require 'ert) |
| 31 | 31 | ||
| 32 | (defvar ansi-osc-tests--strings | 32 | (defvar ansi-osc-tests--strings |
| 33 | `( | 33 | `(("Hello World" "Hello World") |
| 34 | ("Hello World" "Hello World") | ||
| 35 | 34 | ||
| 36 | ;; window title | 35 | ;; window title |
| 37 | ("Buffer \e]2;A window title\e\\content" "Buffer content") | 36 | ("Buffer \e]2;A window title\e\\content" "Buffer content") |
| @@ -44,6 +43,10 @@ | |||
| 44 | 43 | ||
| 45 | ;; hyperlink | 44 | ;; hyperlink |
| 46 | ("\e]8;;http://example.com\e\\This is a link\e]8;;\e\\" "This is a link") | 45 | ("\e]8;;http://example.com\e\\This is a link\e]8;;\e\\" "This is a link") |
| 46 | |||
| 47 | ;; multiple sequences | ||
| 48 | ("Escape \e]2;A window title\e\\sequence followed by \e]2;unfinished sequence" | ||
| 49 | "Escape sequence followed by \e]2;unfinished sequence") | ||
| 47 | )) | 50 | )) |
| 48 | ;; Don't output those strings to stdout since they may have | 51 | ;; Don't output those strings to stdout since they may have |
| 49 | ;; side-effects on the environment | 52 | ;; side-effects on the environment |
| @@ -54,4 +57,44 @@ | |||
| 54 | (with-temp-buffer | 57 | (with-temp-buffer |
| 55 | (insert input) | 58 | (insert input) |
| 56 | (ansi-osc-apply-on-region (point-min) (point-max)) | 59 | (ansi-osc-apply-on-region (point-min) (point-max)) |
| 57 | (should (equal (buffer-string) text)))))) | 60 | (should (equal |
| 61 | (buffer-substring-no-properties | ||
| 62 | (point-min) (point-max)) | ||
| 63 | text)))))) | ||
| 64 | |||
| 65 | (ert-deftest ansi-osc-tests-apply-region-no-handlers-multiple-calls () | ||
| 66 | (let ((ansi-osc-handlers nil)) | ||
| 67 | (with-temp-buffer | ||
| 68 | (insert | ||
| 69 | (concat "First set the window title \e]2;A window title\e\\" | ||
| 70 | "then change it\e]2;Another ")) | ||
| 71 | (ansi-osc-apply-on-region (point-min) (point-max)) | ||
| 72 | (let ((pos (point))) | ||
| 73 | (insert "title\e\\, and stop.") | ||
| 74 | (ansi-osc-apply-on-region pos (point-max))) | ||
| 75 | (should | ||
| 76 | (equal | ||
| 77 | (buffer-substring-no-properties (point-min) (point-max)) | ||
| 78 | "First set the window title then change it, and stop."))))) | ||
| 79 | |||
| 80 | (ert-deftest ansi-osc-tests-filter-region () | ||
| 81 | (pcase-dolist (`(,input ,text) ansi-osc-tests--strings) | ||
| 82 | (with-temp-buffer | ||
| 83 | (insert input) | ||
| 84 | (ansi-osc-filter-region (point-min) (point-max)) | ||
| 85 | (should (equal (buffer-string) text))))) | ||
| 86 | |||
| 87 | |||
| 88 | (ert-deftest ansi-osc-tests-filter-region-with-multiple-calls () | ||
| 89 | (with-temp-buffer | ||
| 90 | (insert | ||
| 91 | (concat "First set the window title \e]2;A window title\e\\" | ||
| 92 | "then change it\e]2;Another ")) | ||
| 93 | (ansi-osc-filter-region (point-min) (point-max)) | ||
| 94 | (let ((pos (point))) | ||
| 95 | (insert "title\e\\, and stop.") | ||
| 96 | (ansi-osc-filter-region pos (point-max))) | ||
| 97 | (should | ||
| 98 | (equal | ||
| 99 | (buffer-string) | ||
| 100 | "First set the window title then change it, and stop.")))) | ||