aboutsummaryrefslogtreecommitdiff
path: root/tests/test-modeline-config-segments.el
blob: 0245749ddf40600b60582f01acb021ed3dec034c (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
;;; test-modeline-config-segments.el --- small modeline segments -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for the small pure segment helpers added in the 2026-07-01
;; modeline overhaul: macro indicator, remote-host tag, narrowing
;; indicator, position/region info, and the padding space.

;;; Code:

(require 'ert)

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

(require 'modeline-config)

;; ---------------------------- Macro Indicator --------------------------------

(ert-deftest test-modeline-config-macro-indicator-shows-when-defining ()
  "Normal: MACRO text with the error face while a macro is recording."
  (let ((defining-kbd-macro t))
    (let ((s (cj/--modeline-macro-indicator)))
      (should (stringp s))
      (should (string-match-p "MACRO" s))
      (should (eq (get-text-property (string-match "MACRO" s) 'face s)
                  'error)))))

(ert-deftest test-modeline-config-macro-indicator-nil-when-idle ()
  "Boundary: nil when no macro is being defined."
  (let ((defining-kbd-macro nil))
    (should-not (cj/--modeline-macro-indicator))))

;; ---------------------------- Remote Host Tag --------------------------------

(ert-deftest test-modeline-config-remote-host-shows-host ()
  "Normal: remote default-directory yields an @host tag."
  (with-temp-buffer
    (setq default-directory "/ssh:velox:/home/cjennings/")
    (let ((s (cj/--modeline-remote-host)))
      (should (stringp s))
      (should (string-match-p "@velox" s)))))

(ert-deftest test-modeline-config-remote-host-nil-when-local ()
  "Boundary: nil for a local directory."
  (with-temp-buffer
    (setq default-directory "/tmp/")
    (should-not (cj/--modeline-remote-host))))

;; --------------------------- Narrowing Indicator -----------------------------

(ert-deftest test-modeline-config-narrow-indicator-shows-when-narrowed ()
  "Normal: narrowed buffer yields the Narrow tag."
  (with-temp-buffer
    (insert "line one\nline two\nline three\n")
    (narrow-to-region 1 9)
    (let ((s (cj/--modeline-narrow-indicator)))
      (should (stringp s))
      (should (string-match-p "Narrow" s)))))

(ert-deftest test-modeline-config-narrow-indicator-nil-when-widened ()
  "Boundary: nil when the buffer is not narrowed."
  (with-temp-buffer
    (insert "text")
    (should-not (cj/--modeline-narrow-indicator))))

;; --------------------------- Position / Region Info ---------------------------

(ert-deftest test-modeline-config-position-info-line-column-percent ()
  "Normal: no region yields L: C: plus a percentage-through-buffer."
  (with-temp-buffer
    (insert (make-string 200 ?x))
    (goto-char (point-min))
    (deactivate-mark)
    (let ((s (cj/--modeline-position-info)))
      (should (stringp s))
      (should (string-match-p "L:" s))
      (should (string-match-p "C:" s))
      ;; point-based percent, %%-escaped for the mode-line construct pass
      (should (string-match-p "%" s)))))

(ert-deftest test-modeline-config-position-info-region-lines-chars ()
  "Normal: an active region yields selection info instead of position."
  (with-temp-buffer
    (insert "one\ntwo\nthree\n")
    (goto-char (point-min))
    (push-mark (point) t t)
    (goto-char 9)                       ; through "one\ntwo\n"
    (let ((transient-mark-mode t))
      (let ((s (cj/--modeline-position-info)))
        (should (stringp s))
        (should (string-match-p "2 lines" s))
        (should (string-match-p "8 chars" s))))))

(ert-deftest test-modeline-config-position-info-single-char-region ()
  "Boundary: a one-char region reports 1 line, 1 char."
  (with-temp-buffer
    (insert "abc")
    (goto-char 1)
    (push-mark (point) t t)
    (goto-char 2)
    (let ((transient-mark-mode t))
      (let ((s (cj/--modeline-position-info)))
        (should (string-match-p "1 line" s))
        (should (string-match-p "1 char" s))))))

;; ------------------------------- Padding --------------------------------------

(ert-deftest test-modeline-config-padding-absolute-height-face ()
  "Normal: padding space carries a face with an absolute integer :height.
The height is anchored to the frame default (not the current buffer's
`default'), so a buffer that remaps `default' larger — nov's reading view,
`text-scale-mode' — no longer inflates the modeline."
  (let ((cj/modeline-height-factor 1.2))
    (let* ((s (cj/--modeline-padding))
           (face (get-text-property 0 'face s))
           (h (plist-get face :height)))
      (should (stringp s))
      (should (integerp h))
      (should (= h (round (* 1.2 (face-attribute 'default :height nil t))))))))

(ert-deftest test-modeline-config-padding-plain-at-factor-one ()
  "Boundary: factor 1.0 (or nil) yields a plain space, no height styling."
  (dolist (factor (list 1.0 nil))
    (let ((cj/modeline-height-factor factor))
      (let ((s (cj/--modeline-padding)))
        (should (stringp s))
        (should-not (get-text-property 0 'display s))
        (should-not (get-text-property 0 'face s))))))

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