aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park2024-09-26 21:34:25 -0700
committerF. Jason Park2024-10-11 16:13:09 -0700
commit9906e34f973f15c0f96ebcfcc6ea4d1144bc6e8f (patch)
tree2795b2a25ad4fb637424e6c46ee80ed64b768371 /test
parent1de2c86317356dbbf5e7f935d3889b2698bc30f6 (diff)
downloademacs-9906e34f973f15c0f96ebcfcc6ea4d1144bc6e8f.tar.gz
emacs-9906e34f973f15c0f96ebcfcc6ea4d1144bc6e8f.zip
Crystallize erc-nicks-track-faces behavior
* etc/ERC-NEWS: Mention changes to `erc-track-faces-normal-list' and `erc-track-faces-priority-list'. Also mention new choice variant for option `erc-nicks-track-faces', although that's arguably just a bug fix because it makes good on previously unrealized behavior implied by the doc strings. * lisp/erc/erc-nicks.el (erc-nicks-skip-faces): Remove faces applied by the `match' module, namely, `erc-current-nick-face', `erc-pal-face', and `erc-fool-face'. That module runs its hooks after `button' on `erc-insert-modify-hook', and because `nicks' piggybacks on `button', it can never encounter those faces while assaying. (erc-nicks-track-faces): Update doc, and introduce new `t' value choice. (erc-nicks-mode, erc-nicks-disable): Update removals from `erc-track--alt-normals-function' to reflect recent renamings. (erc-nicks--reject-uninterned-faces): Use helper. (erc-nicks--oursp, erc-nicks--ours-p): Rename former to latter to respect project style guidelines regarding predicates. (erc-nicks-track-normal-max-rank): New variable. (erc-nicks--check-normals, erc-nicks--assess-track-faces): Rename former to latter, and change purpose to checking for "normals" membership, ranks position, and incumbent face ownership. Remove unused CONTENDERS parameter. Additionally, change behavior to consider replacing the current mode-line face when it's not `nicks' owned if it's explicitly ranked lower than `erc-default-face'. (erc-nicks--track-prioritize, erc-nicks--track-always): New complementary functions implementing the t and `prioritize' variants of `erc-nicks-track-faces'. Both make use of the factored-out `erc-nicks--check-normals' logic. (erc-nicks--setup-track-integration): Add `erc-nicks--track-always' to `erc-track--alt-normals-function' when `erc-track-normal-faces' is t. * lisp/erc/erc-track.el (erc-track--massage-nick-button-faces): Change type of symbol property `erc-track--obsolete-faces' for options `erc-track-faces-priority-list' and friends from a boolean to an alist. (erc-track-faces-priority-list): Add new face for buttonized speakers. (erc-track-faces-normal-list): Add new face for buttonized speakers. Also add `erc-notice-face'. (erc-track--priority-faces): New local variable to cache ranked faces and complement `erc-track--normal-faces'. (erc-track--setup): Initialize new `erc-track--priority-faces' variable, and refactor. (erc-track--alt-normals-function): Doc. (erc-track--select-mode-line-face): Update expected type of `ranks' parameter. (erc-track-modified-channels): Fix wrong-type bug occurring when `erc-track-ignore-normal-contenders-p' and `erc-track-priority-faces-only' are both non-nil. Also fix subtle compatibility oversight regarding an empty face list returned by `erc-track--collect-faces-in'. * test/lisp/erc/erc-nicks-tests.el: Load helpers and fixtures library. (erc-nicks-tests--track-faces): New function. (erc-nicks-track-faces/prioritize, erc-nicks-track-faces/defer) (erc-nicks-track-faces/nil, erc-nicks-track-faces/t): New tests. * test/lisp/erc/erc-track-tests.el (erc-track-tests--select-mode-line-face): Update expected type of mocked parameter. (erc-track-tests--modified-channels/baseline): New function. (erc-track-modified-channels/baseline) (erc-track-modified-channels/baseline/mention) (erc-track-modified-channels/baseline/ignore) (erc-track-modified-channels/baseline/mention/ignore) (erc-track-modified-channels/priority-only-all/baseline) (erc-track-modified-channels/priority-only-all/sans-notice): New tests. * test/lisp/erc/resources/erc-tests-common.el (erc-tests-common-track-modified-channels) (erc-tests-common-track-modified-channels-sans-setup): New functions. (Bug67767)
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-nicks-tests.el269
-rw-r--r--test/lisp/erc/erc-track-tests.el262
-rw-r--r--test/lisp/erc/resources/erc-tests-common.el43
3 files changed, 571 insertions, 3 deletions
diff --git a/test/lisp/erc/erc-nicks-tests.el b/test/lisp/erc/erc-nicks-tests.el
index 08080d249d5..c865a902a0e 100644
--- a/test/lisp/erc/erc-nicks-tests.el
+++ b/test/lisp/erc/erc-nicks-tests.el
@@ -30,8 +30,11 @@
30 30
31;;; Code: 31;;; Code:
32 32
33(require 'ert-x)
34(require 'erc-nicks) 33(require 'erc-nicks)
34(require 'ert-x)
35(eval-and-compile
36 (let ((load-path (cons (ert-resource-directory) load-path)))
37 (require 'erc-tests-common)))
35 38
36;; This function replicates the behavior of older "invert" strategy 39;; This function replicates the behavior of older "invert" strategy
37;; implementations from EmacsWiki, etc. The values for the lower and 40;; implementations from EmacsWiki, etc. The values for the lower and
@@ -568,4 +571,268 @@
568 571
569 (should (equal erc-nicks--colors-rejects '(t))))) 572 (should (equal erc-nicks--colors-rejects '(t)))))
570 573
574(declare-function erc-track-modified-channels "erc-track" ())
575
576(defun erc-nicks-tests--track-faces (test)
577 (require 'erc-track)
578 (defvar erc-modified-channels-alist)
579 (defvar erc-track--normal-faces)
580
581 (erc-tests-common-make-server-buf)
582 (erc-nicks-mode +1)
583
584 (let ((erc-modules (cons 'nicks erc-modules))
585 ;; Pretend these faces were added in response-handling during
586 ;; insertion modification by buttonizing hooks. See
587 ;; `erc-nicks--highlight-button'.
588 (add-face (lambda (face)
589 (erc-nicks--remember-face-for-track ; speaker
590 (list face 'erc-nick-default-face))
591 (erc-nicks--remember-face-for-track ; mention
592 (list face 'erc-default-face))))
593 ;;
594 bob-face alice-face assert-result)
595
596 (with-current-buffer (erc--open-target "#chan")
597 (should erc-nicks-mode)
598 (should (setq bob-face (erc-nicks--get-face "bob" "bob@foonet")))
599 (should (setq alice-face (erc-nicks--get-face "alice" "alice@foonet")))
600
601 (erc-tests-common-track-modified-channels-sans-setup
602
603 (lambda (set-faces)
604
605 (setq assert-result ; fixture binds `erc-modified-channels-alist'
606 (lambda (result)
607 (should (equal (alist-get (current-buffer)
608 erc-modified-channels-alist)
609 result))))
610
611 (funcall test set-faces assert-result add-face
612 bob-face alice-face)))))
613
614 (erc-tests-common-kill-buffers))
615
616(ert-deftest erc-nicks-track-faces/prioritize ()
617 (should (eq erc-nicks-track-faces 'prioritize))
618 (erc-nicks-tests--track-faces
619 (lambda (set-faces assert-result add-face bob-face alice-face)
620
621 (defvar erc-track--alt-normals-function)
622 (should erc-track--alt-normals-function)
623
624 (funcall add-face bob-face)
625 (funcall add-face alice-face)
626
627 ;; Simulate a JOIN.
628 (funcall set-faces '(erc-notice-face))
629 (erc-track-modified-channels)
630 (funcall assert-result '(1 . erc-notice-face))
631
632 ;; Someone speaks, and the mode-line changes to a `nicks' owned
633 ;; composite face for the speaker.
634 (funcall set-faces `(erc-timestamp-face
635 (,bob-face erc-nick-default-face)
636 erc-default-face))
637 (erc-track-modified-channels)
638 (funcall assert-result `(2 ,bob-face erc-nick-default-face))
639
640 ;; That same someone speaks, and the mode-line indicator changes to
641 ;; another "normal" face in the message body.
642 (funcall set-faces `(erc-timestamp-face
643 (,bob-face erc-nick-default-face)
644 erc-default-face))
645 (erc-track-modified-channels)
646 (funcall assert-result '(3 . erc-default-face))
647
648 ;; And yet again, which results in the indicator going back to one.
649 (funcall set-faces `(erc-timestamp-face
650 (,bob-face erc-nick-default-face)
651 erc-default-face))
652 (erc-track-modified-channels)
653 (funcall assert-result `(4 ,bob-face erc-nick-default-face))
654
655 ;; Now the same person mentions another server user, resulting in a
656 ;; change to *that* `nicks' owned face because it appears later in
657 ;; the message content (timestamp is last).
658 (funcall set-faces `(erc-timestamp-face
659 (,alice-face erc-default-face)
660 (,bob-face erc-nick-default-face)
661 erc-default-face))
662 (erc-track-modified-channels)
663 (funcall assert-result `(5 ,alice-face erc-default-face))
664
665 ;; The mentioned user replies, mentioning the mentioner. But
666 ;; instead of the normal "normals" processing preferring the ranked
667 ;; `erc-default-face', the `erc-nicks-track-faces' logic kicks in
668 ;; via `erc-track--alt-normals-function' and provides a `nicks'
669 ;; owned replacement.
670 (funcall set-faces `(erc-timestamp-face
671 (,bob-face erc-default-face)
672 (,alice-face erc-nick-default-face)
673 erc-default-face))
674 (erc-track-modified-channels)
675 (funcall assert-result `(6 ,bob-face erc-default-face))
676
677 ;; Finally, another notice arrives.
678 (funcall set-faces '(erc-notice-face))
679 (erc-track-modified-channels)
680 (funcall assert-result '(7 . erc-notice-face)))))
681
682(ert-deftest erc-nicks-track-faces/defer ()
683 (should (eq erc-nicks-track-faces 'prioritize))
684 (let ((erc-nicks-track-faces 'defer))
685 (erc-nicks-tests--track-faces
686 (lambda (set-faces assert-result add-face bob-face alice-face)
687
688 (funcall add-face bob-face)
689 (funcall add-face alice-face)
690
691 ;; Simulate a JOIN.
692 (funcall set-faces '(erc-notice-face))
693 (erc-track-modified-channels)
694 (funcall assert-result '(1 . erc-notice-face))
695
696 ;; Someone speaks, and the mode-line indicator changes to the
697 ;; highest ranked face in the message. (All `nicks' owned faces
698 ;; are unranked).
699 (funcall set-faces `(erc-timestamp-face
700 (,bob-face erc-nick-default-face)
701 erc-default-face))
702 (erc-track-modified-channels)
703 (funcall assert-result `(2 . erc-default-face))
704
705 ;; That same someone speaks, and the mode-line indicator changes
706 ;; to a `nicks' owned face. It first reaches for the highest
707 ;; ranked face in the message but then applies the "normals"
708 ;; rules, resulting in a promoted alternate.
709 (funcall set-faces `(erc-timestamp-face
710 (,bob-face erc-nick-default-face)
711 erc-default-face))
712 (erc-track-modified-channels)
713 (funcall assert-result `(3 ,bob-face erc-nick-default-face))
714
715 ;; And yet again, which results in the indicator going back to one.
716 (funcall set-faces `(erc-timestamp-face
717 (,bob-face erc-nick-default-face)
718 erc-default-face))
719 (erc-track-modified-channels)
720 (funcall assert-result '(4 . erc-default-face))
721
722 ;; The same person mentions another server user, resulting in a
723 ;; change to that `nicks' owned face because the logic from
724 ;; 3. again applies.
725 (funcall set-faces `(erc-timestamp-face
726 (,alice-face erc-default-face)
727 (,bob-face erc-nick-default-face)
728 erc-default-face))
729 (erc-track-modified-channels)
730 (funcall assert-result `(5 ,alice-face erc-default-face))
731
732 ;; The mentioned user replies, mentioning the mentioner.
733 ;; However, the `nicks' module does not intercede in the decision
734 ;; making to overrule the ranked nominee.
735 (funcall set-faces `(erc-timestamp-face
736 (,bob-face erc-default-face)
737 (,alice-face erc-nick-default-face)
738 erc-default-face))
739 (erc-track-modified-channels)
740 (funcall assert-result '(6 . erc-default-face))
741
742 ;; Finally, another notice arrives.
743 (funcall set-faces '(erc-notice-face))
744 (erc-track-modified-channels)
745 (funcall assert-result '(7 . erc-notice-face))))))
746
747(ert-deftest erc-nicks-track-faces/nil ()
748 (should (eq erc-nicks-track-faces 'prioritize))
749 (let (erc-nicks-track-faces)
750 (erc-nicks-tests--track-faces
751 (lambda (set-faces assert-result _ bob-face alice-face)
752
753 (defvar erc-track--face-reject-function)
754 (should erc-track--face-reject-function)
755
756 ;; Simulate a JOIN.
757 (funcall set-faces '(erc-notice-face))
758 (erc-track-modified-channels)
759 (funcall assert-result '(1 . erc-notice-face))
760
761 ;; Someone speaks, and the mode-line indicator changes to the
762 ;; only ranked face in the message.
763 (funcall set-faces `(erc-timestamp-face
764 (,bob-face erc-nick-default-face)
765 erc-default-face))
766 (erc-track-modified-channels)
767 (funcall assert-result `(2 . erc-default-face))
768
769 ;; That same someone speaks, and since no other "normals" exist
770 ;; in the message, the indicator is not updated.
771 (funcall set-faces `(erc-timestamp-face
772 (,bob-face erc-nick-default-face)
773 erc-default-face))
774 (erc-track-modified-channels)
775 (funcall assert-result '(3 . erc-default-face))
776
777 ;; Now the same person mentions another server user, but the same
778 ;; logic applies, and the indicator is not updated.
779 (funcall set-faces `(erc-timestamp-face
780 (,alice-face erc-default-face)
781 (,bob-face erc-nick-default-face)
782 erc-default-face))
783 (erc-track-modified-channels)
784 (funcall assert-result `(4 . erc-default-face))
785
786 ;; Finally, another notice arrives.
787 (funcall set-faces '(erc-notice-face))
788 (erc-track-modified-channels)
789 (funcall assert-result '(5 . erc-notice-face))))))
790
791(ert-deftest erc-nicks-track-faces/t ()
792 (should (eq erc-nicks-track-faces 'prioritize))
793 (let ((erc-nicks-track-faces t))
794 (erc-nicks-tests--track-faces
795 (lambda (set-faces assert-result add-face bob-face alice-face)
796
797 (defvar erc-track--alt-normals-function)
798 (should erc-track--alt-normals-function)
799
800 (funcall add-face bob-face)
801 (funcall add-face alice-face)
802
803 ;; Simulate a JOIN.
804 (funcall set-faces '(erc-notice-face))
805 (erc-track-modified-channels)
806 (funcall assert-result '(1 . erc-notice-face))
807
808 ;; Someone speaks, and the mode-line indicator changes to that
809 ;; someone's `nicks'-owned face.
810 (funcall set-faces `(erc-timestamp-face
811 (,bob-face erc-nick-default-face)
812 erc-default-face))
813 (erc-track-modified-channels)
814 (funcall assert-result `(2 ,bob-face erc-nick-default-face))
815
816 ;; That same someone speaks, and though one other "normal" exists
817 ;; in the message, `erc-default-face', no update occurs.
818 (funcall set-faces `(erc-timestamp-face
819 (,bob-face erc-nick-default-face)
820 erc-default-face))
821 (erc-track-modified-channels)
822 (funcall assert-result `(3 ,bob-face erc-nick-default-face))
823
824 ;; Another server user speaks, mentioning the previous speaker,
825 ;; and the indicator is updated to reflect the new speaker.
826 (funcall set-faces `(erc-timestamp-face
827 (,bob-face erc-default-face) ; bob:
828 (,alice-face erc-nick-default-face) ; <alice>
829 erc-default-face))
830 (erc-track-modified-channels)
831 (funcall assert-result `(4 ,alice-face erc-nick-default-face))
832
833 ;; Finally, another notice arrives.
834 (funcall set-faces '(erc-notice-face))
835 (erc-track-modified-channels)
836 (funcall assert-result '(5 . erc-notice-face))))))
837
571;;; erc-nicks-tests.el ends here 838;;; erc-nicks-tests.el ends here
diff --git a/test/lisp/erc/erc-track-tests.el b/test/lisp/erc/erc-track-tests.el
index 8149138a971..c830c8b2016 100644
--- a/test/lisp/erc/erc-track-tests.el
+++ b/test/lisp/erc/erc-track-tests.el
@@ -227,6 +227,13 @@
227(defun erc-track-tests--select-mode-line-face (ranked normals cases) 227(defun erc-track-tests--select-mode-line-face (ranked normals cases)
228 (setq normals (map-into (mapcar (lambda (f) (cons f t)) normals) 228 (setq normals (map-into (mapcar (lambda (f) (cons f t)) normals)
229 '(hash-table :test equal))) 229 '(hash-table :test equal)))
230
231 (setq ranked (cons (map-into (mapcar (let ((i 0))
232 (lambda (f) (cons f (cl-incf i))))
233 ranked)
234 '(hash-table :test equal))
235 ranked))
236
230 (pcase-dolist (`(,want ,cur-face ,new-faces) cases) 237 (pcase-dolist (`(,want ,cur-face ,new-faces) cases)
231 238
232 (ert-info ((format "Observed: {cur: %S, new: %S, want: %S}" 239 (ert-info ((format "Observed: {cur: %S, new: %S, want: %S}"
@@ -235,8 +242,8 @@
235 (mapcar (lambda (f) (cons f t)) new-faces) 242 (mapcar (lambda (f) (cons f t)) new-faces)
236 '(hash-table :test equal)) 243 '(hash-table :test equal))
237 (reverse new-faces))) 244 (reverse new-faces)))
238 (should (equal want (funcall #'erc-track--select-mode-line-face 245 (should (equal want (erc-track--select-mode-line-face
239 cur-face new-faces ranked normals)))))) 246 cur-face new-faces ranked normals))))))
240 247
241;; The main difference between these variants is that with the above, 248;; The main difference between these variants is that with the above,
242;; when given alternating lines like 249;; when given alternating lines like
@@ -410,4 +417,255 @@
410 (when noninteractive 417 (when noninteractive
411 (kill-buffer)))) 418 (kill-buffer))))
412 419
420(defun erc-track-tests--modified-channels/baseline (set-faces)
421 ;; Simulate a JOIN, PART, etc. that's displayed in `erc-notice-face'.
422 (funcall set-faces '(erc-notice-face))
423 (erc-track-modified-channels)
424 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
425 '(1 . erc-notice-face)))
426
427 ;; Someone speaks, and the mode-line face goes from ERC's generic
428 ;; "notice" face, `erc-notice-face', to the first face in the
429 ;; inserted message that outranks it, which happens to be the
430 ;; `button' module's composite face for buttonized speakers:
431 ;; (erc-button-nick-default-face erc-nick-default-face). It
432 ;; outranks both the previous occupant, `erc-notice-face', and its
433 ;; one cohabitant in the message text, `erc-default-face', in
434 ;; `erc-track-faces-priority-list'. Note that in the following
435 ;; list, `erc-default-face' appears first because it's used for the
436 ;; opening speaker bracket "<". The timestamp appears last because
437 ;; it's a right-sided stamp appended to the message body.
438 (funcall set-faces '(erc-timestamp-face
439 (erc-button-nick-default-face erc-nick-default-face)
440 erc-default-face))
441 (erc-track-modified-channels)
442 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
443 '(2 erc-button-nick-default-face erc-nick-default-face)))
444
445 ;; The speaker speaks again immediately, and the segment changes to
446 ;; `erc-default-face', which appears later in the message, as
447 ;; normal body text. This happens because both `erc-default-face'
448 ;; and (erc-button-nick-default-face erc-nick-default-face) appear
449 ;; in `erc-track-faces-normal-list', meaning the lower-ranked
450 ;; former can replace the higher-ranked latter in the mode-line for
451 ;; the purpose of indicating channel activity.
452 (funcall set-faces '(erc-timestamp-face
453 (erc-button-nick-default-face erc-nick-default-face)
454 erc-default-face))
455 (erc-track-modified-channels)
456 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
457 '(3 . erc-default-face)))
458
459 ;; Note: if (erc-button-nick-default-face erc-nick-default-face)
460 ;; were removed from `erc-track-faces-priority-list' but kept in
461 ;; `erc-track-faces-normal-list', then replaying the sequence would
462 ;; result in the previous two results being switched:
463 ;; `erc-default-face' would replace `erc-notice-face' before being
464 ;; replaced by the buttonized composite.
465
466 ;; The speaker speaks yet again, and the segment goes back to the
467 ;; higher ranking face.
468 (funcall set-faces '(erc-timestamp-face
469 (erc-button-nick-default-face erc-nick-default-face)
470 erc-default-face))
471 (erc-track-modified-channels)
472 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
473 '(4 erc-button-nick-default-face erc-nick-default-face)))
474
475 ;; Finally, another notice arrives. Although lower ranked, it also
476 ;; appears in `erc-track-faces-normal-list' and so is eligible to
477 ;; replace the incumbent.
478 (funcall set-faces '(erc-notice-face))
479 (erc-track-modified-channels)
480 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
481 '(5 . erc-notice-face))))
482
483(ert-deftest erc-track-modified-channels/baseline ()
484 (erc-tests-common-track-modified-channels
485 #'erc-track-tests--modified-channels/baseline))
486
487(ert-deftest erc-track-modified-channels/baseline/mention ()
488 (erc-tests-common-track-modified-channels
489 (lambda (set-faces)
490 ;; Note: these messages don't have timestamps.
491
492 ;; Simulate a JOIN, PART, etc. that's displayed in `erc-notice-face'.
493 (funcall set-faces '(erc-notice-face))
494 (erc-track-modified-channels)
495 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
496 '(1 . erc-notice-face)))
497
498 ;; Someone speaks, mentioning someone else, and the mode-line
499 ;; changes to (erc-button-nick-default-face erc-nick-default-face)
500 ;; rather than (erc-button-nick-default-face erc-default-face)
501 ;; based on their rankings in `erc-track-faces-priority-list'.
502 (funcall set-faces '((erc-button-nick-default-face erc-default-face)
503 (erc-button-nick-default-face erc-nick-default-face)
504 erc-default-face))
505 (erc-track-modified-channels)
506 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
507 '(2 erc-button-nick-default-face erc-nick-default-face)))
508
509 ;; Someone else speaks, again with a mention and additional body text.
510 (funcall set-faces '((erc-button-nick-default-face erc-default-face)
511 (erc-button-nick-default-face erc-nick-default-face)
512 erc-default-face))
513 (erc-track-modified-channels)
514 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
515 '(3 erc-button-nick-default-face erc-default-face)))
516
517 ;; And yet again, which results in the indicator going back to one.
518 (funcall set-faces '((erc-button-nick-default-face erc-default-face)
519 (erc-button-nick-default-face erc-nick-default-face)
520 erc-default-face))
521 (erc-track-modified-channels)
522 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
523 '(4 erc-button-nick-default-face erc-nick-default-face)))
524
525 ;; Finally, another notice arrives.
526 (funcall set-faces '(erc-notice-face))
527 (erc-track-modified-channels)
528 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
529 '(5 . erc-notice-face))))))
530
531;; The compat-oriented option `erc-track-ignore-normal-contenders-p'
532;; blinds track to `erc-track-faces-normal-list' for certain consecutive
533;; messages with an identical face makeup.
534(ert-deftest erc-track-modified-channels/baseline/ignore ()
535 (let ((erc-track-ignore-normal-contenders-p t))
536 (erc-tests-common-track-modified-channels
537 (lambda (set-faces)
538 ;; Simulate a JOIN, PART, etc. that's displayed in `erc-notice-face'.
539 (funcall set-faces '(erc-notice-face))
540 (erc-track-modified-channels)
541 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
542 '(1 . erc-notice-face)))
543
544 ;; Someone speaks, and the mode-line indicator's face changes to
545 ;; that of a buttonized speaker.
546 (funcall set-faces
547 '(erc-timestamp-face
548 (erc-button-nick-default-face erc-nick-default-face)
549 erc-default-face))
550 (erc-track-modified-channels)
551 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
552 '(2 erc-button-nick-default-face erc-nick-default-face)))
553
554 ;; The speaker speaks again immediately, and the segment doesn't
555 ;; change.
556 (funcall set-faces
557 '(erc-timestamp-face
558 (erc-button-nick-default-face erc-nick-default-face)
559 erc-default-face))
560 (erc-track-modified-channels)
561 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
562 '(3 erc-button-nick-default-face erc-nick-default-face)))
563
564 ;; Finally, another notice arrives.
565 (funcall set-faces '(erc-notice-face))
566 (erc-track-modified-channels)
567 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
568 '(4 . erc-notice-face)))))))
569
570;; Compat-oriented option `erc-track-ignore-normal-contenders-p'.
571(ert-deftest erc-track-modified-channels/baseline/mention/ignore ()
572 (let ((erc-track-ignore-normal-contenders-p t))
573 (erc-tests-common-track-modified-channels
574 (lambda (set-faces)
575
576 ;; Simulate a JOIN, PART, etc. that's displayed in `erc-notice-face'.
577 (funcall set-faces '(erc-notice-face))
578 (erc-track-modified-channels)
579 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
580 '(1 . erc-notice-face)))
581
582 ;; Someone speaks, and the mode-line indicator's face changes to
583 ;; that of a buttonized speaker.
584 (funcall set-faces
585 '((erc-button-nick-default-face erc-default-face)
586 (erc-button-nick-default-face erc-nick-default-face)
587 erc-default-face))
588 (erc-track-modified-channels)
589 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
590 '(2 erc-button-nick-default-face erc-nick-default-face)))
591
592 ;; Someone else speaks, again with a mention and additional body
593 ;; text, but the indicator stays the same.
594 (funcall set-faces
595 '((erc-button-nick-default-face erc-default-face)
596 (erc-button-nick-default-face erc-nick-default-face)
597 erc-default-face))
598 (erc-track-modified-channels)
599 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
600 '(3 erc-button-nick-default-face erc-nick-default-face)))
601
602 ;; Finally, another notice arrives.
603 (funcall set-faces '(erc-notice-face))
604 (erc-track-modified-channels)
605 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
606 '(4 . erc-notice-face)))))))
607
608;; Option `erc-track-priority-faces-only' does not affect the behavior
609;; of the baseline "normals" scenario because all faces appear in
610;; `erc-track-faces-priority-list'.
611(ert-deftest erc-track-modified-channels/priority-only-all/baseline ()
612 (let ((erc-track-priority-faces-only 'all))
613 (erc-tests-common-track-modified-channels
614 #'erc-track-tests--modified-channels/baseline)))
615
616;; This test simulates a common configuration that combines an
617;; `erc-track-faces-priority-list' removed of `erc-notice-face' with
618;; `erc-track-priority-faces-only' being `all'. It also features in the
619;; sample configuration in ERC's manual.
620(ert-deftest erc-track-modified-channels/priority-only-all/sans-notice ()
621 (let ((erc-track-priority-faces-only 'all)
622 (erc-track-faces-priority-list
623 (remq 'erc-notice-face erc-track-faces-priority-list)))
624
625 (erc-tests-common-track-modified-channels
626 (lambda (set-faces)
627 ;; Note: these messages don't have timestamps.
628
629 ;; Simulate a message normally displayed in `erc-notice-face',
630 ;; which has been removed from `erc-track-faces-priority-list'.
631 (funcall set-faces '(erc-notice-face))
632 (erc-track-modified-channels)
633 (should-not (alist-get (current-buffer) erc-modified-channels-alist))
634
635 ;; Someone speaks, mentioning someone else, and the mode-line
636 ;; changes to the buttonized speaker face rather than the
637 ;; buttonized mention face, due to their respective ranks.
638 (funcall set-faces
639 '((erc-button-nick-default-face erc-default-face)
640 (erc-button-nick-default-face erc-nick-default-face)
641 erc-default-face))
642 (erc-track-modified-channels)
643 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
644 '(1 erc-button-nick-default-face erc-nick-default-face)))
645
646 ;; Someone else speaks, again with a mention and additional body text.
647 (funcall set-faces
648 '((erc-button-nick-default-face erc-default-face)
649 (erc-button-nick-default-face erc-nick-default-face)
650 erc-default-face))
651 (erc-track-modified-channels)
652 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
653 '(2 erc-button-nick-default-face erc-default-face)))
654
655 ;; And yet again, which results in the indicator going back to one.
656 (funcall set-faces
657 '((erc-button-nick-default-face erc-default-face)
658 (erc-button-nick-default-face erc-nick-default-face)
659 erc-default-face))
660 (erc-track-modified-channels)
661 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
662 '(3 erc-button-nick-default-face erc-nick-default-face)))
663
664 ;; Finally, another notice arrives, which is ignored.
665 (funcall set-faces '(erc-notice-face))
666 (erc-track-modified-channels)
667 (should (equal (alist-get (current-buffer) erc-modified-channels-alist)
668 '(3 erc-button-nick-default-face
669 erc-nick-default-face)))))))
670
413;;; erc-track-tests.el ends here 671;;; erc-track-tests.el ends here
diff --git a/test/lisp/erc/resources/erc-tests-common.el b/test/lisp/erc/resources/erc-tests-common.el
index 1cd54a1f715..91654467dae 100644
--- a/test/lisp/erc/resources/erc-tests-common.el
+++ b/test/lisp/erc/resources/erc-tests-common.el
@@ -330,4 +330,47 @@ interspersing \"-l\" between members."
330 (set-process-query-on-exit-flag proc t) 330 (set-process-query-on-exit-flag proc t)
331 proc)) 331 proc))
332 332
333(declare-function erc-track--setup "erc-track" ())
334
335(defun erc-tests-common-track-modified-channels (test)
336 (erc-tests-common-prep-for-insertion)
337 (setq erc--target (erc--target-from-string "#chan"))
338 (erc-tests-common-track-modified-channels-sans-setup test))
339
340(defun erc-tests-common-track-modified-channels-sans-setup (test)
341 "Provide a fixture for testing `erc-track-modified-channels'.
342Call function TEST with another function that sets the mocked return
343value of `erc-track--collect-faces-in' to the given argument, a list of
344faces in the reverse order they appear in an inserted message."
345 (defvar erc-modified-channels-alist)
346 (defvar erc-modified-channels-object)
347 (defvar erc-track--attn-faces)
348 (defvar erc-track--normal-faces)
349 (defvar erc-track--priority-faces)
350 (defvar erc-track-faces-normal-list)
351 (defvar erc-track-faces-priority-list)
352 (defvar erc-track-mode)
353
354 (cl-letf* ((erc-track-mode t)
355 (erc-modified-channels-alist nil)
356 (erc-modified-channels-object erc-modified-channels-object)
357 (faces ())
358 ((symbol-function 'force-mode-line-update) #'ignore)
359 ((symbol-function 'erc-faces-in) (lambda (_) faces))
360 ((symbol-function 'erc-track--collect-faces-in)
361 (lambda ()
362 (cons (map-into (mapcar (lambda (f) (cons f t)) faces)
363 '(hash-table :test equal))
364 faces))))
365 (erc-track--setup)
366
367 ;; Faces from `erc-track--attn-faces' prepended.
368 (should (= (+ (length erc-track--attn-faces)
369 (length erc-track-faces-priority-list))
370 (hash-table-count erc-track--priority-faces)))
371 (should (= (length erc-track-faces-normal-list)
372 (hash-table-count erc-track--normal-faces)))
373
374 (funcall test (lambda (arg) (setq faces arg)))))
375
333(provide 'erc-tests-common) 376(provide 'erc-tests-common)