summaryrefslogtreecommitdiff
path: root/test/lisp/erc/resources/erc-tests-common.el
diff options
context:
space:
mode:
authorF. Jason Park <jp@neverwas.me>2024-09-26 21:34:25 -0700
committerF. Jason Park <jp@neverwas.me>2024-10-11 16:13:09 -0700
commit9906e34f973f15c0f96ebcfcc6ea4d1144bc6e8f (patch)
tree2795b2a25ad4fb637424e6c46ee80ed64b768371 /test/lisp/erc/resources/erc-tests-common.el
parent1de2c86317356dbbf5e7f935d3889b2698bc30f6 (diff)
downloademacs-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/resources/erc-tests-common.el')
-rw-r--r--test/lisp/erc/resources/erc-tests-common.el43
1 files changed, 43 insertions, 0 deletions
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."
(set-process-query-on-exit-flag proc t)
proc))
+(declare-function erc-track--setup "erc-track" ())
+
+(defun erc-tests-common-track-modified-channels (test)
+ (erc-tests-common-prep-for-insertion)
+ (setq erc--target (erc--target-from-string "#chan"))
+ (erc-tests-common-track-modified-channels-sans-setup test))
+
+(defun erc-tests-common-track-modified-channels-sans-setup (test)
+ "Provide a fixture for testing `erc-track-modified-channels'.
+Call function TEST with another function that sets the mocked return
+value of `erc-track--collect-faces-in' to the given argument, a list of
+faces in the reverse order they appear in an inserted message."
+ (defvar erc-modified-channels-alist)
+ (defvar erc-modified-channels-object)
+ (defvar erc-track--attn-faces)
+ (defvar erc-track--normal-faces)
+ (defvar erc-track--priority-faces)
+ (defvar erc-track-faces-normal-list)
+ (defvar erc-track-faces-priority-list)
+ (defvar erc-track-mode)
+
+ (cl-letf* ((erc-track-mode t)
+ (erc-modified-channels-alist nil)
+ (erc-modified-channels-object erc-modified-channels-object)
+ (faces ())
+ ((symbol-function 'force-mode-line-update) #'ignore)
+ ((symbol-function 'erc-faces-in) (lambda (_) faces))
+ ((symbol-function 'erc-track--collect-faces-in)
+ (lambda ()
+ (cons (map-into (mapcar (lambda (f) (cons f t)) faces)
+ '(hash-table :test equal))
+ faces))))
+ (erc-track--setup)
+
+ ;; Faces from `erc-track--attn-faces' prepended.
+ (should (= (+ (length erc-track--attn-faces)
+ (length erc-track-faces-priority-list))
+ (hash-table-count erc-track--priority-faces)))
+ (should (= (length erc-track-faces-normal-list)
+ (hash-table-count erc-track--normal-faces)))
+
+ (funcall test (lambda (arg) (setq faces arg)))))
+
(provide 'erc-tests-common)