summaryrefslogtreecommitdiff
path: root/tests/test-nerd-icons-config--apply-tint.el
blob: ef723352c5bdb146d2ac4bbda91e5685a8807feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;;; test-nerd-icons-config--apply-tint.el --- Tests for cj/nerd-icons-apply-tint -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for the bulk-tint helper. Mocks `set-face-foreground' and `facep'
;; at the framework boundary so the tests don't depend on nerd-icons being
;; loaded — only on the symbol list and the dispatch logic.

;;; Code:

(require 'ert)
(require 'cl-lib)

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'nerd-icons-config)

(defmacro test-nerd-icons-config--capture-set-face-foreground (calls-var &rest body)
  "Run BODY with `set-face-foreground' and `facep' stubbed.
Each (face color) pair gets pushed onto CALLS-VAR. `facep' returns t
for every symbol so all faces in the list count as defined."
  (declare (indent 1) (debug t))
  `(cl-letf (((symbol-function 'set-face-foreground)
              (lambda (face color &rest _) (push (cons face color) ,calls-var)))
             ((symbol-function 'facep)
              (lambda (_) t)))
     ,@body))

(ert-deftest test-nerd-icons-config--apply-tint-covers-every-face ()
  "Normal: apply-tint calls set-face-foreground once per face in the list."
  (let ((calls nil))
    (test-nerd-icons-config--capture-set-face-foreground calls
      (cj/nerd-icons-apply-tint "test-color"))
    (should (= (length calls) (length cj/--nerd-icons-color-faces)))
    (dolist (face cj/--nerd-icons-color-faces)
      (should (assq face calls)))))

(ert-deftest test-nerd-icons-config--apply-tint-passes-color-arg ()
  "Normal: apply-tint forwards COLOR to every set-face-foreground call."
  (let ((calls nil))
    (test-nerd-icons-config--capture-set-face-foreground calls
      (cj/nerd-icons-apply-tint "rebeccapurple"))
    (dolist (call calls)
      (should (equal (cdr call) "rebeccapurple")))))

(ert-deftest test-nerd-icons-config--apply-tint-defaults-to-customvar ()
  "Normal: with no COLOR arg, uses `cj/nerd-icons-tint-color'."
  (let ((calls nil))
    (test-nerd-icons-config--capture-set-face-foreground calls
      (let ((cj/nerd-icons-tint-color "default-test-color"))
        (cj/nerd-icons-apply-tint)))
    (should (cl-every (lambda (call) (equal (cdr call) "default-test-color")) calls))))

(ert-deftest test-nerd-icons-config--apply-tint-skips-undefined-faces ()
  "Boundary: faces that fail `facep' are silently skipped, not errored."
  (let ((calls nil))
    (cl-letf (((symbol-function 'set-face-foreground)
               (lambda (face color &rest _) (push (cons face color) calls)))
              ((symbol-function 'facep)
               (lambda (_) nil)))
      (cj/nerd-icons-apply-tint "any"))
    (should (null calls))))

(provide 'test-nerd-icons-config--apply-tint)
;;; test-nerd-icons-config--apply-tint.el ends here