>From 803064a22318abcbcc3fe700884186c51b6fd039 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Wed, 6 Jul 2022 00:40:42 -0700 Subject: [PATCH 1/3] ; Demo mutating default value of `erc-server-last-peers' --- test/lisp/erc/erc-tests.el | 88 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 4971d0e194..373f5f16b0 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -893,4 +893,92 @@ erc-process-input-line (should-not calls)))))) +;; Note: if adding an erc-backend-tests.el, please relocate this there. + +(ert-deftest erc-message () + (unless (equal erc-server-last-peers '(nil . nil)) + (setq erc-server-last-peers (cons nil nil))) + (let (server-proc + calls + erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook) + (cl-letf (((symbol-function 'erc-display-message) + (lambda (_ _ _ line) (push line calls))) + ((symbol-function 'erc-server-send) + (lambda (line _) (push line calls))) + ((symbol-function 'erc-server-buffer) + (lambda () (process-buffer server-proc)))) + (with-current-buffer (get-buffer-create "ExampleNet") + (erc-mode) + (setq erc-server-current-nick "tester" + server-proc (start-process "sleep" (current-buffer) "sleep" "1") + erc-server-process server-proc + erc-server-last-peers (cons nil nil) + erc-server-users (make-hash-table :test 'equal) + erc-network 'ExampleNet) + (set-process-query-on-exit-flag erc-server-process nil)) + + (with-current-buffer (get-buffer-create "#chan") + (erc-mode) + (setq erc-server-process (buffer-local-value 'erc-server-process + (get-buffer "ExampleNet")) + erc-default-recipients '("#chan") + erc-channel-users (make-hash-table :test 'equal) + erc-network 'ExampleNet) + (erc-update-current-channel-member "alice" "alice") + (erc-update-current-channel-member "tester" "tester")) + + (with-current-buffer "ExampleNet" + (erc-server-PRIVMSG erc-server-process + (make-erc-response + :sender "alice!~u@fsf.org" + :command "PRIVMSG" + :command-args '("#chan" "hi") + :unparsed ":alice!~u@fsf.org PRIVMSG #chan :hi")) + (should (equal erc-server-last-peers '("alice"))) + (should (string-match "" (pop calls)))) + + (with-current-buffer "#chan" + (ert-info ("Shortcuts unusable in target buffers") + (should-not (local-variable-p 'erc-server-last-peers)) + (should (equal erc-server-last-peers '(nil . nil))) + (erc-message "PRIVMSG" ". hi") + (should (equal erc-server-last-peers '(nil . nil))) + (should (eq 'no-target (pop calls))) + (erc-message "PRIVMSG" ", hi") + (should (equal erc-server-last-peers '(nil . nil))) + (should (eq 'no-target (pop calls))))) + + (with-current-buffer "ExampleNet" + (ert-info ("Shortcuts local in server bufs") + (should (equal erc-server-last-peers '("alice"))) + (erc-message "PRIVMSG" ", hi") + (should (equal erc-server-last-peers '("alice" . "alice"))) + (should (string-match "PRIVMSG alice :hi" (pop calls))) + (setcdr erc-server-last-peers "bob") + (erc-message "PRIVMSG" ". hi") + (should (equal erc-server-last-peers '("alice" . "bob"))) + (should (string-match "PRIVMSG bob :hi" (pop calls))))) + + (with-current-buffer "#chan" + (ert-info ("Non-shortcuts affect global default") + (should-not (local-variable-p 'erc-server-last-peers)) + (should (equal erc-server-last-peers '(nil . nil))) + (erc-message "PRIVMSG" "#chan hola") + (should (equal erc-server-last-peers '(nil . "#chan"))) + (should (equal (default-value 'erc-server-last-peers) + '(nil . "#chan"))) + (should (string-match "hola" (pop calls)))) + + (ert-info ("Dot shortcut now usable in target buffers") + (erc-message "PRIVMSG" ". how") + (should (equal erc-server-last-peers '(nil . "#chan"))) + (should (string-match "how" (pop calls)))))) + + (should (equal (default-value 'erc-server-last-peers) '(nil . "#chan"))) + (setq erc-server-last-peers (cons nil nil)) + (should (equal erc-server-last-peers '(nil . nil))) + (should-not calls) + (kill-buffer "ExampleNet") + (kill-buffer "#chan"))) + ;;; erc-tests.el ends here -- 2.36.1