Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hlissner committed Jun 6, 2017
1 parent bffd519 commit 0d3b5df
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cask
@@ -0,0 +1,7 @@
(source melpa)

(package "doom-themes" "1.2.9" "A pack of themes inspired by Atom ONE.")

(depends-on "all-the-icons")
(development
(depends-on "ert-runner"))
11 changes: 11 additions & 0 deletions Makefile
@@ -0,0 +1,11 @@
all:
@cask

test:
@cask exec ert-runner

clean:
@rm -rf .cask
@rm -f *.elc test/*.elc

.PHONY: test
116 changes: 116 additions & 0 deletions test/doom-themes-color-test.el
@@ -0,0 +1,116 @@
;;; doom-themes-color-test.el

(ert-deftest doom-themes-color ()
"TODO"
(-with-colors! ((black "#000000" "#222222" "black"))
(should-not (doom-color 'red))
(should (equal (doom-color 'black 't) "#000000"))
(should (equal (doom-color 'black '256) "#222222"))
(should (equal (doom-color 'black '16) "black"))
(should (equal (doom-color 'black '9999) (doom-color 'black 't)))
(should (equal (doom-color 'black) (doom-color 'black 't)))))

(ert-deftest doom-themes-color-detect ()
"TODO"
(-with-colors! ((red "#FF0000" "#AA4444" "red"))
(should-not (-color-p '(:background "red")))
(should (-color-p '(:foreground red)))
(should-not (-color-p '(:box `(:color red))))
(should (-color-p '(:box `(:color ,red))))
(should-not (-color-p '(:box '(:color red))))
(should-not (-color-p '(:box '(:color ,red))))

(should-not (-color-p '(:background "black")))
(should-not (-color-p '(:foreground black)))
(should-not (-color-p '(:box `(:color black))))
(should-not (-color-p '(:box `(:color ,black))))
(should-not (-color-p '(:box '(:color black))))
(should-not (-color-p '(:box '(:color ,black))))))

(ert-deftest doom-themes-color-plain-subst ()
"TODO"
(-with-colors! ((red "#FF0000" "#AA4444" "red"))
(-colorize! (:background red)
(:background (doom-color 'red '256))
256)

(-colorize! (:background blue)
(:background blue)
256)))

(ert-deftest doom-themes-color-nested-subst ()
"Should substitute color variables nested with sublists or exprs."
(-with-colors! ((red "#FF0000" "#AA4444" "red"))
(-colorize! (:box `(:color ,red))
(:box `(:color ,(doom-color 'red '256)))
256)

(-colorize! (:foreground (doom-darken red 0.2))
(:foreground (doom-darken (doom-color 'red '256) 0.2))
256)))

(ert-deftest doom-themes-color-side-effects ()
"Shouldn't alter the original value."
(-with-colors! ((red "#FF0000" "#AA4444" "red"))
(let ((plist '(:background red)))
(should plist)
(doom-themes--colorize plist 't)
(should (equal plist '(:background red))))

(let ((plist '(:box `(:color ,red))))
(should plist)
(doom-themes--colorize plist 't)
(should (equal plist '(:box `(:color ,red)))))))

(ert-deftest doom-themes-color-no-subst ()
"TODO"
(-with-colors! ((red "#FF0000" "#AA4444" "red"))
(-colorize! (:background "red")
(:background "red")
256)))

(ert-deftest doom-themes-color-recurse-subst ()
"TODO"
(-with-colors! ((red "#FF0000" "#AA4444" "red"))
(-colorize! (:foreground red :background "blue")
(:foreground (doom-color 'red 't) :background "blue")
t)

(-colorize! (:background "blue" :foreground red)
(:background "blue" :foreground (doom-color 'red 't))
t)))

(ert-deftest doom-themes-color-multi-subst ()
"TODO"
(-with-colors! ((red "#FF0000" "#AA4444" "red")
(blue "#0000FF" "#4444AA" "blue")
(white "#F9F9F9" "#FFFFFF" "white"))
(-colorize! (:background blue :foreground red)
(:background (doom-color 'blue 't) :foreground (doom-color 'red 't))
t)

(-colorize! (:background blue :distant-foreground "white" :foreground red)
(:background (doom-color 'blue 't) :distant-foreground "white" :foreground (doom-color 'red 't))
t)

(-colorize! (:background "blue" :distant-foreground white :foreground red)
(:background "blue" :distant-foreground (doom-color 'white 't) :foreground (doom-color 'red 't))
t)

(-colorize! (:background blue :distant-foreground white :foreground "red")
(:background (doom-color 'blue 't) :distant-foreground (doom-color 'white 't) :foreground "red")
t)))

(ert-deftest doom-themes-color-quoting-subst ()
"TODO"
(-with-colors! ((red "#FF0000" "#AA4444" "red"))
(-colorize! (:box `(:color red)) (:box `(:color red)) t)

(-colorize! (:box '(:color red)) (:box '(:color red)) t)

(-colorize! (:box `(:color ,red)) (:box `(:color ,(doom-color 'red 't))) t)

(-colorize! (:box '(:color ,red)) (:box '(:color ,red)) t)))

(provide 'doom-themes-color-test)
;;; doom-themes-color-test.el ends here
86 changes: 86 additions & 0 deletions test/doom-themes-face-test.el
@@ -0,0 +1,86 @@
;;; doom-themes-face-test.el

(ert-deftest doom-themes-build-simple-face ()
"TODO"
(-with-colors! ((blue "#0000FF" "#2222DD" "blue"))
;; literal test
(let ((face '(default '((t (:background "blue"))))))
(should (equal (-build-face face)
'(list 'default '((t (:background "blue")))))))

;; plain
(should
(equal (-build-face '(default :background "blue"))
'(list 'default (list (list (quote t) (list :background "blue"))))))))

(ert-deftest doom-themes-build-nested-face ()
"Test `doom-themes--build-face'; builds a face out of a simple sub-spec that
uses a doom-themes function to modify the resulting color."
(-with-colors! ((blue "#0000FF" "#2222DD" "blue"))
(should
(equal (-build-face '(default :background (doom-darken blue 0.2)))
'(list 'default
(list (list '((class color) (min-colors 257)) (list :background (doom-darken (doom-color 'blue '257) 0.2)))
(list '((class color) (min-colors 256)) (list :background (doom-darken (doom-color 'blue '256) 0.2)))
(list '((class color) (min-colors 16)) (list :background (doom-darken (doom-color 'blue '16) 0.2)))))))))

(ert-deftest doom-themes-full-build ()
"Test `doom-themes--build-face'; builds a face out of a list of sub-specs that
use all the available functionality of this API. `doom-themes--colors' is left
blank to prevent expansion of colors."
(-with-colors! ()
(-with-faces!
((default :background bg :foreground fg)
;; (doom-default :inherit 'default :background (doom-lighten bg 0.2))
(fringe
(&all :inherit 'default)
(&dark :foreground grey)
(&light :foreground light-grey))
(avy-lead-face
`((((background dark)) (:background ,(car highlight) :foreground ,(car black) :distant-foreground ,(car white)))
(((background light)) (:background ,(car highlight) :foreground ,(car white) :distant-foreground ,(car black))))))

(should (equal (doom-themes-common-faces)
'((list 'default (list (list 't (list :background bg :foreground fg))))
(list 'fringe (list (list '((background dark)) (list :inherit 'default :foreground grey))
(list '((background light)) (list :inherit 'default :foreground light-grey))))
(list 'avy-lead-face `((((background dark)) (:background ,(car highlight) :foreground ,(car black) :distant-foreground ,(car white)))
(((background light)) (:background ,(car highlight) :foreground ,(car white) :distant-foreground ,(car black)))))))))))


(ert-deftest doom-themes-build-simple-bg-face ()
"Test `doom-themes--build-face' with a simple spec that includes &dark/&light sub-specs."
(-with-colors! ((blue "#0000FF" "#2222DD" "blue"))
(should
(equal (-build-face
'(default
(&all :background "blue")
(&dark :foreground "white")
(&light :foreground "black")))
'(list 'default
(list (list '((background dark))
(list :background "blue" :foreground "white"))
(list '((background light))
(list :background "blue" :foreground "black"))))))))

(ert-deftest doom-themes-build-complex-bg-face ()
"Test `doom-themes--build-face' with a complex spec that includes &dark/&light sub-specs."
(-with-colors! ((blue "#2222DD" "#0000FF" "blue")
(red "#DD2222" "#FF0000" "red")
(white "#EEEEEE" "#FFFFFF" "white"))
(should
(equal (-build-face
'(default
(&all :background blue)
(&dark :foreground white)
(&light :foreground red)))
'(list 'default
(list (list '((class color) (min-colors 257) (background dark)) (list :background (doom-color 'blue '257) :foreground (doom-color 'white '257)))
(list '((class color) (min-colors 256) (background dark)) (list :background (doom-color 'blue '256) :foreground (doom-color 'white '256)))
(list '((class color) (min-colors 16) (background dark)) (list :background (doom-color 'blue '16) :foreground (doom-color 'white '16)))
(list '((class color) (min-colors 257) (background light)) (list :background (doom-color 'blue '257) :foreground (doom-color 'red '257)))
(list '((class color) (min-colors 256) (background light)) (list :background (doom-color 'blue '256) :foreground (doom-color 'red '256)))
(list '((class color) (min-colors 16) (background light)) (list :background (doom-color 'blue '16) :foreground (doom-color 'red '16)))))))))

(provide 'doom-themes-face-test)
;;; doom-themes-face-test.el ends here
27 changes: 27 additions & 0 deletions test/test-helper.el
@@ -0,0 +1,27 @@
;;; test-helper.el

(push (expand-file-name "../" (file-name-directory load-file-name)) load-path)
(push (expand-file-name "../themes" (file-name-directory load-file-name)) load-path)

(require 'doom-themes)
(require 'doom-themes-common)

(defalias '-color-p 'doom-themes--colors-p)
(defalias '-build-face 'doom-themes--build-face)

(defmacro -colorize! (rulesA rulesB type)
`(should
(equal (doom-themes--colorize ',rulesA ',type)
',rulesB)))

(defmacro -with-colors! (colors &rest body)
(declare (indent defun))
`(let ((doom-themes--colors '(,@colors)))
,@body))

(defmacro -with-faces! (faces &rest body)
(declare (indent defun))
`(let ((doom-themes-common-faces ',faces))
,@body))

;;; test-helper.el ends here

0 comments on commit 0d3b5df

Please sign in to comment.