aboutsummaryrefslogtreecommitdiff
path: root/tests/test-modeline-config-eat-state.el
blob: 7d20c6814fd08ca8a5b095a92d05514ac4cc8104 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;;; test-modeline-config-eat-state.el --- eat input-mode/process segment -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for `cj/--modeline-eat-state', the left-side segment that shows
;; an eat terminal's input mode and process state as icons with
;; explanatory hover text (replacing eat's own [semi-char]:run
;; mode-line-process).  eat isn't installed under `make test', so the
;; tests fake an eat buffer: `major-mode' set to `eat-mode' and the
;; input-mode flags defvar'd here.  Batch has no graphic display, so the
;; glyphs exercise their letter/text fallbacks.

;;; Code:

(require 'ert)

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

(require 'modeline-config)

(defvar eat--semi-char-mode nil)
(defvar eat--char-mode nil)
(defvar eat--line-mode nil)

(defmacro test-eat-state--with-fake-eat-buffer (&rest body)
  "Run BODY in a temp buffer masquerading as an eat-mode buffer."
  `(with-temp-buffer
     (setq major-mode 'eat-mode)
     ,@body))

(ert-deftest test-modeline-eat-state-nil-outside-eat ()
  "Boundary: non-eat buffers get no segment."
  (with-temp-buffer
    (should-not (cj/--modeline-eat-state))))

(ert-deftest test-modeline-eat-state-semi-char-quiet-face ()
  "Normal: semi-char (the default mode) renders in the quiet shadow face."
  (test-eat-state--with-fake-eat-buffer
   (setq-local eat--semi-char-mode t)
   (let ((s (cj/--modeline-eat-state)))
     (should (stringp s))
     (should (text-property-any 0 (length s) 'face 'shadow s)))))

(ert-deftest test-modeline-eat-state-char-mode-warning-face ()
  "Normal: char mode (raw keys) renders in the warning face."
  (test-eat-state--with-fake-eat-buffer
   (setq-local eat--char-mode t)
   (let ((s (cj/--modeline-eat-state)))
     (should (stringp s))
     (should (text-property-any 0 (length s) 'face 'warning s)))))

(ert-deftest test-modeline-eat-state-input-mode-detection ()
  "Normal: the four input-mode flags map to the right symbols."
  (test-eat-state--with-fake-eat-buffer
   (setq-local eat--semi-char-mode t)
   (should (eq (cj/--modeline-eat-input-mode) 'semi-char)))
  (test-eat-state--with-fake-eat-buffer
   (setq-local eat--char-mode t)
   (should (eq (cj/--modeline-eat-input-mode) 'char)))
  (test-eat-state--with-fake-eat-buffer
   (setq-local eat--line-mode t)
   (should (eq (cj/--modeline-eat-input-mode) 'line)))
  (test-eat-state--with-fake-eat-buffer
   (should (eq (cj/--modeline-eat-input-mode) 'emacs))))

(ert-deftest test-modeline-eat-state-dead-process-error-face ()
  "Error: no live process renders the exited indicator in the error face."
  (test-eat-state--with-fake-eat-buffer
   (setq-local eat--semi-char-mode t)
   (let ((s (cj/--modeline-eat-state)))
     (should (text-property-any 0 (length s) 'face 'error s)))))

(ert-deftest test-modeline-eat-state-live-process-success-face ()
  "Normal: a live buffer process renders the running indicator, no error face."
  (test-eat-state--with-fake-eat-buffer
   (setq-local eat--semi-char-mode t)
   (let ((proc (start-process "test-eat-state" (current-buffer) "sleep" "10")))
     (unwind-protect
         (let ((s (cj/--modeline-eat-state)))
           (should (text-property-any 0 (length s) 'face 'success s))
           (should-not (text-property-any 0 (length s) 'face 'error s)))
       (set-process-query-on-exit-flag proc nil)
       (kill-process proc)))))

(ert-deftest test-modeline-eat-state-hover-text-explains ()
  "Normal: the input-mode glyph carries explanatory help-echo."
  (test-eat-state--with-fake-eat-buffer
   (setq-local eat--semi-char-mode t)
   (let* ((s (cj/--modeline-eat-state))
          (pos (text-property-not-all 0 (length s) 'help-echo nil s)))
     (should pos)
     (should (string-match-p "semi-char" (get-text-property pos 'help-echo s))))))

(provide 'test-modeline-config-eat-state)
;;; test-modeline-config-eat-state.el ends here