summaryrefslogtreecommitdiff
path: root/test/lisp/erc/erc-tests.el
diff options
context:
space:
mode:
authorF. Jason Park <jp@neverwas.me>2021-11-06 03:09:43 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-11-06 03:09:43 +0100
commit4d656ea5ff7ba79315af42e159254867bfd157ad (patch)
tree03965e6c5cd08400222cbadbbe6741459d9514df /test/lisp/erc/erc-tests.el
parent82d0550648969ce10303b67b7a8da51c4e855501 (diff)
downloademacs-4d656ea5ff7ba79315af42e159254867bfd157ad.tar.gz
emacs-4d656ea5ff7ba79315af42e159254867bfd157ad.tar.bz2
emacs-4d656ea5ff7ba79315af42e159254867bfd157ad.zip
Don't send empty lines for implicit targets in ERC
* erc.el (erc-send-input-line): Previously, any line typed into a query or channel buffer without an explicit user-command handler (meaning most lines), would be sent twice because a trailing newline (linefeed) would be appended. This has been verified by checking IRCd server logs. IRCds won't return an error upon receiving an empty message, but they also won't forward them to channel subscribers and DM pals. * erc-tests.el: Add test for erc-process-input-line, which also indirectly tests erc-send-input-line. It also tests the command lookup and dispatch facility (bug#50008).
Diffstat (limited to 'test/lisp/erc/erc-tests.el')
-rw-r--r--test/lisp/erc/erc-tests.el62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 6ed26f68289..685f4e2bea2 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -228,4 +228,66 @@
(kill-buffer "*erc-protocol*")
(should-not erc-debug-irc-protocol)))
+
+;; The point of this test is to ensure output is handled identically
+;; regardless of whether a command handler is summoned.
+
+(ert-deftest erc-process-input-line ()
+ (let (erc-server-last-sent-time
+ erc-server-flood-queue
+ (orig-erc-cmd-MSG (symbol-function 'erc-cmd-MSG))
+ calls)
+ (with-temp-buffer
+ (cl-letf (((symbol-function 'erc-cmd-MSG)
+ (lambda (line)
+ (push line calls)
+ (funcall orig-erc-cmd-MSG line)))
+ ((symbol-function 'erc-server-buffer)
+ (lambda () (current-buffer)))
+ ((symbol-function 'erc-server-process-alive)
+ (lambda () t))
+ ((symbol-function 'erc-server-send-queue)
+ #'ignore)
+ ((symbol-function 'erc-default-target)
+ (lambda () "" "#chan")))
+
+ (ert-info ("Dispatch to user command handler")
+
+ (ert-info ("Baseline")
+ (erc-process-input-line "/msg #chan hi\n")
+ (should (equal (pop calls) " #chan hi"))
+ (should (equal (pop erc-server-flood-queue)
+ '("PRIVMSG #chan :hi\r\n" . utf-8))))
+
+ (ert-info ("Spaces preserved")
+ (erc-process-input-line "/msg #chan hi you\n")
+ (should (equal (pop calls) " #chan hi you"))
+ (should (equal (pop erc-server-flood-queue)
+ '("PRIVMSG #chan :hi you\r\n" . utf-8))))
+
+ (ert-info ("Empty line honored")
+ (erc-process-input-line "/msg #chan\n")
+ (should (equal (pop calls) " #chan"))
+ (should (equal (pop erc-server-flood-queue)
+ '("PRIVMSG #chan :\r\n" . utf-8)))))
+
+ (ert-info ("Implicit cmd via `erc-send-input-line-function'")
+
+ (ert-info ("Baseline")
+ (erc-process-input-line "hi")
+ (should (equal (pop erc-server-flood-queue)
+ '("PRIVMSG #chan :hi\r\n" . utf-8))))
+
+ (ert-info ("Spaces preserved")
+ (erc-process-input-line "hi you")
+ (should (equal (pop erc-server-flood-queue)
+ '("PRIVMSG #chan :hi you\r\n" . utf-8))))
+
+ (ert-info ("Empty line transmitted without injected-space kludge")
+ (erc-process-input-line "")
+ (should (equal (pop erc-server-flood-queue)
+ '("PRIVMSG #chan :\r\n" . utf-8))))
+
+ (should-not calls))))))
+
;;; erc-tests.el ends here