aboutsummaryrefslogtreecommitdiff
path: root/tests/test-keyboard-compat--icon-blank-in-terminal.el
blob: db2bb6b7571bd9e8b4d735efacee7c0cbc79ad7c (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
;;; test-keyboard-compat--icon-blank-in-terminal.el --- Tests for cj/--icon-blank-in-terminal -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for the per-call icon-rendering gate that replaced the load-time
;; defun-redefinition. The helper must dispatch on the current frame's
;; `display-graphic-p' so the same daemon can serve real icons to GUI frames
;; and blanks to terminal frames.

;;; Code:

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

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'keyboard-compat)

(defmacro test-keyboard-compat--with-graphic-p (graphic-p &rest body)
  "Run BODY with `display-graphic-p' stubbed to GRAPHIC-P."
  (declare (indent 1) (debug t))
  `(cl-letf (((symbol-function 'display-graphic-p)
              (lambda (&optional _) ,graphic-p)))
     ,@body))

(ert-deftest test-keyboard-compat--icon-blank-in-terminal-passes-through-on-gui ()
  "Normal: returns ORIG's value when display-graphic-p is non-nil."
  (test-keyboard-compat--with-graphic-p t
    (let ((orig (lambda (&rest _) "ICON")))
      (should (equal (cj/--icon-blank-in-terminal orig "foo.txt") "ICON")))))

(ert-deftest test-keyboard-compat--icon-blank-in-terminal-blank-on-terminal ()
  "Boundary: returns empty string when display-graphic-p is nil."
  (test-keyboard-compat--with-graphic-p nil
    (let ((orig (lambda (&rest _) "ICON")))
      (should (equal (cj/--icon-blank-in-terminal orig "foo.txt") "")))))

(ert-deftest test-keyboard-compat--icon-blank-in-terminal-forwards-args ()
  "Normal: forwards all ARGS to ORIG when graphical."
  (test-keyboard-compat--with-graphic-p t
    (let ((received nil))
      (cj/--icon-blank-in-terminal
       (lambda (&rest args) (setq received args) "ok")
       'a 'b 'c)
      (should (equal received '(a b c))))))

(ert-deftest test-keyboard-compat--icon-blank-in-terminal-does-not-call-orig-on-terminal ()
  "Error: ORIG must not be invoked when display-graphic-p is nil."
  (test-keyboard-compat--with-graphic-p nil
    (let ((called nil))
      (cj/--icon-blank-in-terminal
       (lambda (&rest _) (setq called t) "ICON"))
      (should-not called))))

(provide 'test-keyboard-compat--icon-blank-in-terminal)
;;; test-keyboard-compat--icon-blank-in-terminal.el ends here