diff options
| author | F. Jason Park | 2023-06-27 20:47:26 -0700 |
|---|---|---|
| committer | F. Jason Park | 2023-07-01 07:19:51 -0700 |
| commit | 99d74dcd45938e2686d93eb5649800e14a88cd84 (patch) | |
| tree | 4d1dfe430b80b4690aac5c5499c6b5b087431317 /test | |
| parent | d42b45dcc7504deb9d1e7b730fed69e18f958533 (diff) | |
| download | emacs-99d74dcd45938e2686d93eb5649800e14a88cd84.tar.gz emacs-99d74dcd45938e2686d93eb5649800e14a88cd84.zip | |
Account for leading timestamps in erc-match
* lisp/erc/erc-match.el (erc-text-matched-hook): Mention that stamps
may be present in the narrowed buffer but absent from the message
parameter.
(erc-match--message): New function containing what was the body of
`erc-match-message' as if the latter were simply renamed.
(erc-match-message): Move body to `erc-match--message' and call it
with more aggressive narrowing. This fixes a regression stemming from
d880a08f "Cement ordering of essential hook members in ERC". Special
thanks to Libera.Chat user jrm for reporting this bug. (Bug#60936)
* test/lisp/erc/erc-scenarios-match.el: New test file.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/erc/erc-scenarios-match.el | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/test/lisp/erc/erc-scenarios-match.el b/test/lisp/erc/erc-scenarios-match.el new file mode 100644 index 00000000000..49e6a3370fc --- /dev/null +++ b/test/lisp/erc/erc-scenarios-match.el | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | ;;; erc-scenarios-match.el --- Misc `erc-match' scenarios -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2023 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Code: | ||
| 21 | |||
| 22 | (require 'ert-x) | ||
| 23 | (eval-and-compile | ||
| 24 | (let ((load-path (cons (ert-resource-directory) load-path))) | ||
| 25 | (require 'erc-scenarios-common))) | ||
| 26 | |||
| 27 | (require 'erc-stamp) | ||
| 28 | (require 'erc-match) | ||
| 29 | |||
| 30 | ;; This defends against a regression in which all matching by the | ||
| 31 | ;; `erc-match-message' fails when `erc-add-timestamp' precedes it in | ||
| 32 | ;; `erc-insert-modify-hook'. Basically, `erc-match-message' used to | ||
| 33 | ;; expect an `erc-parsed' text property on the first character in a | ||
| 34 | ;; message, which doesn't exist, when the message content is prefixed | ||
| 35 | ;; by a leading timestamp. | ||
| 36 | |||
| 37 | (ert-deftest erc-scenarios-match--stamp-left-current-nick () | ||
| 38 | :tags '(:expensive-test) | ||
| 39 | (erc-scenarios-common-with-cleanup | ||
| 40 | ((erc-scenarios-common-dialog "base/reconnect") | ||
| 41 | (dumb-server (erc-d-run "localhost" t 'unexpected-disconnect)) | ||
| 42 | (port (process-contact dumb-server :service)) | ||
| 43 | (erc-server-flood-penalty 0.1) | ||
| 44 | (erc-insert-timestamp-function 'erc-insert-timestamp-left) | ||
| 45 | (expect (erc-d-t-make-expecter))) | ||
| 46 | |||
| 47 | (ert-info ("Connect") | ||
| 48 | (with-current-buffer (erc :server "127.0.0.1" | ||
| 49 | :port port | ||
| 50 | :full-name "tester" | ||
| 51 | :nick "tester") | ||
| 52 | (should (memq 'erc-match-message | ||
| 53 | (memq 'erc-add-timestamp erc-insert-modify-hook))) | ||
| 54 | ;; The "match type" is `current-nick'. | ||
| 55 | (funcall expect 5 "tester") | ||
| 56 | (should (eq (get-text-property (1- (point)) 'font-lock-face) | ||
| 57 | 'erc-current-nick-face)))))) | ||
| 58 | |||
| 59 | ;; This asserts that when stamps appear before a message, | ||
| 60 | ;; some non-nil invisibility property spans the entire message. | ||
| 61 | (ert-deftest erc-scenarios-match--stamp-left-fools-invisible () | ||
| 62 | :tags '(:expensive-test) | ||
| 63 | (erc-scenarios-common-with-cleanup | ||
| 64 | ((erc-scenarios-common-dialog "join/legacy") | ||
| 65 | (dumb-server (erc-d-run "localhost" t 'foonet)) | ||
| 66 | (port (process-contact dumb-server :service)) | ||
| 67 | (erc-server-flood-penalty 0.1) | ||
| 68 | (erc-insert-timestamp-function 'erc-insert-timestamp-left) | ||
| 69 | (erc-timestamp-only-if-changed-flag nil) | ||
| 70 | (erc-fools '("bob")) | ||
| 71 | (erc-text-matched-hook '(erc-hide-fools)) | ||
| 72 | (erc-autojoin-channels-alist '((FooNet "#chan"))) | ||
| 73 | (expect (erc-d-t-make-expecter)) | ||
| 74 | (hiddenp (lambda () | ||
| 75 | (and (eq (field-at-pos (pos-bol)) 'erc-timestamp) | ||
| 76 | (get-text-property (pos-bol) 'invisible) | ||
| 77 | (>= (next-single-property-change (pos-bol) | ||
| 78 | 'invisible nil) | ||
| 79 | (pos-eol)))))) | ||
| 80 | |||
| 81 | (ert-info ("Connect") | ||
| 82 | (with-current-buffer (erc :server "127.0.0.1" | ||
| 83 | :port port | ||
| 84 | :full-name "tester" | ||
| 85 | :password "changeme" | ||
| 86 | :nick "tester") | ||
| 87 | (should (memq 'erc-match-message | ||
| 88 | (memq 'erc-add-timestamp erc-insert-modify-hook))) | ||
| 89 | (funcall expect 5 "This server is in debug mode"))) | ||
| 90 | |||
| 91 | (ert-info ("Ensure lines featuring \"bob\" are invisible") | ||
| 92 | (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan")) | ||
| 93 | (should (funcall expect 10 "<bob> tester, welcome!")) | ||
| 94 | (should (funcall hiddenp)) | ||
| 95 | |||
| 96 | ;; Alice's is the only one visible. | ||
| 97 | (should (funcall expect 10 "<alice> tester, welcome!")) | ||
| 98 | (should (eq (field-at-pos (pos-bol)) 'erc-timestamp)) | ||
| 99 | (should (get-text-property (pos-bol) 'invisible)) | ||
| 100 | (should-not (get-text-property (point) 'invisible)) | ||
| 101 | |||
| 102 | (should (funcall expect 10 "<bob> alice: But, as it seems")) | ||
| 103 | (should (funcall hiddenp)) | ||
| 104 | |||
| 105 | (should (funcall expect 10 "<alice> bob: Well, this is the forest")) | ||
| 106 | (should (funcall hiddenp)) | ||
| 107 | |||
| 108 | (should (funcall expect 10 "<alice> bob: And will you")) | ||
| 109 | (should (funcall hiddenp)) | ||
| 110 | |||
| 111 | (should (funcall expect 10 "<bob> alice: Live, and be prosperous")) | ||
| 112 | (should (funcall hiddenp)) | ||
| 113 | |||
| 114 | (should (funcall expect 10 "ERC>")) | ||
| 115 | (should-not (get-text-property (pos-bol) 'invisible)) | ||
| 116 | (should-not (get-text-property (point) 'invisible)))))) | ||
| 117 | |||
| 118 | (eval-when-compile (require 'erc-join)) | ||
| 119 | |||
| 120 | ;;; erc-scenarios-match.el ends here | ||