]> git.eshelyaron.com Git - emacs.git/commitdiff
; Fix erc--channel-modes test on graphical displays
authorF. Jason Park <jp@neverwas.me>
Sun, 26 Nov 2023 03:23:55 +0000 (19:23 -0800)
committerF. Jason Park <jp@neverwas.me>
Sun, 26 Nov 2023 22:25:27 +0000 (14:25 -0800)
* lisp/erc/erc-fill.el (erc-fill--wrap-insert-merged-post): Use
correct variable.
* test/lisp/erc/erc-scenarios-display-message.el: Mute unrelated noisy
test.
* test/lisp/erc/erc-tests.el (erc--channel-modes): Bail out following
first group of assertions when running on a graphical display.
(erc--channel-modes/graphic-p): New test asserting different values
for graphical terminals.  Note that this too is tagged as :unstable.
See also: d2ce30afdd2 "; Mark test for erc--update-channel-modes as
:unstable".

lisp/erc/erc-fill.el
test/lisp/erc/erc-scenarios-display-message.el
test/lisp/erc/erc-tests.el

index fc572666461adde022e8e9b55b8764a581cc5182..82e881cb71ce85990f40a11a37d32e1aaa3ed1dc 100644 (file)
@@ -642,7 +642,7 @@ to be disabled."
 
 (defun erc-fill--wrap-insert-merged-pre ()
   "Add `display' property in lieu of speaker."
-  (if erc-fill--wrap-merge-indicator-post
+  (if erc-fill--wrap-merge-indicator-pre
       (progn
         (put-text-property (point-min) (point) 'display
                            (car erc-fill--wrap-merge-indicator-pre))
index 5751a32212d6211499907075e969614803a04698..c7e0c2fc17a63b18d19c9b3e5e9e1e30a573ea15 100644 (file)
@@ -57,6 +57,7 @@
         (funcall expect 10 "*** dummy (~u@rdjcgiwfuwqmc.irc) has quit")
         (should (eq 'QUIT (get-text-property (match-beginning 0) 'erc-msg)))))
 
-    (erc-cmd-QUIT "")))
+    (with-current-buffer "foonet"
+      (erc-cmd-QUIT ""))))
 
 ;;; erc-scenarios-display-message.el ends here
index 1d0eb70578a2de9092a270dd3108b520499378d7..0d6ddf12380d659bb388e44aeae181324ed96ab2 100644 (file)
   (should (equal (erc--channel-modes) '((?k . "h2") (?l . "3") (?t))))
   (should (equal (erc--channel-modes 3 ",") "klt h2,3"))
 
+  ;; The function this tests behaves differently in different
+  ;; environments.  For example, on one GNU Linux system, it returns
+  ;; truncation ellipsis when run interactively.  Rather than have
+  ;; hard-to-read "nondeterministic" comparisons against sets of
+  ;; acceptable values, we use separate tests.
+  (when (display-graphic-p) (ert-pass))
+
   ;; Truncation cache populated and used.
   (let ((cache (erc--channel-mode-types-shortargs erc--channel-mode-types))
         first-run)
     (should (zerop (hash-table-count cache)))
     (should (equal (erc--channel-modes 1 ",") "klt h,3"))
     (should (equal (setq first-run (map-pairs cache)) '(((1 ?k "h2") . "h"))))
+
+    ;; Second call uses cache.
     (cl-letf (((symbol-function 'truncate-string-to-width)
                (lambda (&rest _) (ert-fail "Shouldn't run"))))
       (should (equal (erc--channel-modes 1 ",") "klt h,3")))
+
     ;; Same key for only entry matches that of first result.
     (should (pcase (map-pairs cache)
               ((and '(((1 ?k "h2") . "h")) second-run)
   (should (equal (erc--channel-modes 1) "klt h 3"))
   (should (equal (erc--channel-modes 0) "klt  "))) ; 2 spaces
 
+(ert-deftest erc--channel-modes/graphic-p ()
+  :tags '(:unstable)
+  (unless (display-graphic-p) (ert-skip "See non-/graphic-p variant"))
+
+  (erc-tests--set-fake-server-process "sleep" "1")
+  (setq erc--isupport-params (make-hash-table)
+        erc--target (erc--target-from-string "#test")
+        erc-server-parameters
+        '(("CHANMODES" . "eIbq,k,flj,CFLMPQRSTcgimnprstuz")))
+
+  (cl-letf (((symbol-function 'erc-update-mode-line) #'ignore))
+    (erc--update-channel-modes "+bltk" "fool!*@*" "3" "hun2"))
+
+  ;; Truncation cache populated and used.
+  (let ((cache (erc--channel-mode-types-shortargs erc--channel-mode-types))
+        first-run)
+    (should (zerop (hash-table-count cache)))
+    (should (equal (erc--channel-modes 2 ",") "klt h…,3" ))
+    (should (equal (setq first-run (map-pairs cache))
+                   '(((2 ?k "hun2") . "h…"))))
+
+    ;; Second call uses cache.
+    (cl-letf (((symbol-function 'truncate-string-to-width)
+               (lambda (&rest _) (ert-fail "Shouldn't run"))))
+      (should (equal (erc--channel-modes 2 ",") "klt h…,3" )))
+
+    ;; Same key for only entry matches that of first result.
+    (should (pcase (map-pairs cache)
+              ((and `(((2 ?k "hun2") . "h…")) second-run)
+               (eq (pcase first-run (`((,k . ,_)) k))
+                   (pcase second-run (`((,k . ,_)) k)))))))
+
+  ;; A max length of 0 is nonsensical anyway, so skip those.
+  (should (equal (erc--channel-modes 3) "klt hu… 3"))
+  (should (equal (erc--channel-modes 2) "klt h… 3"))
+  (should (equal (erc--channel-modes 1) "klt … 3")))
+
 (ert-deftest erc--update-user-modes ()
   (let ((erc--user-modes (list ?a)))
     (should (equal (erc--update-user-modes "+a") '(?a)))