blob: bb905ad4d4f8ec38d1122555eff70623d990bc1b (
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
;;; test-ui-buffer-status-colors.el --- Tests for buffer status colors -*- lexical-binding: t; -*-
;;; Commentary:
;; Unit tests for buffer status color system.
;; Tests the state detection logic used by both cursor color and modeline.
;;; Code:
(require 'ert)
(require 'user-constants)
(require 'ui-config)
(require 'modeline-config)
;;; Color Constant Tests
(ert-deftest test-buffer-status-colors-has-all-states ()
"Test that all required states are defined in color alist."
(should (alist-get 'read-only cj/buffer-status-colors))
(should (alist-get 'overwrite cj/buffer-status-colors))
(should (alist-get 'modified cj/buffer-status-colors))
(should (alist-get 'unmodified cj/buffer-status-colors)))
(ert-deftest test-buffer-status-colors-values-are-strings ()
"Test that all color values are strings (hex colors)."
(dolist (entry cj/buffer-status-colors)
(should (stringp (cdr entry)))
;; Check if it looks like a hex color
(should (string-match-p "^#[0-9a-fA-F]\\{6\\}$" (cdr entry)))))
;;; Cursor Color State Detection Tests
(ert-deftest test-cursor-color-state-read-only-buffer ()
"Test state detection for read-only buffer."
(with-temp-buffer
(setq buffer-read-only t)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state 'read-only)))))
(ert-deftest test-cursor-color-state-overwrite-mode ()
"Test state detection for overwrite mode."
(with-temp-buffer
(setq buffer-read-only nil)
(overwrite-mode 1)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state 'overwrite)))))
(ert-deftest test-cursor-color-state-modified-buffer ()
"Test state detection for modified buffer."
(with-temp-buffer
(setq buffer-read-only nil)
(insert "test")
(set-buffer-modified-p t)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state 'modified)))))
(ert-deftest test-cursor-color-state-unmodified-buffer ()
"Test state detection for unmodified buffer."
(with-temp-buffer
(setq buffer-read-only nil)
(set-buffer-modified-p nil)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state 'unmodified)))))
(ert-deftest test-cursor-color-state-priority-read-only-over-modified ()
"Test that read-only state takes priority over modified state."
(with-temp-buffer
(insert "test")
(set-buffer-modified-p t)
(setq buffer-read-only t)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state 'read-only)))))
(ert-deftest test-cursor-color-state-priority-overwrite-over-modified ()
"Test that overwrite mode takes priority over modified state."
(with-temp-buffer
(insert "test")
(set-buffer-modified-p t)
(overwrite-mode 1)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state 'overwrite)))))
;;; Integration Tests - Cursor Color Function
(ert-deftest test-cursor-color-function-exists ()
"Test that cursor color function is defined."
(should (fboundp 'cj/set-cursor-color-according-to-mode)))
(ert-deftest test-cursor-color-returns-correct-color-for-read-only ()
"Test cursor color function returns red for read-only buffer."
(with-temp-buffer
(setq buffer-read-only t)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified)))
(color (alist-get state cj/buffer-status-colors)))
(should (equal color "#f06a3f")))))
(ert-deftest test-cursor-color-returns-correct-color-for-overwrite ()
"Test cursor color function returns gold for overwrite mode."
(with-temp-buffer
(overwrite-mode 1)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified)))
(color (alist-get state cj/buffer-status-colors)))
(should (equal color "#c48702")))))
(ert-deftest test-cursor-color-returns-correct-color-for-modified ()
"Test cursor color function returns green for modified buffer."
(with-temp-buffer
(insert "test")
(set-buffer-modified-p t)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified)))
(color (alist-get state cj/buffer-status-colors)))
(should (equal color "#64aa0f")))))
(ert-deftest test-cursor-color-returns-correct-color-for-unmodified ()
"Test cursor color function returns white for unmodified buffer."
(with-temp-buffer
(set-buffer-modified-p nil)
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified)))
(color (alist-get state cj/buffer-status-colors)))
(should (equal color "#ffffff")))))
;;; Modeline Integration Tests
(ert-deftest test-modeline-buffer-name-variable-exists ()
"Test that modeline buffer name variable is defined."
(should (boundp 'cj/modeline-buffer-name)))
(ert-deftest test-modeline-buffer-name-is-mode-line-construct ()
"Test that modeline buffer name is a valid mode-line construct."
(should (listp cj/modeline-buffer-name))
(should (eq (car cj/modeline-buffer-name) :eval)))
;;; Edge Cases
(ert-deftest test-buffer-status-new-buffer-starts-unmodified ()
"Test that new buffer starts in unmodified state."
(with-temp-buffer
(let* ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state 'unmodified)))))
(ert-deftest test-buffer-status-insert-makes-modified ()
"Test that inserting text changes state to modified."
(with-temp-buffer
;; Initially unmodified
(set-buffer-modified-p nil)
(let ((state1 (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state1 'unmodified)))
;; Insert text
(insert "test")
(let ((state2 (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state2 'modified)))))
(ert-deftest test-buffer-status-explicit-unmodify ()
"Test that explicitly setting unmodified works."
(with-temp-buffer
(insert "test")
(should (buffer-modified-p))
;; Explicitly set unmodified
(set-buffer-modified-p nil)
(let ((state (cond
(buffer-read-only 'read-only)
(overwrite-mode 'overwrite)
((buffer-modified-p) 'modified)
(t 'unmodified))))
(should (eq state 'unmodified)))))
(provide 'test-ui-buffer-status-colors)
;;; test-ui-buffer-status-colors.el ends here
|