3
3
(require 'ert )
4
4
(require 'sysver-mode )
5
5
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
+
6
29
(ert-deftest sysver-test-underscore-part-of-word-on ()
7
30
" Test the behavior of the underscore based on a major-mode option.
8
31
@@ -17,20 +40,53 @@ the expected values."
17
40
(while options
18
41
(with-temp-buffer
19
42
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
27
79
28
- ; ; test
29
- (forward-word )
80
+ test-string
30
81
31
- ; ; verify
32
- ( should ( equal ( point ) (pop exp-results))) )))
82
+ ; ; feature to test
83
+ (( setq sysver-emphasize-operators (pop options )))
33
84
85
+ (; ; test
86
+ (goto-char (next-single-property-change (point ) 'face nil (point-max )))
34
87
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