aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp
diff options
context:
space:
mode:
authorF. Jason Park2023-11-13 18:24:59 -0800
committerF. Jason Park2023-11-18 12:34:56 -0800
commite7fa460e1da3847456f03b9f508c6f6e5c09e450 (patch)
treebabdd61caf088c6e6226c7079c266fdd430e060e /test/lisp
parentb088222ec9f0cff720ca366bdef448d392731f94 (diff)
downloademacs-e7fa460e1da3847456f03b9f508c6f6e5c09e450.tar.gz
emacs-e7fa460e1da3847456f03b9f508c6f6e5c09e450.zip
Use caching variant of erc-parse-prefix internally
* lisp/erc/erc-common.el (erc--parsed-prefix): New struct to help with tasks that depends on the advertised "PREFIX" parameter. * lisp/erc/erc.el (erc-parse-prefix): Rework slightly for readability. (erc--parsed-prefix): New variable and function of the same name for caching the reversed result of `erc-parse-prefix' locally per server. (erc-channel-receive-names): Use value stored in `erc--parsed-prefix'. * test/lisp/erc/erc-tests.el (erc-with-server-buffer): Only activate spy around actual test case forms. (erc--parse-prefix): New test. (Bug#67220)
Diffstat (limited to 'test/lisp')
-rw-r--r--test/lisp/erc/erc-tests.el66
1 files changed, 62 insertions, 4 deletions
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index e7422d330c0..b4a3c89b27c 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -115,14 +115,20 @@
115 (setq erc-away 1) 115 (setq erc-away 1)
116 (erc-tests--set-fake-server-process "sleep" "1") 116 (erc-tests--set-fake-server-process "sleep" "1")
117 117
118 (let (calls) 118 (let (mockingp calls)
119 (advice-add 'buffer-local-value :after (lambda (&rest r) (push r calls)) 119 (advice-add 'buffer-local-value :after
120 (lambda (&rest r) (when mockingp (push r calls)))
120 '((name . erc-with-server-buffer))) 121 '((name . erc-with-server-buffer)))
121 122
122 (should (= 1 (erc-with-server-buffer erc-away))) 123 (should (= 1 (prog2 (setq mockingp t)
124 (erc-with-server-buffer erc-away)
125 (setq mockingp nil))))
126
123 (should (equal (pop calls) (list 'erc-away (current-buffer)))) 127 (should (equal (pop calls) (list 'erc-away (current-buffer))))
124 128
125 (should (= 1 (erc-with-server-buffer (ignore 'me) erc-away))) 129 (should (= 1 (prog2 (setq mockingp t)
130 (erc-with-server-buffer (ignore 'me) erc-away)
131 (setq mockingp nil))))
126 (should-not calls) 132 (should-not calls)
127 133
128 (advice-remove 'buffer-local-value 'erc-with-server-buffer))) 134 (advice-remove 'buffer-local-value 'erc-with-server-buffer)))
@@ -643,6 +649,58 @@
643 649
644 (should (equal '("de" "" "fg@xy") (erc-parse-user "abc\nde!fg@xy")))))) 650 (should (equal '("de" "" "fg@xy") (erc-parse-user "abc\nde!fg@xy"))))))
645 651
652(ert-deftest erc--parsed-prefix ()
653 (erc-mode)
654 (erc-tests--set-fake-server-process "sleep" "1")
655 (setq erc--isupport-params (make-hash-table))
656
657 ;; Uses fallback values when no PREFIX parameter yet received, thus
658 ;; ensuring caller can use slot accessors immediately intead of
659 ;; checking if null beforehand.
660 (should-not erc--parsed-prefix)
661 (should (equal (erc--parsed-prefix)
662 #s(erc--parsed-prefix nil "qaohv" "~&@%+"
663 ((?q . ?~) (?a . ?&)
664 (?o . ?@) (?h . ?%) (?v . ?+)))))
665 (let ((cached (should erc--parsed-prefix)))
666 (should (eq (erc--parsed-prefix) cached)))
667
668 ;; Cache broken. (Notice not setting `erc--parsed-prefix' to nil).
669 (setq erc-server-parameters '(("PREFIX" . "(Yqaohv)!~&@%+")))
670
671 (let ((proc erc-server-process)
672 (expected '((?Y . ?!) (?q . ?~) (?a . ?&)
673 (?o . ?@) (?h . ?%) (?v . ?+)))
674 cached)
675
676 (with-temp-buffer
677 (erc-mode)
678 (setq erc-server-process proc)
679 (should (equal expected
680 (erc--parsed-prefix-alist (erc--parsed-prefix)))))
681
682 (should (equal expected (erc--parsed-prefix-alist erc--parsed-prefix)))
683 (setq cached erc--parsed-prefix)
684 (should (equal cached
685 #s(erc--parsed-prefix ("(Yqaohv)!~&@%+") "Yqaohv" "!~&@%+"
686 ((?Y . ?!) (?q . ?~) (?a . ?&)
687 (?o . ?@) (?h . ?%) (?v . ?+)))))
688 ;; Second target buffer reuses cached value.
689 (with-temp-buffer
690 (erc-mode)
691 (setq erc-server-process proc)
692 (should (eq cached (erc--parsed-prefix))))
693
694 ;; New value computed when cache broken.
695 (puthash 'PREFIX (list "(Yqaohv)!~&@%+") erc--isupport-params)
696 (with-temp-buffer
697 (erc-mode)
698 (setq erc-server-process proc)
699 (should-not (eq cached (erc--parsed-prefix)))
700 (should (equal (erc--parsed-prefix-alist
701 (erc-with-server-buffer erc--parsed-prefix))
702 expected)))))
703
646(ert-deftest erc--parse-isupport-value () 704(ert-deftest erc--parse-isupport-value ()
647 (should (equal (erc--parse-isupport-value "a,b") '("a" "b"))) 705 (should (equal (erc--parse-isupport-value "a,b") '("a" "b")))
648 (should (equal (erc--parse-isupport-value "a,b,c") '("a" "b" "c"))) 706 (should (equal (erc--parse-isupport-value "a,b,c") '("a" "b" "c")))