aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park2021-10-07 14:26:36 +0200
committerF. Jason Park2023-11-24 13:38:52 -0800
commit2ed9c9f1b3230bb99b60646fe1cf46664453f693 (patch)
tree00fbb23f7283648d87e598bd6d98cec51f3629ab /test
parent7cbe6ae7124cade32bce1268212e2279dcb6df20 (diff)
downloademacs-2ed9c9f1b3230bb99b60646fe1cf46664453f693.tar.gz
emacs-2ed9c9f1b3230bb99b60646fe1cf46664453f693.zip
Optionally allow substitution patterns in erc-prompt
* etc/ERC-NEWS: Add entry for `erc-prompt-format'. * lisp/erc/erc-compat.el (erc-compat--defer-format-spec-in-buffer): New macro to wrap `format-spec' specification values in functions that run in the current buffer and fall back to the empty string. * lisp/erc/erc.el (erc-prompt): Add predefined Custom choice for function type in `erc-prompt-format'. (erc--prompt-format-face-example): New "pre-propertized" value for option `erc-prompt-format'. (erc-prompt-format): New companion option for `erc-prompt' choice `erc-prompt-format'. New function of the same name to perform format substitutions and serve as a Custom choice value for `erc-prompt'. Based on work and ideas originally proposed by Stefan Kangas. (erc--away-indicator, erc-away-status-indicator, erc--format-away-indicator): New formatting function and helper variables for displaying short away status. (erc--user-modes-indicator): New variable. (erc--format-user-modes): New function. (erc--format-channel-status-prefix): New function. (erc--format-modes): New function. * test/lisp/erc/erc-scenarios-prompt-format.el: New file. (Bug#51082) Co-authored-by: Stefan Kangas <stefankangas@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-scenarios-prompt-format.el117
1 files changed, 117 insertions, 0 deletions
diff --git a/test/lisp/erc/erc-scenarios-prompt-format.el b/test/lisp/erc/erc-scenarios-prompt-format.el
new file mode 100644
index 00000000000..7eccb859dbc
--- /dev/null
+++ b/test/lisp/erc/erc-scenarios-prompt-format.el
@@ -0,0 +1,117 @@
1;;; erc-scenarios-prompt-format.el --- erc-prompt-format-mode -*- 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(defvar erc-fill-wrap-align-prompt)
28(defvar erc-fill-wrap-use-pixels)
29
30(defun erc-scenarios-prompt-format--assert (needle &rest props)
31 (save-excursion
32 (goto-char erc-insert-marker)
33 (should (search-forward needle nil t))
34 (pcase-dolist (`(,k . ,v) props)
35 (should (equal (get-text-property (point) k) v)))))
36
37;; This makes assertions about the option `erc-fill-wrap-align-prompt'
38;; as well as the standard value of `erc-prompt-format'. One minor
39;; omission is that this doesn't check behavior in query buffers.
40(ert-deftest erc-scenarios-prompt-format ()
41 :tags '(:expensive-test)
42 (erc-scenarios-common-with-cleanup
43 ((erc-scenarios-common-dialog "base/modes")
44 (erc-server-flood-penalty 0.1)
45 (dumb-server (erc-d-run "localhost" t 'chan-changed))
46 (erc-modules (cons 'fill-wrap erc-modules))
47 (erc-fill-wrap-align-prompt t)
48 (erc-fill-wrap-use-pixels nil)
49 (erc-prompt #'erc-prompt-format)
50 (erc-autojoin-channels-alist '((Libera.Chat "#chan")))
51 (expect (erc-d-t-make-expecter))
52 ;; Collect samples of `line-prefix' to verify deltas as the
53 ;; prompt grows and shrinks.
54 (line-prefixes nil)
55 (stash-pfx (lambda ()
56 (pcase (get-text-property erc-insert-marker 'line-prefix)
57 (`(space :width (- erc-fill--wrap-value ,n))
58 (car (push n line-prefixes)))))))
59
60 (ert-info ("Connect to Libera.Chat")
61 (with-current-buffer (erc :server "127.0.0.1"
62 :port (process-contact dumb-server :service)
63 :nick "tester"
64 :full-name "tester")
65 (funcall expect 5 "Welcome to the Libera.Chat")
66 (funcall stash-pfx)
67 (funcall expect 5 "changed mode")
68 ;; New prompt is shorter than default with placeholders, like
69 ;; "(foo?)(bar?)" (assuming we win the inherent race).
70 (should (>= (car line-prefixes) (funcall stash-pfx)))
71 (erc-scenarios-prompt-format--assert "user-" '(display . ("Ziw")))))
72
73 (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan"))
74 (should-not erc-channel-key)
75 (should-not erc-channel-user-limit)
76
77 (ert-info ("Receive notice that mode has changed")
78 (erc-d-t-wait-for 10 (equal erc-channel-modes '("n" "t")))
79 (funcall stash-pfx)
80 (erc-scenarios-common-say "ready before")
81 (funcall expect 10 " has changed mode for #chan to +Qu")
82 (erc-d-t-wait-for 10 (equal erc-channel-modes '("Q" "n" "t" "u")))
83 ;; Prompt is longer now, so too is the `line-prefix' subtrahend.
84 (should (< (car line-prefixes) (funcall stash-pfx)))
85 (erc-scenarios-prompt-format--assert "Qntu")
86 (erc-scenarios-prompt-format--assert "#chan>"))
87
88 (ert-info ("Key stored locally")
89 (erc-scenarios-common-say "ready key")
90 (funcall expect 10 " has changed mode for #chan to +k hunter2")
91 ;; Prompt has grown by 1.
92 (should (< (car line-prefixes) (funcall stash-pfx)))
93 (erc-scenarios-prompt-format--assert "Qkntu"))
94
95 (ert-info ("Limit stored locally")
96 (erc-scenarios-common-say "ready limit")
97 (funcall expect 10 " has changed mode for #chan to +l 3")
98 (erc-d-t-wait-for 10 (eql erc-channel-user-limit 3))
99 (should (equal erc-channel-modes '("Q" "n" "t" "u")))
100 ;; Prompt has grown by 1 again.
101 (should (< (car line-prefixes) (funcall stash-pfx)))
102 (erc-scenarios-prompt-format--assert "Qklntu"))
103
104 (ert-info ("Modes removed and local state deletion succeeds")
105 (erc-scenarios-common-say "ready drop")
106 (funcall expect 10 " has changed mode for #chan to -lu")
107 (funcall expect 10 " has changed mode for #chan to -Qk *")
108 (erc-d-t-wait-for 10 (equal erc-channel-modes '("n" "t")))
109 ;; Prompt has shrunk.
110 (should (> (car line-prefixes) (funcall stash-pfx)))
111 (erc-scenarios-prompt-format--assert "nt"))
112
113 (should-not erc-channel-key)
114 (should-not erc-channel-user-limit)
115 (funcall expect 10 "<Chad> after"))))
116
117;;; erc-scenarios-prompt-format.el ends here