Skip to content

Commit 03d78ae

Browse files
committed
Improve test infrastructure, test font lock for operators
1 parent b04f885 commit 03d78ae

File tree

2 files changed

+106
-15
lines changed

2 files changed

+106
-15
lines changed

sysver-mode.el

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,43 @@ This is useful to let the user customize it via the customization options"
222222

223223
;; define the code-highlighting
224224
;; TODO
225-
;; (setq font-lock-defaults
226-
;; ())
225+
(setq font-lock-defaults
226+
;; keywords argument
227+
`((
228+
,(cons (regexp-opt (append
229+
sysver-keywords-design-elements
230+
sysver-keywords-struct-procedures-waits) 'symbols)
231+
font-lock-keyword-face)
232+
233+
,(cons (regexp-opt (append
234+
) 'symbols)
235+
font-lock-function-name-face)
236+
237+
,(cons (regexp-opt (append
238+
sysver-keywords-aggregate-data-types sysver-keywords-classes) 'symbols)
239+
font-lock-type-face)
240+
;; operators dedicated highlighting (user option)
241+
,(cons (concat "\\s-" (regexp-opt (append
242+
sysver-keywords-operators)) "\\s-")
243+
(if sysver-emphasize-operators
244+
font-lock-constant-face
245+
nil)) ; maintain default face
246+
;; block delimiter highlighting (user option)
247+
,(cons (regexp-opt (append
248+
sysver-keywords-block-statements) 'symbols)
249+
(if sysver-emphasize-block-statements
250+
font-lock-constant-face
251+
font-lock-type-face))
252+
253+
,(cons (regexp-opt (append
254+
)
255+
'symbols)
256+
font-lock-preprocessor-face))
257+
nil ; fontify also string and comments
258+
nil ; make the search case-sensitive
259+
))
260+
;; re-fontify current buffer as the defaults are directly changed
261+
(font-lock-refresh-defaults)
227262
)
228263

229264
(provide 'sysver-mode)

test/sysver-misc.el

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
33
(require 'ert)
44
(require 'sysver-mode)
55

6+
(defmacro sysver-utc-environment (test-string setup-to-test test-body)
7+
"Freshly reload the `sysver' major mode and setup the environment for an unit-test-case (UTC).
8+
9+
The TEST-STRING is a string to be inserted into the current buffer.
10+
The SETUP-TO-TEST should be an unquoted list of statements to setup the feature under test, while
11+
the TEST-BODY is an unquoted list of statements to verify the tested feature."
12+
13+
`(progn
14+
;; reload sysver
15+
(unload-feature 'sysver-mode t)
16+
(load-file "../sysver-mode.el")
17+
18+
;; add the setup features to be tested
19+
,@setup-to-test
20+
21+
;; enable sysver
22+
(sysver-mode)
23+
(insert test-string)
24+
(goto-char (point-min))
25+
(font-lock-fontify-buffer)
26+
27+
,@test-body))
28+
629
(ert-deftest sysver-test-underscore-part-of-word-on ()
730
"Test the behavior of the underscore based on a major-mode option.
831
@@ -17,20 +40,53 @@ the expected values."
1740
(while options
1841
(with-temp-buffer
1942

20-
;; setup
21-
(unload-feature 'sysver-mode t)
22-
(load-file "../sysver-mode.el")
23-
(setq sysver-underscore-is-word-constituent (pop options))
24-
(sysver-mode)
25-
(insert test-string)
26-
(goto-char (point-min))
43+
(sysver-utc-environment
44+
45+
test-string
46+
47+
;; feature to test
48+
((setq sysver-underscore-is-word-constituent (pop options)))
49+
50+
(;; test
51+
(forward-word)
52+
53+
;; verify
54+
(should (equal (point) (pop exp-results)))))))))
55+
56+
(ert-deftest sysver-test-emphasize-operators ()
57+
"Test that the emphasize highlighting for the operators is effective.
58+
59+
A string with the target elements to be highlighted is created and the `sysver-emphasize-operators'
60+
assigned. The result is checked by evaluating the face-property change of the target string."
61+
62+
;; all operators are tested by cycling through their list
63+
(let ((operator-list (list
64+
"=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
65+
"?" "+" "-" "!" "~" "&" "~&" "|" "~|" "^" "~^" "^~"
66+
"*" "/" "%" "==" "!=" "===" "!==" "==?" "!=?" "&&" "||" "**"
67+
"<" "<=" ">" ">=" ">>>" "<<<" "->" "<->" "##" ">>" "<<" "++" "--")))
68+
69+
(while operator-list
70+
(let* ((test-string (concat "### " (pop operator-list) " "))
71+
(options '(nil t))
72+
(exp-face '(nil font-lock-constant-face))
73+
(exp-points `(,(1+ (length test-string)) 4)))
74+
75+
(while options
76+
(with-temp-buffer
77+
78+
(sysver-utc-environment
2779

28-
;; test
29-
(forward-word)
80+
test-string
3081

31-
;; verify
32-
(should (equal (point) (pop exp-results))))))
82+
;; feature to test
83+
((setq sysver-emphasize-operators (pop options)))
3384

85+
(;; test
86+
(goto-char (next-single-property-change (point) 'face nil (point-max)))
3487

35-
;; ensure the other tests are not affected
36-
(require 'sysver-mode))
88+
;; verify
89+
(should (equal (point) (pop exp-points))) ; next reached point
90+
(should (equal
91+
(get-text-property (point) 'face)
92+
(pop exp-face)))))))))))

0 commit comments

Comments
 (0)