diff options
| author | F. Jason Park | 2023-10-18 23:20:07 -0700 |
|---|---|---|
| committer | F. Jason Park | 2023-10-20 14:53:24 -0700 |
| commit | bcebda5eec2166e475579c2aa2ee425aeabbb505 (patch) | |
| tree | cfc3e9646f1d30639bae321292da52c3bf974dd1 /test | |
| parent | 47612514a9e04d6f41568c3f0cdeae837c2eae19 (diff) | |
| download | emacs-bcebda5eec2166e475579c2aa2ee425aeabbb505.tar.gz emacs-bcebda5eec2166e475579c2aa2ee425aeabbb505.zip | |
Respect user markers in erc-insert-timestamp-left
* lisp/erc/erc-stamp.el (erc-insert-timestamp-left): Convert to normal
function, a mere wrapper that defers to existing generic variants, in
order to dissuade users from adding their own methods, which could
complicate troubleshooting, etc.
(erc--insert-timestamp-left): Rename both methods using internal
double-hyphen convention. In `erc-stamp--display-margin-mode'
implementation, don't displace third-party markers.
* test/lisp/erc/erc-scenarios-stamp.el: New file. (Bug#60936)
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/erc/erc-scenarios-stamp.el | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/test/lisp/erc/erc-scenarios-stamp.el b/test/lisp/erc/erc-scenarios-stamp.el new file mode 100644 index 00000000000..d6b5d868ce5 --- /dev/null +++ b/test/lisp/erc/erc-scenarios-stamp.el | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | ;;; erc-scenarios-stamp.el --- Misc `erc-stamp' 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 | |||
| 29 | (defvar erc-scenarios-stamp--user-marker nil) | ||
| 30 | |||
| 31 | (defun erc-scenarios-stamp--on-post-modify () | ||
| 32 | (when-let (((erc--check-msg-prop 'erc-cmd 4))) | ||
| 33 | (set-marker erc-scenarios-stamp--user-marker (point-max)) | ||
| 34 | (ert-info ("User marker correctly placed at `erc-insert-marker'") | ||
| 35 | (should (= ?\n (char-before erc-scenarios-stamp--user-marker))) | ||
| 36 | (should (= erc-scenarios-stamp--user-marker erc-insert-marker)) | ||
| 37 | (save-excursion | ||
| 38 | (goto-char erc-scenarios-stamp--user-marker) | ||
| 39 | ;; The raw message ends in " Iabefhkloqv". However, | ||
| 40 | ;; `erc-server-004' only prints up to the 5th parameter. | ||
| 41 | (should (looking-back "CEIMRUabefhiklmnoqstuv\n")))))) | ||
| 42 | |||
| 43 | (ert-deftest erc-scenarios-stamp--left/display-margin-mode () | ||
| 44 | |||
| 45 | (erc-scenarios-common-with-cleanup | ||
| 46 | ((erc-scenarios-common-dialog "base/reconnect") | ||
| 47 | (dumb-server (erc-d-run "localhost" t 'unexpected-disconnect)) | ||
| 48 | (port (process-contact dumb-server :service)) | ||
| 49 | (erc-scenarios-stamp--user-marker (make-marker)) | ||
| 50 | (erc-stamp--current-time 704591940) | ||
| 51 | (erc-stamp--tz t) | ||
| 52 | (erc-server-flood-penalty 0.1) | ||
| 53 | (erc-timestamp-only-if-changed-flag nil) | ||
| 54 | (erc-insert-timestamp-function #'erc-insert-timestamp-left) | ||
| 55 | (erc-modules (cons 'fill-wrap erc-modules)) | ||
| 56 | (erc-timestamp-only-if-changed-flag nil) | ||
| 57 | (expect (erc-d-t-make-expecter))) | ||
| 58 | |||
| 59 | (ert-info ("Connect") | ||
| 60 | (with-current-buffer (erc :server "127.0.0.1" | ||
| 61 | :port port | ||
| 62 | :full-name "tester" | ||
| 63 | :nick "tester") | ||
| 64 | |||
| 65 | (add-hook 'erc-insert-post-hook #'erc-scenarios-stamp--on-post-modify | ||
| 66 | nil t) | ||
| 67 | (funcall expect 5 "This server is in debug mode") | ||
| 68 | |||
| 69 | (ert-info ("Stamps appear in left margin and are invisible") | ||
| 70 | (should (eq 'erc-timestamp (field-at-pos (pos-bol)))) | ||
| 71 | (should (= (pos-bol) (field-beginning (pos-bol)))) | ||
| 72 | (should (eq 'msg (get-text-property (pos-bol) 'erc-msg))) | ||
| 73 | (should (eq 'NOTICE (get-text-property (pos-bol) 'erc-cmd))) | ||
| 74 | (should (= ?- (char-after (field-end (pos-bol))))) | ||
| 75 | (should (equal (get-text-property (1+ (field-end (pos-bol))) | ||
| 76 | 'erc-speaker) | ||
| 77 | "irc.foonet.org")) | ||
| 78 | (should (pcase (get-text-property (pos-bol) 'display) | ||
| 79 | (`((margin left-margin) ,s) | ||
| 80 | (eq 'timestamp (get-text-property 0 'invisible s)))))) | ||
| 81 | |||
| 82 | ;; We set a third-party marker at the end of 004's message (on | ||
| 83 | ;; then "\n"), post-insertion. | ||
| 84 | (ert-info ("User markers untouched by subsequent message left stamp") | ||
| 85 | (save-excursion | ||
| 86 | (goto-char erc-scenarios-stamp--user-marker) | ||
| 87 | (should (looking-back "CEIMRUabefhiklmnoqstuv\n")) | ||
| 88 | (should (looking-at (rx "["))))))))) | ||
| 89 | |||
| 90 | ;;; erc-scenarios-stamp.el ends here | ||