Merge pull request #212 from bkaestner/main

Make DOCSTRING in mtt-define-test optional
This commit is contained in:
Protesilaos Stavrou 2026-04-10 21:29:03 +03:00 committed by GitHub
commit 44cc370313
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -35,17 +35,22 @@
(require 'ert) (require 'ert)
(require 'modus-themes) (require 'modus-themes)
(defmacro mtt-define-test (symbol docstring &rest body) (defmacro mtt-define-test (symbol &rest args)
"Write test for SYMBOL with DOCSTRING that runs BODY. "Write test for SYMBOL with DOCSTRING that runs BODY.
If docstring is nil, use a generic snippet of text." If DOCSTRING is nil, use a generic snippet of text.
(declare (indent defun))
`(ert-deftest ,(intern (format "mtt-%s" symbol)) ()
,(if (stringp docstring)
docstring
(format "Test that `%s' does the right thing." symbol))
,@body))
(mtt-define-test modus-themes--hex-to-rgb nil \(fn NAME [DOCSTRING] BODY...)"
(declare (doc-string 2) (indent defun))
(let* ((has-docstring (stringp (car args)))
(docstring (if has-docstring
(car args)
(format "Test that `%s' does the right thing." symbol)))
(body (if has-docstring (cdr args) args)))
`(ert-deftest ,(intern (format "mtt-%s" symbol)) ()
,docstring
,@body)))
(mtt-define-test modus-themes--hex-to-rgb
(should (equal (modus-themes--hex-to-rgb "#fff") (list 1.0 1.0 1.0))) (should (equal (modus-themes--hex-to-rgb "#fff") (list 1.0 1.0 1.0)))
(should (equal (modus-themes--hex-to-rgb "#000") (list 0.0 0.0 0.0))) (should (equal (modus-themes--hex-to-rgb "#000") (list 0.0 0.0 0.0)))
(should (equal (modus-themes--hex-to-rgb "#f00") (list 1.0 0.0 0.0))) (should (equal (modus-themes--hex-to-rgb "#f00") (list 1.0 0.0 0.0)))
@ -94,7 +99,7 @@ Also see `modus-themes-test--modus-themes--hex-to-rgb'."
(should-error (modus-themes-contrast "#ffffff" "#00000")) (should-error (modus-themes-contrast "#ffffff" "#00000"))
(should-error (modus-themes-contrast "#fffff" "#00000"))) (should-error (modus-themes-contrast "#fffff" "#00000")))
(mtt-define-test modus-themes--color-eight-to-six-digits nil (mtt-define-test modus-themes--color-eight-to-six-digits
(should (string= (modus-themes--color-eight-to-six-digits "#f00") "#f00")) (should (string= (modus-themes--color-eight-to-six-digits "#f00") "#f00"))
(should (string= (modus-themes--color-eight-to-six-digits "#ff1919") "#ff1919")) (should (string= (modus-themes--color-eight-to-six-digits "#ff1919") "#ff1919"))
(should (string= (modus-themes--color-eight-to-six-digits "#ffff19991999") "#ff1919"))) (should (string= (modus-themes--color-eight-to-six-digits "#ffff19991999") "#ff1919")))
@ -108,27 +113,27 @@ Also see `modus-themes-test--modus-themes--hex-to-rgb'."
(should (string= (modus-themes-adjust-value "#505050" 0) "#505050")) (should (string= (modus-themes-adjust-value "#505050" 0) "#505050"))
(should-error (modus-themes-adjust-value "#ff00" 10))) (should-error (modus-themes-adjust-value "#ff00" 10)))
(mtt-define-test modus-themes-activate nil (mtt-define-test modus-themes-activate
(if (custom-theme-p 'modus-operandi-tritanopia) (if (custom-theme-p 'modus-operandi-tritanopia)
(should-not (modus-themes-activate 'modus-operandi-tritanopia)) (should-not (modus-themes-activate 'modus-operandi-tritanopia))
(should (custom-theme-p 'modus-operandi-tritanopia)))) (should (custom-theme-p 'modus-operandi-tritanopia))))
(mtt-define-test modus-themes--belongs-to-family-p nil (mtt-define-test modus-themes--belongs-to-family-p
(should (modus-themes--belongs-to-family-p 'modus-operandi 'modus-themes)) (should (modus-themes--belongs-to-family-p 'modus-operandi 'modus-themes))
(should-not (modus-themes--belongs-to-family-p 'my-fancy-theme 'modus-themes)) (should-not (modus-themes--belongs-to-family-p 'my-fancy-theme 'modus-themes))
(should-not (modus-themes--belongs-to-family-p 'modus-operandi 'my-fancy-themes))) (should-not (modus-themes--belongs-to-family-p 'modus-operandi 'my-fancy-themes)))
(mtt-define-test modus-themes-get-all-known-themes nil (mtt-define-test modus-themes-get-all-known-themes
(should (equal (modus-themes-get-all-known-themes) modus-themes-items)) (should (equal (modus-themes-get-all-known-themes) modus-themes-items))
(should-not (modus-themes-get-all-known-themes 'my-fancy-themes))) (should-not (modus-themes-get-all-known-themes 'my-fancy-themes)))
(mtt-define-test modus-themes--background-p nil (mtt-define-test modus-themes--background-p
(should (modus-themes--background-p 'modus-operandi 'light)) (should (modus-themes--background-p 'modus-operandi 'light))
(should-not (modus-themes--background-p 'modus-operandi 'dark)) (should-not (modus-themes--background-p 'modus-operandi 'dark))
(should-not (modus-themes--background-p 'modus-operandi t)) (should-not (modus-themes--background-p 'modus-operandi t))
(should-not (modus-themes--background-p 'modus-operandi :light))) (should-not (modus-themes--background-p 'modus-operandi :light)))
(mtt-define-test modus-themes-sort nil (mtt-define-test modus-themes-sort
(let ((first-has-prefix-fn (lambda (themes prefix) (let ((first-has-prefix-fn (lambda (themes prefix)
(when-let* ((first (car themes)) (when-let* ((first (car themes))
(name (symbol-name first))) (name (symbol-name first)))
@ -155,7 +160,7 @@ Also see `modus-themes-test--modus-themes--hex-to-rgb'."
(face-list)))) (face-list))))
(modus-themes-load-theme current-theme)))) (modus-themes-load-theme current-theme))))
(mtt-define-test color-dark-p nil (mtt-define-test color-dark-p
(let ((modus-operandi-sample-foregrounds (let ((modus-operandi-sample-foregrounds
'("#a60000" '("#a60000"
"#972500" "#972500"
@ -209,7 +214,7 @@ Also see `modus-themes-test--modus-themes--hex-to-rgb'."
(should (seq-every-p #'modus-themes-color-dark-p modus-operandi-sample-foregrounds)) (should (seq-every-p #'modus-themes-color-dark-p modus-operandi-sample-foregrounds))
(should-not (seq-every-p #'modus-themes-color-dark-p modus-vivendi-sample-foregrounds)))) (should-not (seq-every-p #'modus-themes-color-dark-p modus-vivendi-sample-foregrounds))))
(mtt-define-test get-readable-foreground nil (mtt-define-test get-readable-foreground
(let ((modus-operandi-sample-foregrounds (let ((modus-operandi-sample-foregrounds
'("#a60000" '("#a60000"
"#972500" "#972500"