Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 358 lines (297 sloc) 12.871 kb
1d47367 @jscheid Add license
authored
1 ;;; kite-color-tests.el --- Kite test suite for color helpers
2
3 ;; Copyright (C) 2012 Julian Scheid
4
5eebac9 @jscheid Add email address to author name
authored
5 ;; Author: Julian Scheid <julians37@gmail.com>
afe1642 @jscheid Remove 'WWW' keyword
authored
6 ;; Keywords: tools
3deba10 @jscheid Improve package meta-data
authored
7 ;; Package: kite
8 ;; Compatibility: GNU Emacs 24
9
dc768cf @jscheid Add note that kite is not part of Emacs
authored
10 ;; This file is not part of GNU Emacs.
1d47367 @jscheid Add license
authored
11
12 ;; Kite is free software: you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; Kite is distributed in the hope that it will be useful, but WITHOUT
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 ;; License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with Kite. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26
27 ;; Kite test suite for color helpers.
28 ;;
29 ;; It is part of Kite, a WebKit inspector front-end.
30
31
32 ;;; Code:
33
10a8b68 @jscheid Add module kite-color
authored
34 (ert-deftest kite-test-color-regex ()
35 (dolist (color-spec
36 '(;; 4.1. Example I
37 "black"
38 "white"
39 "maroon"
40 "olive"
41
42 ;; 4.2.1 Example I
43 "#f00"
44 "#ff0000"
45 "rgb(255,0,0)"
46 "rgb(100%, 0%, 0%)"
47
48 ;; 4.2.1 Example I (sic)
49 "rgb(255,0,0)"
50 "rgb(300,0,0)"
51 "rgb(255,-10,0)"
52 "rgb(110%, 0%, 0%)"
53
54 ;; 4.2.2 Example I
55 "rgb(255,0,0)"
56 "rgba(255,0,0,1)"
57 "rgb(100%,0%,0%)"
58 "rgba(100%,0%,0%,1)"
59
60 ;; 4.2.2 Example I (sic)
61 "rgba(0,0,255,0.5)"
62 "rgba(100%, 50%, 0%, 0.1)"
63
64 ;; 4.2.4 Example I
65 "hsl(0, 100%, 50%)"
66 "hsl(120, 100%, 50%)"
67 "hsl(120, 100%, 25%)"
68 "hsl(120, 100%, 75%)"
69 "hsl(120, 50%, 50%)"
70
71 ;; 4.2.5 Example I
72 "hsl(120, 100%, 50%)"
73 "hsla(120, 100%, 50%, 1)"
74
75 ;; 4.2.5 Example I (sic)
76 "hsla(240, 100%, 50%, 0.5)"
77 "hsla(30, 100%, 50%, 0.1)"
78 ))
79 (should (eq 0 (string-match
80 kite-color-regexp
81 color-spec)))))
82
83 (ert-deftest kite-test-color-keywords ()
84 (should (equal '(0.0 0.0 0.0)
85 (kite-parse-color "black"))))
86
87 (ert-deftest kite-test-hex3 ()
88 (should (equal '(0.0 0.0 0.0)
89 (kite-parse-color "#000")))
90 (should (equal '(1.0 0.0 0.0)
91 (kite-parse-color "#f00")))
92 (should (equal '(0.0 1.0 0.0)
93 (kite-parse-color "#0f0")))
94 (should (equal '(0.0 0.0 1.0)
95 (kite-parse-color "#00f")))
96 (should (equal '(1.0 1.0 1.0)
97 (kite-parse-color "#fff")))
98 (should (equal '(1.0 1.0 1.0)
99 (kite-parse-color "#FFF")))
100 (should (equal `(0.0 0.0 ,(/ 1.0 15.0))
101 (kite-parse-color "#001"))))
102
103 (ert-deftest kite-test-hex6 ()
104 (should (equal '(0.0 0.0 0.0)
105 (kite-parse-color "#000000")))
106 (should (equal '(1.0 0.0 0.0)
107 (kite-parse-color "#ff0000")))
108 (should (equal '(0.0 1.0 0.0)
109 (kite-parse-color "#00ff00")))
110 (should (equal '(0.0 0.0 1.0)
111 (kite-parse-color "#0000ff")))
112 (should (equal '(1.0 1.0 1.0)
113 (kite-parse-color "#ffffff")))
114 (should (equal '(1.0 1.0 1.0)
115 (kite-parse-color "#FfFfFf"))))
116
117 (ert-deftest kite-test-rgb-integer ()
118 ;; basic tests
119 (should (equal '(0.0 0.0 0.0)
120 (kite-parse-color "rgb(0,0,0)")))
121 (should (equal '(1.0 0.0 0.0)
122 (kite-parse-color "rgb(255,0,0)")))
123 (should (equal '(0.0 1.0 0.0)
124 (kite-parse-color "rgb(0,255,0)")))
125 (should (equal '(0.0 0.0 1.0)
126 (kite-parse-color "rgb(0,0,255)")))
127 (should (equal '(1.0 1.0 1.0)
128 (kite-parse-color "rgb(255,255,255)")))
129
130 ;; float division
131 (should (equal `(0.0 0.0 ,(/ 1.0 255.0))
132 (kite-parse-color "rgb(0,0,1)")))
133
134 ;; whitespace
135 (should (equal '(0.0 0.0 0.0)
136 (kite-parse-color "rgb( 0 , 0 , 0 )")))
137
138 ;; negative values
139 (should (equal '(0.0 0.0 0.0)
140 (kite-parse-color "rgb(-0, -0, -0)")))
141
142 ;; clamping
143 (should (equal '(0.0 1.0 1.0)
144 (kite-parse-color "rgb(-100, 500, 123456)"))))
145
146 (ert-deftest kite-test-rgb-percent ()
147 (should (equal '(0.0 0.0 0.0)
148 (kite-parse-color "rgb(0%,0%,0%)")))
149 (should (equal '(1.0 0.0 0.0)
150 (kite-parse-color "rgb(100%,0%,0%)")))
151 (should (equal '(0.0 1.0 0.0)
152 (kite-parse-color "rgb(0%,100%,0%)")))
153 (should (equal '(0.0 0.0 1.0)
154 (kite-parse-color "rgb(0%,0%,100%)")))
155 (should (equal '(1.0 1.0 1.0)
156 (kite-parse-color "rgb(100%,100%,100%)")))
157 (should (equal `(0.0 0.0 ,(/ 1.0 100.0))
158 (kite-parse-color "rgb(0%,0%,1%)")))
159 (should (equal '(0.0 0.0 0.0)
160 (kite-parse-color "rgb( 0% , 0% , 0% )")))
161 (should (equal '(0.0 1.0 1.0)
162 (kite-parse-color "rgb(-20%, 101%, 1000%)"))))
163
164 (ert-deftest kite-test-rgba-integer ()
165 (should (equal '(0.0 0.0 0.0 0.0)
166 (kite-parse-color "rgba(0,0,0,-0.2)")))
167 (should (equal '(1.0 0.0 0.0 0.4)
168 (kite-parse-color "rgba(255,0,0,0.4)")))
169 (should (equal '(0.0 1.0 0.0 0.6)
170 (kite-parse-color "rgba(0,255,0,0.6)")))
171 (should (equal '(0.0 0.0 1.0 0.8)
172 (kite-parse-color "rgba(0,0,255,.8)")))
173 (should (equal '(1.0 1.0 1.0 1.0)
174 (kite-parse-color "rgba(255,255,255,1)")))
175 (should (equal `(0.0 0.0 ,(/ 1.0 255.0) 0.01)
176 (kite-parse-color "rgba(0,0,1,0.01)")))
177 (should (equal '(0.0 0.0 0.0 1.0)
178 (kite-parse-color "rgba( 0 , 0 , 0, 1. )"))))
179
180 (ert-deftest kite-test-rgba-percent ()
181 (should (equal '(0.0 0.0 0.0 0.0)
182 (kite-parse-color "rgba(0%,0%,0%,-0.2)")))
183 (should (equal '(1.0 0.0 0.0 0.4)
184 (kite-parse-color "rgba(100%,0%,0%,0.4)")))
185 (should (equal '(0.0 1.0 0.0 0.6)
186 (kite-parse-color "rgba(0%,100%,0%,0.6)")))
187 (should (equal '(0.0 0.0 1.0 0.8)
188 (kite-parse-color "rgba(0%,0%,100%,.8)")))
189 (should (equal '(1.0 1.0 1.0 1.0)
190 (kite-parse-color "rgba(100%,100%,100%,1)")))
191 (should (equal `(0.0 0.0 ,(/ 1.0 100.0) 0.01)
192 (kite-parse-color "rgba(0%,0%,1%,0.01)")))
193 (should (equal '(0.0 0.0 0.0 1.0)
194 (kite-parse-color "rgba( 0% , 0% , 0%, 1. )"))))
195
196 (ert-deftest kite-test-hsl ()
197 (should (equal '(1.0 0.0 0.0)
198 (kite-parse-color "hsl(0, 100%, 50%)")))
199 (should (equal '(0.0 1.0 0.0)
200 (kite-parse-color "hsl(120, 100%, 50%)")))
201 (should (equal '(0.5 1.0 0.5)
202 (kite-parse-color "hsl(120, 100%, 75%)")))
203 (should (equal '(0.25 0.75 0.25)
204 (kite-parse-color "hsl(120, 50%, 50%)")))
205 (should (equal '(0.0 0.0 1.0)
206 (kite-parse-color "hsl(240, 200%, 50%)")))
207 (should (equal '(0.5 0.5 0.5)
208 (kite-parse-color "hsl(0, -50%, 50%)")))
209 (should (equal '(0.0 0.0 1.0)
210 (kite-parse-color "hsl(600, 200%, 50%)")))
211 (should (equal '(0.0 0.0 1.0)
212 (kite-parse-color "hsl(-120, 200%, 50%)"))))
213
214 (ert-deftest kite-test-hsla ()
215 (should (equal '(1.0 0.0 0.0 0.0)
216 (kite-parse-color "hsla(0, 100%, 50%, 0.)")))
217 (should (equal '(0.0 1.0 0.0 1.0)
218 (kite-parse-color "hsla(120, 100%, 50%, 2.0)")))
219 (should (equal '(0.5 1.0 0.5 0.0)
220 (kite-parse-color "hsla(120, 100%, 75%, -10)")))
221 (should (equal '(0.25 0.75 0.25 0.5)
222 (kite-parse-color "hsla(120, 50%, 50%, .5)")))
223 (should (equal '(0.0 0.0 1.0 0.0)
224 (kite-parse-color "hsla(240, 200%, 50%, 0)")))
225 (should (equal '(0.5 0.5 0.5 0.0)
226 (kite-parse-color "hsla(0, -50%, 50%, -0)")))
227 (should (equal '(0.0 0.0 1.0 1.0)
228 (kite-parse-color "hsla(600, 200%, 50% , 5.)")))
229 (should (equal '(0.0 0.0 1.0 1.0)
230 (kite-parse-color "hsla(-120, 200%, 50% , 10.00 )"))))
231
232 (ert-deftest kite-test-invalid-hex ()
233 ;; hex, too short
234 (should (null (kite-parse-color "#1")))
235 (should (null (kite-parse-color "#12")))
236
237 ;; hex, invalid length
238 (should (null (kite-parse-color "#1234")))
239 (should (null (kite-parse-color "#12345")))
240
241 ;; hex, too long
242 (should (null (kite-parse-color "#1234567")))
243 (should (null (kite-parse-color "#12345678")))
244
245 ;; hex, invalid characters
246 (should (null (kite-parse-color "#00g")))
247 (should (null (kite-parse-color "#00HH00"))))
248
249 (ert-deftest kite-test-invalid-rgb ()
250 ;; rgb, mix percent and integers
251 (should (null (kite-parse-color "rgb(0,0%,0)")))
252 (should (null (kite-parse-color "rgb(100%, 100%, 0)")))
253
254 ;; rgb, comma missing
255 (should (null (kite-parse-color "rgb(100%, 100% 0)")))
256
257 ;; rgb, not enough components
258 (should (null (kite-parse-color "rgb(0)")))
259 (should (null (kite-parse-color "rgb(0,0)")))
260 (should (null (kite-parse-color "rgb(0%)")))
261
262 ;; rgb, too many components
263 (should (null (kite-parse-color "rgb(0,0,0,0)")))
264 (should (null (kite-parse-color "rgb(0%,0%,0%,0%)")))
265
266 ;; rgb, invalid whitespace
267 (should (null (kite-parse-color "rgb (0,0,0)")))
268 (should (null (kite-parse-color " rgb(0,0,0)")))
269 (should (null (kite-parse-color "rgb(0,0,0) ")))
270 (should (null (kite-parse-color "rgb(0 %, 0 %, 0 %) ")))
271 (should (null (kite-parse-color "rgb(- 0%, - 0%, - 0%) ")))
272 (should (null (kite-parse-color "rgb(- 0, - 0, - 0)"))))
273
274 ;; rgb, invalid capitalization
275 (should (null (kite-parse-color "RGB(0,0,0)")))
276 (should (null (kite-parse-color "Rgb(0,0,0)")))
277
278 (ert-deftest kite-test-invalid-rgba ()
279
280 ;; rgba, mix percent and integers
281 (should (null (kite-parse-color "rgba(0,0%,0,0)")))
282 (should (null (kite-parse-color "rgba(100%, 100%, 0, 0)")))
283 (should (null (kite-parse-color "rgba(0, 0, 0, 100%)")))
284 (should (null (kite-parse-color "rgba(0%, 0%, 0%, 100%)")))
285
286 ;; rgba, not enough components
287 (should (null (kite-parse-color "rgba(0,0,0)")))
288 (should (null (kite-parse-color "rgba(0%,0%,0%)")))
289
290 ;; rgba, too many components
291 (should (null (kite-parse-color "rgba(0,0,0,0,0)")))
292 (should (null (kite-parse-color "rgb(0%,0%,0%,0%,0%)")))
293
294 ;; rgba, invalid whitespace
295 (should (null (kite-parse-color "rgba (0,0,0,0)")))
296 (should (null (kite-parse-color " rgba(0,0,0,0)")))
297 (should (null (kite-parse-color "rgba(0,0,0,0) ")))
298 (should (null (kite-parse-color "rgba(0 %, 0 %, 0 %, 0) ")))
299 (should (null (kite-parse-color "rgba(- 0%, - 0%, - 0%, 0) ")))
300 (should (null (kite-parse-color "rgba(- 0, - 0, - 0, 0)"))))
301
302 (ert-deftest kite-test-invalid-hsl ()
303 ;; hsl, mix percent and integers
304 (should (null (kite-parse-color "hsl(0%,0%,0%)")))
305 (should (null (kite-parse-color "hsl(100, 100%, 0)")))
306
307 ;; hsl, comma missing
308 (should (null (kite-parse-color "hsl(100, 100% 0%)")))
309
310 ;; hsl, not enough components
311 (should (null (kite-parse-color "hsl(0)")))
312 (should (null (kite-parse-color "hsl(0,0%)")))
313
314 ;; hsl, too many components
315 (should (null (kite-parse-color "hsl(0,0%,0%,0%)")))
316 (should (null (kite-parse-color "hsl(0,0%,0%,0)")))
317
318 ;; hsl, invalid whitespace
319 (should (null (kite-parse-color "hsl (0,0%,0%)")))
320 (should (null (kite-parse-color " hsl(0,0%,0%)")))
321 (should (null (kite-parse-color "hsl(0,0%,0%) ")))
322 (should (null (kite-parse-color "hsl(0, 0 %, 0 %) ")))
323 (should (null (kite-parse-color "hsl(- 0, - 0%, - 0%) ")))
324
325 ;; hsl, invalid capitalization
326 (should (null (kite-parse-color "HSL(0,0%,0%)")))
327 (should (null (kite-parse-color "Hsl(0,0%,0%)"))))
328
329 (ert-deftest kite-test-invalid-hsla ()
330 ;; hsla, mix percent and integers
331 (should (null (kite-parse-color "hsla(0%,0%,0%,0)")))
332 (should (null (kite-parse-color "hsla(100, 100%, 0%, 0%)")))
333
334 ;; hsla, comma missing
335 (should (null (kite-parse-color "hsla(100, 100% 0%, 0)")))
336
337 ;; hsla, not enough components
338 (should (null (kite-parse-color "hsla(0)")))
339 (should (null (kite-parse-color "hsla(0,0%,0%)")))
340
341 ;; hsla, too many components
342 (should (null (kite-parse-color "hsla(0,0%,0%,0,0)")))
343
344 ;; hsla, invalid whitespace
345 (should (null (kite-parse-color "hsla (0,0%,0%,0)")))
346 (should (null (kite-parse-color " hsla(0,0%,0%,0)")))
347 (should (null (kite-parse-color "hsla(0,0%,0%,0) ")))
348 (should (null (kite-parse-color "hsla(0, 0 %, 0 %, 0) ")))
349 (should (null (kite-parse-color "hsla(- 0, - 0%, - 0%, - 0) ")))
350
351 ;; hsla, invalid capitalization
352 (should (null (kite-parse-color "HSLA(0,0%,0%,0)")))
353 (should (null (kite-parse-color "Hsla(0,0%,0%,0)"))))
354
355 (provide 'kite-color-tests)
015dfbb @jscheid Add end-of-file markers
authored
356
357 ;;; kite-color-tests.el ends here
Something went wrong with that request. Please try again.