diff options
author | F. Jason Park <jp@neverwas.me> | 2024-09-26 21:34:25 -0700 |
---|---|---|
committer | F. Jason Park <jp@neverwas.me> | 2024-10-11 16:13:09 -0700 |
commit | 9906e34f973f15c0f96ebcfcc6ea4d1144bc6e8f (patch) | |
tree | 2795b2a25ad4fb637424e6c46ee80ed64b768371 /test/lisp/erc/erc-nicks-tests.el | |
parent | 1de2c86317356dbbf5e7f935d3889b2698bc30f6 (diff) | |
download | emacs-9906e34f973f15c0f96ebcfcc6ea4d1144bc6e8f.tar.gz emacs-9906e34f973f15c0f96ebcfcc6ea4d1144bc6e8f.tar.bz2 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/lisp/erc/erc-nicks-tests.el')
-rw-r--r-- | test/lisp/erc/erc-nicks-tests.el | 269 |
1 files changed, 268 insertions, 1 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 @@ ;;; Code: -(require 'ert-x) (require 'erc-nicks) +(require 'ert-x) +(eval-and-compile + (let ((load-path (cons (ert-resource-directory) load-path))) + (require 'erc-tests-common))) ;; This function replicates the behavior of older "invert" strategy ;; implementations from EmacsWiki, etc. The values for the lower and @@ -568,4 +571,268 @@ (should (equal erc-nicks--colors-rejects '(t))))) +(declare-function erc-track-modified-channels "erc-track" ()) + +(defun erc-nicks-tests--track-faces (test) + (require 'erc-track) + (defvar erc-modified-channels-alist) + (defvar erc-track--normal-faces) + + (erc-tests-common-make-server-buf) + (erc-nicks-mode +1) + + (let ((erc-modules (cons 'nicks erc-modules)) + ;; Pretend these faces were added in response-handling during + ;; insertion modification by buttonizing hooks. See + ;; `erc-nicks--highlight-button'. + (add-face (lambda (face) + (erc-nicks--remember-face-for-track ; speaker + (list face 'erc-nick-default-face)) + (erc-nicks--remember-face-for-track ; mention + (list face 'erc-default-face)))) + ;; + bob-face alice-face assert-result) + + (with-current-buffer (erc--open-target "#chan") + (should erc-nicks-mode) + (should (setq bob-face (erc-nicks--get-face "bob" "bob@foonet"))) + (should (setq alice-face (erc-nicks--get-face "alice" "alice@foonet"))) + + (erc-tests-common-track-modified-channels-sans-setup + + (lambda (set-faces) + + (setq assert-result ; fixture binds `erc-modified-channels-alist' + (lambda (result) + (should (equal (alist-get (current-buffer) + erc-modified-channels-alist) + result)))) + + (funcall test set-faces assert-result add-face + bob-face alice-face))))) + + (erc-tests-common-kill-buffers)) + +(ert-deftest erc-nicks-track-faces/prioritize () + (should (eq erc-nicks-track-faces 'prioritize)) + (erc-nicks-tests--track-faces + (lambda (set-faces assert-result add-face bob-face alice-face) + + (defvar erc-track--alt-normals-function) + (should erc-track--alt-normals-function) + + (funcall add-face bob-face) + (funcall add-face alice-face) + + ;; Simulate a JOIN. + (funcall set-faces '(erc-notice-face)) + (erc-track-modified-channels) + (funcall assert-result '(1 . erc-notice-face)) + + ;; Someone speaks, and the mode-line changes to a `nicks' owned + ;; composite face for the speaker. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(2 ,bob-face erc-nick-default-face)) + + ;; That same someone speaks, and the mode-line indicator changes to + ;; another "normal" face in the message body. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result '(3 . erc-default-face)) + + ;; And yet again, which results in the indicator going back to one. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(4 ,bob-face erc-nick-default-face)) + + ;; Now the same person mentions another server user, resulting in a + ;; change to *that* `nicks' owned face because it appears later in + ;; the message content (timestamp is last). + (funcall set-faces `(erc-timestamp-face + (,alice-face erc-default-face) + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(5 ,alice-face erc-default-face)) + + ;; The mentioned user replies, mentioning the mentioner. But + ;; instead of the normal "normals" processing preferring the ranked + ;; `erc-default-face', the `erc-nicks-track-faces' logic kicks in + ;; via `erc-track--alt-normals-function' and provides a `nicks' + ;; owned replacement. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-default-face) + (,alice-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(6 ,bob-face erc-default-face)) + + ;; Finally, another notice arrives. + (funcall set-faces '(erc-notice-face)) + (erc-track-modified-channels) + (funcall assert-result '(7 . erc-notice-face))))) + +(ert-deftest erc-nicks-track-faces/defer () + (should (eq erc-nicks-track-faces 'prioritize)) + (let ((erc-nicks-track-faces 'defer)) + (erc-nicks-tests--track-faces + (lambda (set-faces assert-result add-face bob-face alice-face) + + (funcall add-face bob-face) + (funcall add-face alice-face) + + ;; Simulate a JOIN. + (funcall set-faces '(erc-notice-face)) + (erc-track-modified-channels) + (funcall assert-result '(1 . erc-notice-face)) + + ;; Someone speaks, and the mode-line indicator changes to the + ;; highest ranked face in the message. (All `nicks' owned faces + ;; are unranked). + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(2 . erc-default-face)) + + ;; That same someone speaks, and the mode-line indicator changes + ;; to a `nicks' owned face. It first reaches for the highest + ;; ranked face in the message but then applies the "normals" + ;; rules, resulting in a promoted alternate. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(3 ,bob-face erc-nick-default-face)) + + ;; And yet again, which results in the indicator going back to one. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result '(4 . erc-default-face)) + + ;; The same person mentions another server user, resulting in a + ;; change to that `nicks' owned face because the logic from + ;; 3. again applies. + (funcall set-faces `(erc-timestamp-face + (,alice-face erc-default-face) + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(5 ,alice-face erc-default-face)) + + ;; The mentioned user replies, mentioning the mentioner. + ;; However, the `nicks' module does not intercede in the decision + ;; making to overrule the ranked nominee. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-default-face) + (,alice-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result '(6 . erc-default-face)) + + ;; Finally, another notice arrives. + (funcall set-faces '(erc-notice-face)) + (erc-track-modified-channels) + (funcall assert-result '(7 . erc-notice-face)))))) + +(ert-deftest erc-nicks-track-faces/nil () + (should (eq erc-nicks-track-faces 'prioritize)) + (let (erc-nicks-track-faces) + (erc-nicks-tests--track-faces + (lambda (set-faces assert-result _ bob-face alice-face) + + (defvar erc-track--face-reject-function) + (should erc-track--face-reject-function) + + ;; Simulate a JOIN. + (funcall set-faces '(erc-notice-face)) + (erc-track-modified-channels) + (funcall assert-result '(1 . erc-notice-face)) + + ;; Someone speaks, and the mode-line indicator changes to the + ;; only ranked face in the message. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(2 . erc-default-face)) + + ;; That same someone speaks, and since no other "normals" exist + ;; in the message, the indicator is not updated. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result '(3 . erc-default-face)) + + ;; Now the same person mentions another server user, but the same + ;; logic applies, and the indicator is not updated. + (funcall set-faces `(erc-timestamp-face + (,alice-face erc-default-face) + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(4 . erc-default-face)) + + ;; Finally, another notice arrives. + (funcall set-faces '(erc-notice-face)) + (erc-track-modified-channels) + (funcall assert-result '(5 . erc-notice-face)))))) + +(ert-deftest erc-nicks-track-faces/t () + (should (eq erc-nicks-track-faces 'prioritize)) + (let ((erc-nicks-track-faces t)) + (erc-nicks-tests--track-faces + (lambda (set-faces assert-result add-face bob-face alice-face) + + (defvar erc-track--alt-normals-function) + (should erc-track--alt-normals-function) + + (funcall add-face bob-face) + (funcall add-face alice-face) + + ;; Simulate a JOIN. + (funcall set-faces '(erc-notice-face)) + (erc-track-modified-channels) + (funcall assert-result '(1 . erc-notice-face)) + + ;; Someone speaks, and the mode-line indicator changes to that + ;; someone's `nicks'-owned face. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(2 ,bob-face erc-nick-default-face)) + + ;; That same someone speaks, and though one other "normal" exists + ;; in the message, `erc-default-face', no update occurs. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-nick-default-face) + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(3 ,bob-face erc-nick-default-face)) + + ;; Another server user speaks, mentioning the previous speaker, + ;; and the indicator is updated to reflect the new speaker. + (funcall set-faces `(erc-timestamp-face + (,bob-face erc-default-face) ; bob: + (,alice-face erc-nick-default-face) ; <alice> + erc-default-face)) + (erc-track-modified-channels) + (funcall assert-result `(4 ,alice-face erc-nick-default-face)) + + ;; Finally, another notice arrives. + (funcall set-faces '(erc-notice-face)) + (erc-track-modified-channels) + (funcall assert-result '(5 . erc-notice-face)))))) + ;;; erc-nicks-tests.el ends here |