summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modus-themes.el14
-rw-r--r--tests/modus-themes-test.el9
2 files changed, 17 insertions, 6 deletions
diff --git a/modus-themes.el b/modus-themes.el
index 0e895d9..19b0924 100644
--- a/modus-themes.el
+++ b/modus-themes.el
@@ -3797,12 +3797,14 @@ If HEX-COLOR is three or six digits, then return it as is."
(defun modus-themes-adjust-value (hex-rgb percentage)
"Adjust value of HEX-RGB colour by PERCENTAGE."
- (pcase-let* ((`(,r ,g ,b) (color-name-to-rgb hex-rgb))
- (fn (if (color-dark-p (list r g b))
- #'color-lighten-name
- #'color-darken-name))
- (value (funcall fn hex-rgb percentage)))
- (modus-themes--color-six-digits value)))
+ (if-let* ((rgb (modus-themes--hex-to-rgb hex-rgb)))
+ (pcase-let* ((`(,r ,g ,b) rgb)
+ (fn (if (color-dark-p (list r g b))
+ #'color-lighten-name
+ #'color-darken-name))
+ (value (funcall fn hex-rgb percentage)))
+ (modus-themes--color-eight-to-six-digits value))
+ (error "The `%s' has to be a valid hexadecimal RGB color" hex-rgb)))
(defvar modus-themes-registered-items nil
"List of defined themes.
diff --git a/tests/modus-themes-test.el b/tests/modus-themes-test.el
index a6a585b..c77b7d0 100644
--- a/tests/modus-themes-test.el
+++ b/tests/modus-themes-test.el
@@ -85,6 +85,15 @@ Also see `modus-themes-test--modus-themes--hex-to-rgb'."
(should (= (funcall float-2-fn "#ff00ff" "#ffffff") 3.14)))
(should-error (modus-themes-contrast "#ffffff" "#00000"))
(should-error (modus-themes-contrast "#fffff" "#00000")))
+(ert-deftest mtt-modus-themes-adjust-value ()
+ "Test that `modus-themes-adjust-value' does the right thing.
+Also see `modus-themes-test--modus-themes--hex-to-rgb'."
+ (should (string= (modus-themes-adjust-value "#ff0000" 10) "#ff1919"))
+ (should (string= (modus-themes-adjust-value "#505050" 100) "#ffffff"))
+ (should (string= (modus-themes-adjust-value "#505050" -100) "#000000"))
+ (should (string= (modus-themes-adjust-value "#505050" 0) "#505050"))
+ (should-error (modus-themes-adjust-value "#ff00" 10)))
+
(ert-deftest mtt-inheritance ()
"Ensure all faces inherit from valid faces."
;; Third-party packages, loaded if possible to better test face inheritance.