aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park2023-04-10 17:58:05 -0700
committerF. Jason Park2023-05-05 17:18:01 -0700
commit2e18ba6302f3e4aa5485eeaca39c747beb55ca8f (patch)
treee8d2172243a5e3f03d70f11e428a893fbbaf5687 /test
parent2641dfd4b4334942282358b50d74f75424ebf4fa (diff)
downloademacs-2e18ba6302f3e4aa5485eeaca39c747beb55ca8f.tar.gz
emacs-2e18ba6302f3e4aa5485eeaca39c747beb55ca8f.zip
Simplify erc-button movement commands
* etc/ERC-NEWS: Mention TAB being bound to new command `erc-tab' and `erc-previous-button' now stopping at the start of buttons. * lisp/erc/erc-button.el (erc-button-mode, erc-button-enable, erc-button-disable): Add and remove `erc-button-next' to `erc--tab-functions' hook, which is tantamount to binding the command in the read-only area of an ERC buffer. (erc-button-next-function): Deprecate and remove from client code path because this module doesn't concern itself with prompt input and thus no longer needs to conform to the `completion-at-point-functions' interface. (erc-button--prev-next-predicate-functions): New variable, a hook to determine whether to continue searching for a button. Other modules should utilize this as needed. (erc-button--end-of-button-p): Add function to serve as default value for `erc-button--continue-predicate'. (erc--button-next): Add generalized button-movement function. (erc-button-next, erc-button-previous): Make `erc-button-previous' behave more predictably by having it land at the beginning of buttons. And remove roundabout appeal to HOF in `erc-button-next'. (erc-button-previous-of-nick): New command to jump to previous appearance of nick at point. * lisp/erc/erc-fill.el (erc-fill-wrap, erc-fill-wrap-enable, erc-fill-wrap-disable): Add and remove merge-related hookee from `erc-button--prev-next-predicate-functions'. (erc-fill--wrap-merged-button-p): New function to detect redundant speakers. * lisp/erc/erc.el (erc-complete-functions): Quote TAB in doc string. (erc-mode-map): Bind `erc-tab' to TAB. (erc--tab-functions, erc-tab): Add new command and hook to serve as unified dispatch for TAB-related operations. It calls `c-a-p' in the input area and defers to module code in the read-only message area. * test/lisp/erc/erc-button-tests.el: New file. * test/lisp/erc/erc-fill-tests.el (erc-fill-tests--wrap-populate): Run finalizer for transient keymap timer. * test/lisp/erc/erc-tests.el (erc-button--display-error-notice-with-keys): Move to new dedicated test file for erc-button and fix expected behavior of `erc-button-previous'. (Bug#62834)
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-button-tests.el177
-rw-r--r--test/lisp/erc/erc-fill-tests.el2
-rw-r--r--test/lisp/erc/erc-tests.el61
3 files changed, 179 insertions, 61 deletions
diff --git a/test/lisp/erc/erc-button-tests.el b/test/lisp/erc/erc-button-tests.el
new file mode 100644
index 00000000000..ced08d117bc
--- /dev/null
+++ b/test/lisp/erc/erc-button-tests.el
@@ -0,0 +1,177 @@
1;;; erc-button-tests.el --- Tests for erc-button -*- 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
9;; by the Free Software Foundation, either version 3 of the License,
10;; or (at your option) any later version.
11;;
12;; GNU Emacs is distributed in the hope that it will be useful, but
13;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15;; 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;;; Commentary:
21
22;;; Code:
23
24(require 'erc-button)
25
26(defun erc-button-tests--insert-privmsg (speaker &rest msg-parts)
27 (declare (indent 1))
28 (let ((msg (erc-format-privmessage speaker
29 (apply #'concat msg-parts) nil t)))
30 (erc-display-message nil nil (current-buffer) msg)))
31
32(defun erc-button-tests--populate (test)
33 (let ((inhibit-message noninteractive)
34 erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
35
36 (with-current-buffer
37 (cl-letf
38 (((symbol-function 'erc-server-connect)
39 (lambda (&rest _)
40 (setq erc-server-process
41 (start-process "sleep" (current-buffer) "sleep" "1"))
42 (set-process-query-on-exit-flag erc-server-process nil))))
43
44 (erc-open "localhost" 6667 "tester" "Tester" 'connect
45 nil nil nil nil nil "tester" 'foonet))
46
47 (with-current-buffer (erc--open-target "#chan")
48 (erc-update-channel-member
49 "#chan" "alice" "alice" t nil nil nil nil nil "fake" "~u" nil nil t)
50
51 (erc-update-channel-member
52 "#chan" "bob" "bob" t nil nil nil nil nil "fake" "~u" nil nil t)
53
54 (erc-display-message
55 nil 'notice (current-buffer)
56 (concat "This server is in debug mode and is logging all user I/O. "
57 "Blah alice (1) bob (2) blah."))
58
59 (funcall test))
60
61 (when noninteractive
62 (kill-buffer "#chan")
63 (kill-buffer)))))
64
65(ert-deftest erc-button-next ()
66 (erc-button-tests--populate
67 (lambda ()
68 (erc-button-tests--insert-privmsg "alice"
69 "(3) bob (4) come, you are a tedious fool: to the purpose.")
70
71 (erc-button-tests--insert-privmsg "bob"
72 "(5) alice (6) Come me to what was done to her.")
73
74 (should (= erc-input-marker (point)))
75
76 ;; Break out of input area
77 (erc-button-previous 1)
78 (should (looking-at (rx "alice (6)")))
79
80 ;; No next button
81 (should-error (erc-button-next 1) :type 'user-error)
82 (should (looking-at (rx "alice (6)")))
83
84 ;; Next with negative arg is equivalent to previous
85 (erc-button-next -1)
86 (should (looking-at (rx "bob> (5)")))
87
88 ;; One past end of button
89 (forward-char 3)
90 (should (looking-at (rx "> (5)")))
91 (should-not (get-text-property (point) 'erc-callback))
92 (erc-button-previous 1)
93 (should (looking-at (rx "bob> (5)")))
94
95 ;; At end of button
96 (forward-char 2)
97 (should (looking-at (rx "b> (5)")))
98 (erc-button-previous 1)
99 (should (looking-at (rx "bob (4)")))
100
101 ;; Skip multiple buttons back
102 (erc-button-previous 2)
103 (should (looking-at (rx "bob (2)")))
104
105 ;; Skip multiple buttons forward
106 (erc-button-next 2)
107 (should (looking-at (rx "bob (4)")))
108
109 ;; No error as long as some progress made
110 (erc-button-previous 100)
111 (should (looking-at (rx "alice (1)")))
112
113 ;; Error when no progress made
114 (should-error (erc-button-previous 1) :type 'user-error)
115 (should (looking-at (rx "alice (1)"))))))
116
117;; See also `erc-scenarios-networks-announced-missing' in
118;; erc-scenarios-misc.el for a more realistic example.
119(ert-deftest erc-button--display-error-notice-with-keys ()
120 (with-current-buffer (get-buffer-create "*fake*")
121 (let ((mode erc-button-mode)
122 (inhibit-message noninteractive)
123 erc-modules
124 erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
125 (erc-mode)
126 (setq erc-server-process
127 (start-process "sleep" (current-buffer) "sleep" "1"))
128 (set-process-query-on-exit-flag erc-server-process nil)
129 (erc--initialize-markers (point) nil)
130 (erc-button-mode +1)
131 (should (equal (erc-button--display-error-notice-with-keys
132 "If \\[erc-bol] fails, "
133 "see \\[erc-bug] or `erc-mode-map'.")
134 "*** If C-a fails, see M-x erc-bug or `erc-mode-map'."))
135 (goto-char (point-min))
136
137 (ert-info ("Keymap substitution succeeds")
138 (erc-button-next 1)
139 (should (looking-at "C-a"))
140 (should (eq (get-text-property (point) 'mouse-face) 'highlight))
141 (erc-button-press-button)
142 (with-current-buffer "*Help*"
143 (goto-char (point-min))
144 (should (search-forward "erc-bol" nil t)))
145 (erc-button-next 1)
146 ;; End of interval correct
147 (erc-button-previous 1)
148 (should (looking-at "C-a fails")))
149
150 (ert-info ("Extended command mapping succeeds")
151 (erc-button-next 1)
152 (should (looking-at "M-x erc-bug"))
153 (erc-button-press-button)
154 (should (eq (get-text-property (point) 'mouse-face) 'highlight))
155 (with-current-buffer "*Help*"
156 (goto-char (point-min))
157 (should (search-forward "erc-bug" nil t))))
158
159 (ert-info ("Symbol-description face preserved") ; mutated by d-e-n-w-k
160 (erc-button-next 1)
161 (should (equal (get-text-property (point) 'font-lock-face)
162 '(erc-button erc-error-face)))
163 (should (eq (get-text-property (point) 'mouse-face) 'highlight))
164 (should (eq erc-button-face 'erc-button))) ; extent evaporates
165
166 (ert-info ("Format when trailing args include non-strings")
167 (should (equal (erc-button--display-error-notice-with-keys
168 "abc" " %d def" " 45%s" 123 '\6)
169 "*** abc 123 def 456")))
170
171 (when noninteractive
172 (unless mode
173 (erc-button-mode -1))
174 (kill-buffer "*Help*")
175 (kill-buffer)))))
176
177;;; erc-button-tests.el ends here
diff --git a/test/lisp/erc/erc-fill-tests.el b/test/lisp/erc/erc-fill-tests.el
index e8dd25e8ea1..170436ffbaa 100644
--- a/test/lisp/erc/erc-fill-tests.el
+++ b/test/lisp/erc/erc-fill-tests.el
@@ -94,6 +94,8 @@
94 ;; Defend against non-local exits from `ert-skip' 94 ;; Defend against non-local exits from `ert-skip'
95 (unwind-protect 95 (unwind-protect
96 (funcall test) 96 (funcall test)
97 (when set-transient-map-timer
98 (timer-event-handler set-transient-map-timer))
97 (set-window-buffer (selected-window) original-window-buffer) 99 (set-window-buffer (selected-window) original-window-buffer)
98 (when noninteractive 100 (when noninteractive
99 (while-let ((buf (pop erc-fill-tests--buffers))) 101 (while-let ((buf (pop erc-fill-tests--buffers)))
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 88b9babf206..5aaf7e499e3 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -2110,65 +2110,4 @@ connection."
2110 (put 'erc-mname-enable 'definition-name 'mname) 2110 (put 'erc-mname-enable 'definition-name 'mname)
2111 (put 'erc-mname-disable 'definition-name 'mname)))))) 2111 (put 'erc-mname-disable 'definition-name 'mname))))))
2112 2112
2113
2114;; XXX move erc-button tests to new file if more added.
2115(require 'erc-button)
2116
2117;; See also `erc-scenarios-networks-announced-missing' in
2118;; erc-scenarios-misc.el for a more realistic example.
2119(ert-deftest erc-button--display-error-notice-with-keys ()
2120 (with-current-buffer (get-buffer-create "*fake*")
2121 (let ((mode erc-button-mode)
2122 (inhibit-message noninteractive)
2123 erc-modules
2124 erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
2125 (erc-mode)
2126 (erc-tests--set-fake-server-process "sleep" "1")
2127 (erc--initialize-markers (point) nil)
2128 (erc-button-mode +1)
2129 (should (equal (erc-button--display-error-notice-with-keys
2130 "If \\[erc-bol] fails, "
2131 "see \\[erc-bug] or `erc-mode-map'.")
2132 "*** If C-a fails, see M-x erc-bug or `erc-mode-map'."))
2133 (goto-char (point-min))
2134
2135 (ert-info ("Keymap substitution succeeds")
2136 (erc-button-next)
2137 (should (looking-at "C-a"))
2138 (should (eq (get-text-property (point) 'mouse-face) 'highlight))
2139 (erc-button-press-button)
2140 (with-current-buffer "*Help*"
2141 (goto-char (point-min))
2142 (should (search-forward "erc-bol" nil t)))
2143 (erc-button-next)
2144 (erc-button-previous) ; end of interval correct
2145 (should (looking-at "a fails")))
2146
2147 (ert-info ("Extended command mapping succeeds")
2148 (erc-button-next)
2149 (should (looking-at "M-x erc-bug"))
2150 (erc-button-press-button)
2151 (should (eq (get-text-property (point) 'mouse-face) 'highlight))
2152 (with-current-buffer "*Help*"
2153 (goto-char (point-min))
2154 (should (search-forward "erc-bug" nil t))))
2155
2156 (ert-info ("Symbol-description face preserved") ; mutated by d-e-n-w-k
2157 (erc-button-next)
2158 (should (equal (get-text-property (point) 'font-lock-face)
2159 '(erc-button erc-error-face)))
2160 (should (eq (get-text-property (point) 'mouse-face) 'highlight))
2161 (should (eq erc-button-face 'erc-button))) ; extent evaporates
2162
2163 (ert-info ("Format when trailing args include non-strings")
2164 (should (equal (erc-button--display-error-notice-with-keys
2165 "abc" " %d def" " 45%s" 123 '\6)
2166 "*** abc 123 def 456")))
2167
2168 (when noninteractive
2169 (unless mode
2170 (erc-button-mode -1))
2171 (kill-buffer "*Help*")
2172 (kill-buffer)))))
2173
2174;;; erc-tests.el ends here 2113;;; erc-tests.el ends here