aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp
diff options
context:
space:
mode:
authorF. Jason Park2023-11-04 11:08:22 -0700
committerF. Jason Park2023-11-04 15:36:24 -0700
commit781f950edab0509f12e3ec4880690ef6541841ee (patch)
tree84354df3801c823ec03520c9fec35eba337c2b00 /test/lisp
parentf7c7f7ac20defe3ee8a32659a6799b20ddd58aeb (diff)
downloademacs-781f950edab0509f12e3ec4880690ef6541841ee.tar.gz
emacs-781f950edab0509f12e3ec4880690ef6541841ee.zip
Preserve user markers when inserting ERC date stamps
* lisp/erc/erc-stamp.el (erc-stamp--insert-date-stamp-as-phony-message): Ensure existing user markers aren't displaced by date-stamp insertion. * lisp/erc/erc.el (erc--insert-line-function): New function-valued variable for overriding `insert'. (erc-insert-line): Call `erc--insert-line-function', when non-nil, to insert line specially. * test/lisp/erc/erc-scenarios-stamp.el (erc-scenarios-stamp--on-insert-modify): New assertion helper function. (erc-scenarios-stamp--date-mode/left-and-right): New test. (Bug#60936)
Diffstat (limited to 'test/lisp')
-rw-r--r--test/lisp/erc/erc-scenarios-stamp.el65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/lisp/erc/erc-scenarios-stamp.el b/test/lisp/erc/erc-scenarios-stamp.el
index b98300d04be..49307dd228a 100644
--- a/test/lisp/erc/erc-scenarios-stamp.el
+++ b/test/lisp/erc/erc-scenarios-stamp.el
@@ -113,4 +113,69 @@
113 (not (eq 'erc-timestamp (field-at-pos (point)))))) 113 (not (eq 'erc-timestamp (field-at-pos (point))))))
114 (should (erc--get-inserted-msg-prop 'erc-cmd))))))) 114 (should (erc--get-inserted-msg-prop 'erc-cmd)))))))
115 115
116;; This user-owned hook member places a marker on the first message in
117;; a buffer. Inserting a date stamp in front of it shouldn't move the
118;; marker.
119(defun erc-scenarios-stamp--on-insert-modify ()
120 (unless (marker-position erc-scenarios-stamp--user-marker)
121 (set-marker erc-scenarios-stamp--user-marker (point-min))
122 (save-excursion
123 (goto-char erc-scenarios-stamp--user-marker)
124 (should (looking-at "Opening"))))
125
126 ;; Sometime after the first message ("Opening connection.."), assert
127 ;; that the marker we just placed hasn't moved.
128 (when (erc--check-msg-prop 'erc-cmd 2)
129 (save-restriction
130 (widen)
131 (ert-info ("Date stamp preserves opening user marker")
132 (goto-char erc-scenarios-stamp--user-marker)
133 (should-not (eq 'erc-timestamp (field-at-pos (point))))
134 (should (looking-at "Opening"))
135 (should (eq 'unknown (get-text-property (point) 'erc-msg))))))
136
137 ;; On 003 ("*** This server was created on"), clear state to force a
138 ;; new date stamp on the next message.
139 (when (erc--check-msg-prop 'erc-cmd 3)
140 (setq erc-timestamp-last-inserted-left nil)
141 (set-marker erc-scenarios-stamp--user-marker erc-insert-marker)))
142
143(ert-deftest erc-scenarios-stamp--date-mode/left-and-right ()
144
145 (should (eq erc-insert-timestamp-function
146 #'erc-insert-timestamp-left-and-right))
147
148 (erc-scenarios-common-with-cleanup
149 ((erc-scenarios-common-dialog "base/reconnect")
150 (dumb-server (erc-d-run "localhost" t 'unexpected-disconnect))
151 (port (process-contact dumb-server :service))
152 (erc-scenarios-stamp--user-marker (make-marker))
153 (erc-server-flood-penalty 0.1)
154 (erc-modules (if (zerop (random 2))
155 (cons 'fill-wrap erc-modules)
156 erc-modules))
157 (expect (erc-d-t-make-expecter))
158 (erc-mode-hook
159 (cons (lambda ()
160 (add-hook 'erc-insert-modify-hook
161 #'erc-scenarios-stamp--on-insert-modify -99 t))
162 erc-mode-hook)))
163
164 (ert-info ("Connect")
165 (with-current-buffer (erc :server "127.0.0.1"
166 :port port
167 :full-name "tester"
168 :nick "tester")
169
170 (funcall expect 5 "Welcome to the foonet")
171 (funcall expect 5 "*** AWAYLEN=390")
172
173 (ert-info ("Date stamp preserves other user marker")
174 (goto-char erc-scenarios-stamp--user-marker)
175 (should-not (eq 'erc-timestamp (field-at-pos (point))))
176 (should (looking-at (rx "*** irc.foonet.org oragono")))
177 (should (eq 's004 (get-text-property (point) 'erc-msg))))
178
179 (funcall expect 5 "This server is in debug mode")))))
180
116;;; erc-scenarios-stamp.el ends here 181;;; erc-scenarios-stamp.el ends here