aboutsummaryrefslogtreecommitdiff
path: root/tests/test-keyboard-compat--icon-blank-in-terminal.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-keyboard-compat--icon-blank-in-terminal.el')
-rw-r--r--tests/test-keyboard-compat--icon-blank-in-terminal.el54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test-keyboard-compat--icon-blank-in-terminal.el b/tests/test-keyboard-compat--icon-blank-in-terminal.el
new file mode 100644
index 00000000..db2bb6b7
--- /dev/null
+++ b/tests/test-keyboard-compat--icon-blank-in-terminal.el
@@ -0,0 +1,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