- (unwind-protect
- (progn
- (context-coloring-test-disable-mode-mode)
- (context-coloring-mode)
- (context-coloring-mode -1)
- (when (not torn-down)
- (ert-fail "Expected teardown function to have been called, but it wasn't.")))
- (funcall done)))))
-
-
-;;; Theme tests
-
-(defvar context-coloring-test-theme-index 0
- "Unique index for unique theme names.")
-
-(defun context-coloring-test-get-next-theme ()
- "Return a unique symbol for a throwaway theme."
- (prog1
- (intern (format "context-coloring-test-theme-%s"
- context-coloring-test-theme-index))
- (setq context-coloring-test-theme-index
- (+ context-coloring-test-theme-index 1))))
-
-(defun context-coloring-test-assert-face (level foreground &optional negate)
- "Assert that a face for LEVEL exists and that its `:foreground'
-is FOREGROUND, or the inverse if NEGATE is non-nil."
- (let* ((face (context-coloring-level-face level))
- actual-foreground)
- (when (not (or negate
- face))
- (ert-fail (format (concat "Expected face for level `%s' to exist; "
- "but it didn't")
- level)))
- (setq actual-foreground (face-attribute face :foreground))
- (when (funcall (if negate #'identity #'not)
- (string-equal foreground actual-foreground))
- (ert-fail (format (concat "Expected face for level `%s' "
- "%sto have foreground `%s'; "
- "but it %s.")
- level
- (if negate "not " "") foreground
- (if negate
- "did" (format "was `%s'" actual-foreground)))))))
-
-(defun context-coloring-test-assert-not-face (&rest arguments)
- "Assert that LEVEL does not have a face with `:foreground'
-FOREGROUND. Apply ARGUMENTS to
-`context-coloring-test-assert-face', see that function."
- (apply #'context-coloring-test-assert-face
- (append arguments '(t))))
-
-(defun context-coloring-test-assert-theme-originally-set-p
- (settings &optional negate)
- "Assert that `context-coloring-theme-originally-set-p' will
-return t for a theme with SETTINGS, or the inverse if NEGATE is
-non-nil."
- (let ((theme (context-coloring-test-get-next-theme)))
- (put theme 'theme-settings settings)
- (when (funcall (if negate #'identity #'not)
- (context-coloring-theme-originally-set-p theme))
- (ert-fail (format (concat "Expected theme `%s' with settings `%s' "
- "%sto be considered to have defined a level, "
- "but it %s.")
- theme settings
- (if negate "not " "")
- (if negate "was" "wasn't"))))))
-
-(defun context-coloring-test-assert-not-theme-originally-set-p (&rest arguments)
- "Assert that `context-coloring-theme-originally-set-p' does not
-return t for a theme with SETTINGS. Apply ARGUMENTS to
-`context-coloring-test-assert-theme-originally-set-p', see that
-function."
- (apply #'context-coloring-test-assert-theme-originally-set-p
- (append arguments '(t))))
-
-(context-coloring-test-deftest theme-originally-set-p
- (lambda ()
- (context-coloring-test-assert-theme-originally-set-p
- '((theme-face context-coloring-level-0-face)))
- (context-coloring-test-assert-theme-originally-set-p
- '((theme-face face)
- (theme-face context-coloring-level-0-face)))
- (context-coloring-test-assert-theme-originally-set-p
- '((theme-face context-coloring-level-0-face)
- (theme-face face)))
- (context-coloring-test-assert-not-theme-originally-set-p
- '((theme-face face)))))
-
-(defun context-coloring-test-assert-theme-settings-highest-level
- (settings expected-level)
- "Assert that a theme with SETTINGS has the highest level
-EXPECTED-LEVEL."
- (let ((theme (context-coloring-test-get-next-theme)))
- (put theme 'theme-settings settings)
- (context-coloring-test-assert-theme-highest-level theme expected-level)))
-
-(defun context-coloring-test-assert-theme-highest-level
- (theme expected-level &optional negate)
- "Assert that THEME has the highest level EXPECTED-LEVEL, or the
-inverse if NEGATE is non-nil."
- (let ((highest-level (context-coloring-theme-highest-level theme)))
- (when (funcall (if negate #'identity #'not) (eq highest-level expected-level))
- (ert-fail (format (concat "Expected theme with settings `%s' "
- "%sto have a highest level of `%s', "
- "but it %s.")
- (get theme 'theme-settings)
- (if negate "not " "") expected-level
- (if negate "did" (format "was %s" highest-level)))))))
-
-(defun context-coloring-test-assert-theme-not-highest-level (&rest arguments)
- "Assert that THEME's highest level is not EXPECTED-LEVEL.
-Apply ARGUMENTS to
-`context-coloring-test-assert-theme-highest-level', see that
-function."
- (apply #'context-coloring-test-assert-theme-highest-level
- (append arguments '(t))))
-
-(context-coloring-test-deftest theme-highest-level