-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsvg-mode-line-themes-tests.el
187 lines (173 loc) · 5.91 KB
/
svg-mode-line-themes-tests.el
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
(require 'svg-mode-line-themes)
(require 'ert)
(smt/defwidget test-center-label
:text "center")
(smt/defrow center-test
:align "center"
:widgets '(test-center-label)
:always-visible t)
(smt/deftheme test
:prototype 'diesel
:rows (list 'default-left
'center-test
(smt/make-row
:prototype 'center-test
:baseline
(lambda (row)
(+ (smt/r-baseline
(smt/r-prototype row))
(frame-char-height))))
'default-right)
:pixel-height (* 2 (frame-char-height)))
(ert-deftest smt/combine-styles ()
(should (null (smt/combine-styles)))
(should (null (smt/combine-styles '(:a 45) '(:a nil))))
(should (equal (smt/combine-styles '(:a 45) nil)
'(:a 45)))
(should (equal '(:a 45)
(smt/combine-styles '(:a 45))))
(let (( result (smt/combine-styles '(:a 1) '(:b 2))))
(should (= 1 (getf result :a)))
(should (= 2 (getf result :b)))
(should (= 4 (length result))))
(let (( result (smt/combine-styles '(:a 1) '(:a 2))))
(should (= 2 (getf result :a)))
(should (= 2 (length result))))
(let (( result (smt/combine-styles '(:a 1) '(:b 2) '(:c 3))))
(should (= 1 (getf result :a)))
(should (= 2 (getf result :b)))
(should (= 3 (getf result :c)))
(should (= 6 (length result)))))
(ert-deftest smt/ranges-overlapping-p ()
(should (smt/ranges-overlapping-p '(0 . 10) '(5 . 6)))
(should (smt/ranges-overlapping-p '(0 . 10) '(9 . 20)))
(should (smt/ranges-overlapping-p '(3 . 10) '(3 . 5)))
(should (smt/ranges-overlapping-p '(3 . 5) '(3 . 10)))
(should-not (smt/ranges-overlapping-p '(0 . 0) '(0 . 0)))
(should-not (smt/ranges-overlapping-p '(0 . 10) '(10 . 10)))
(should-not (smt/ranges-overlapping-p '(0 . 0) '(0 . 10)))
(should-not (smt/ranges-overlapping-p '(0 . 10) '(0 . 0)))
)
(ert-deftest smt/row ()
(let (( row (smt/make-row
:margin 2
:widgets (list
(smt/make-widget
:text "123")
(smt/make-widget
:text "456")))))
(should (= (smt/r-width row) 6))
(should (equal (smt/r-align row) "left"))
(should (= (smt/maybe-funcall (smt/r-margin row)) 2))
(should (= (smt/r-left row) 2))
(should (equal (smt/r-range row) '(2 . 8)))))
(ert-deftest smt/theme-overlapping ()
(let (( theme
(smt/make-theme
:rows
(list (smt/make-row
:margin 2
:widgets
(list
(smt/make-widget
:text "123346")))
(smt/make-row
:margin 8
:widgets
(list
(smt/make-widget
:text "123346")))))))
(should (= 2 (length (smt/t-visible-rows theme)))))
(let (( theme
(smt/make-theme
:rows
(list (smt/make-row
:margin 2
:widgets
(list
(smt/make-widget
:text "123346")))
(smt/make-row
:margin 7
:widgets
(list
(smt/make-widget
:text "123346")))))))
(should (= 1 (length (smt/t-visible-rows theme)))))
(let (( theme
(smt/make-theme
:rows
(list (smt/make-row
:widgets
(list
(smt/make-widget
:text "first")))
(smt/make-row
:align "right"
:widgets
(list
(smt/make-widget
:text "123456")))
(smt/make-row
:align "right"
:widgets
(list
(smt/make-widget
:text "1234567")))))))
(flet (( smt/window-width () 10))
(should (= 4 (smt/r-left (second (smt/t-rows theme)))))
(should (= 1 (length (smt/t-visible-rows theme))))
(should (equal (smt/w-text
(car (smt/r-widgets
(car (smt/t-visible-rows theme)))))
"first"))
))
(let (( theme
(smt/make-theme
:rows
(list (smt/make-row
:widgets
(list
(smt/make-widget
:text "12345")))
(smt/make-row
:align "right"
:widgets
(list
(smt/make-widget
:text "12345")))))))
(flet (( smt/window-width () 10))
(should (= 2 (length (smt/t-visible-rows theme)))))))
(ert-deftest smt/objects ()
(let (( namespace
(list (cons 'archetype
(list :type 'type1
:shadow1 'shadow
:shadow2 'light))))
( obj1
(list :prototype 'archetype
:prop1 1
:prop2 2
:prop3 3
:shadow1 nil
:shadow2 'shadow)))
(should (eq 'type1 (smt/get obj1 :type namespace)))
(should (null (smt/get obj1 :shadow1 namespace)))
(should (eq 'shadow (smt/get obj1 :shadow2 namespace)))
))
(smt/deftype atest
:some-prop 34)
(smt/defatest self-reference
:prototype 'self-reference)
(smt/defatest mutual-reference1
:prototype 'mutual-reference2)
(smt/defatest mutual-reference2
:prototype 'mutual-reference1)
(ert-deftest smt/cyclical-references ()
(let (( anonymous (smt/make-atest)))
(setf (getf anonymous :prototype) anonymous)
(should-error (smt/a-some-prop anonymous))
(should-error (smt/a-some-prop 'mutual-reference1))
(should-error (smt/a-some-prop 'self-reference))))
(provide 'svg-mode-line-themes-tests)
;;; svg-mode-line-themes-tests.el ends here