diff options
| author | Simen Heggestøyl | 2017-12-16 09:49:54 +0100 |
|---|---|---|
| committer | Simen Heggestøyl | 2017-12-17 10:26:04 +0100 |
| commit | bd9e8b31a1a38a2ffa5c2ff5e805a42ffccc36ec (patch) | |
| tree | 441203fb603da9188c2b96171abafbbffe0c8bac /test | |
| parent | ac0d6c06b805b8f05a854a69639531bf737fea3f (diff) | |
| download | emacs-bd9e8b31a1a38a2ffa5c2ff5e805a42ffccc36ec.tar.gz emacs-bd9e8b31a1a38a2ffa5c2ff5e805a42ffccc36ec.zip | |
Add command for cycling between CSS color formats
* lisp/textmodes/css-mode.el (css-mode-map): Add keybinding for
'css-cycle-color-format'.
(css--rgb-color): Add support for extracting alpha component.
(css--hex-alpha, css--color-to-4-dpc, css--named-color-to-hex)
(css--format-rgba-alpha, css--hex-to-rgb)
(css--rgb-to-named-color-or-hex): New functions.
(css-cycle-color-format): New command for cycling between color
formats.
* test/lisp/textmodes/css-mode-tests.el (css-test-color-to-4-dpc):
(css-test-named-color-to-hex, css-test-format-rgba-alpha)
(css-test-hex-to-rgb, css-test-rgb-to-named-color-or-hex)
(css-test-cycle-color-format, css-test-hex-alpha): New tests for the
changes mentioned above.
* etc/NEWS: Mention the new command.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/textmodes/css-mode-tests.el | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/lisp/textmodes/css-mode-tests.el b/test/lisp/textmodes/css-mode-tests.el index 1e58751f140..2be57726256 100644 --- a/test/lisp/textmodes/css-mode-tests.el +++ b/test/lisp/textmodes/css-mode-tests.el | |||
| @@ -244,6 +244,73 @@ | |||
| 244 | (should (member "body" completions)) | 244 | (should (member "body" completions)) |
| 245 | (should-not (member "article" completions))))) | 245 | (should-not (member "article" completions))))) |
| 246 | 246 | ||
| 247 | (ert-deftest css-test-color-to-4-dpc () | ||
| 248 | (should (equal (css--color-to-4-dpc "#ffffff") | ||
| 249 | (css--color-to-4-dpc "#fff"))) | ||
| 250 | (should (equal (css--color-to-4-dpc "#aabbcc") | ||
| 251 | (css--color-to-4-dpc "#abc"))) | ||
| 252 | (should (equal (css--color-to-4-dpc "#fab") | ||
| 253 | "#ffffaaaabbbb")) | ||
| 254 | (should (equal (css--color-to-4-dpc "#fafbfc") | ||
| 255 | "#fafafbfbfcfc"))) | ||
| 256 | |||
| 257 | (ert-deftest css-test-named-color-to-hex () | ||
| 258 | (dolist (item '(("black" "#000000") | ||
| 259 | ("white" "#ffffff") | ||
| 260 | ("salmon" "#fa8072"))) | ||
| 261 | (with-temp-buffer | ||
| 262 | (css-mode) | ||
| 263 | (insert (nth 0 item)) | ||
| 264 | (css--named-color-to-hex) | ||
| 265 | (should (equal (buffer-string) (nth 1 item)))))) | ||
| 266 | |||
| 267 | (ert-deftest css-test-format-rgba-alpha () | ||
| 268 | (should (equal (css--format-rgba-alpha 0) "0")) | ||
| 269 | (should (equal (css--format-rgba-alpha 0.0) "0")) | ||
| 270 | (should (equal (css--format-rgba-alpha 0.00001) "0")) | ||
| 271 | (should (equal (css--format-rgba-alpha 1) "1")) | ||
| 272 | (should (equal (css--format-rgba-alpha 1.0) "1")) | ||
| 273 | (should (equal (css--format-rgba-alpha 1.00001) "1")) | ||
| 274 | (should (equal (css--format-rgba-alpha 0.10000) "0.1")) | ||
| 275 | (should (equal (css--format-rgba-alpha 0.100001) "0.1")) | ||
| 276 | (should (equal (css--format-rgba-alpha 0.2524334) "0.25"))) | ||
| 277 | |||
| 278 | (ert-deftest css-test-hex-to-rgb () | ||
| 279 | (dolist (item '(("#000" "rgb(0, 0, 0)") | ||
| 280 | ("#000000" "rgb(0, 0, 0)") | ||
| 281 | ("#fff" "rgb(255, 255, 255)") | ||
| 282 | ("#ffffff" "rgb(255, 255, 255)") | ||
| 283 | ("#ffffff80" "rgba(255, 255, 255, 0.5)") | ||
| 284 | ("#fff8" "rgba(255, 255, 255, 0.5)"))) | ||
| 285 | (with-temp-buffer | ||
| 286 | (css-mode) | ||
| 287 | (insert (nth 0 item)) | ||
| 288 | (css--hex-to-rgb) | ||
| 289 | (should (equal (buffer-string) (nth 1 item)))))) | ||
| 290 | |||
| 291 | (ert-deftest css-test-rgb-to-named-color-or-hex () | ||
| 292 | (dolist (item '(("rgb(0, 0, 0)" "black") | ||
| 293 | ("rgb(255, 255, 255)" "white") | ||
| 294 | ("rgb(255, 255, 240)" "ivory") | ||
| 295 | ("rgb(18, 52, 86)" "#123456") | ||
| 296 | ("rgba(18, 52, 86, 0.5)" "#12345680"))) | ||
| 297 | (with-temp-buffer | ||
| 298 | (css-mode) | ||
| 299 | (insert (nth 0 item)) | ||
| 300 | (css--rgb-to-named-color-or-hex) | ||
| 301 | (should (equal (buffer-string) (nth 1 item)))))) | ||
| 302 | |||
| 303 | (ert-deftest css-test-cycle-color-format () | ||
| 304 | (with-temp-buffer | ||
| 305 | (css-mode) | ||
| 306 | (insert "black") | ||
| 307 | (css-cycle-color-format) | ||
| 308 | (should (equal (buffer-string) "#000000")) | ||
| 309 | (css-cycle-color-format) | ||
| 310 | (should (equal (buffer-string) "rgb(0, 0, 0)")) | ||
| 311 | (css-cycle-color-format) | ||
| 312 | (should (equal (buffer-string) "black")))) | ||
| 313 | |||
| 247 | (ert-deftest css-mdn-symbol-guessing () | 314 | (ert-deftest css-mdn-symbol-guessing () |
| 248 | (dolist (item '(("@med" "ia" "@media") | 315 | (dolist (item '(("@med" "ia" "@media") |
| 249 | ("@keyframes " "{" "@keyframes") | 316 | ("@keyframes " "{" "@keyframes") |
| @@ -301,6 +368,12 @@ | |||
| 301 | (should (equal (css--hex-color "#aabbcc") "#aabbcc")) | 368 | (should (equal (css--hex-color "#aabbcc") "#aabbcc")) |
| 302 | (should (equal (css--hex-color "#aabbccdd") "#aabbcc"))) | 369 | (should (equal (css--hex-color "#aabbccdd") "#aabbcc"))) |
| 303 | 370 | ||
| 371 | (ert-deftest css-test-hex-alpha () | ||
| 372 | (should (equal (css--hex-alpha "#abcd") "d")) | ||
| 373 | (should-not (css--hex-alpha "#abc")) | ||
| 374 | (should (equal (css--hex-alpha "#aabbccdd") "dd")) | ||
| 375 | (should-not (css--hex-alpha "#aabbcc"))) | ||
| 376 | |||
| 304 | (ert-deftest css-test-named-color () | 377 | (ert-deftest css-test-named-color () |
| 305 | (dolist (text '("@mixin black" "@include black")) | 378 | (dolist (text '("@mixin black" "@include black")) |
| 306 | (with-temp-buffer | 379 | (with-temp-buffer |