make-color-test.el 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. (require 'ert)
  2. ;; We need additional functions to compare floats
  3. (cl-defun make-color-floats-equal-p (f1 f2 &optional (precision .001))
  4. "Return t if floating numbers F1 and F2 are equal.
  5. PRECISION is a float telling how many decimal places are taken.
  6. F1 and F2 are rounded to that PRECISION."
  7. (= (round f1 precision)
  8. (round f2 precision)))
  9. (cl-defun make-color-float-lists-equal-p (l1 l2 &optional (precision .001))
  10. "Return t if lists L1 and L2 contain equal floating numbers.
  11. See `make-color-floats-equal-p' for PRECISION."
  12. (cl-loop for elt1 in l1
  13. for elt2 in l2
  14. unless (make-color-floats-equal-p elt1 elt2 precision) return nil
  15. finally return t))
  16. (ert-deftest make-color-test-+ ()
  17. "Test `make-color-+'."
  18. (should (make-color-floats-equal-p (make-color-+ '(0.23 0.401)) .631))
  19. (should (make-color-floats-equal-p (make-color-+ '(0.23 0.93)) 1))
  20. (should (make-color-floats-equal-p (make-color-+ '(0.1 -0.8 -0.7)) 0))
  21. (should (make-color-floats-equal-p (make-color-+ '(0.1 -0.8 -0.7) t) .6)))
  22. (ert-deftest make-color-test-shift-color ()
  23. "Test `make-color-shift-color-by-rgb' and `make-color-shift-color-by-hsl'."
  24. (should (make-color-float-lists-equal-p
  25. (make-color-shift-color-by-rgb '(0.1 0 0.71) :red -0.2 :blue 0.01)
  26. '(0.0 0.0 0.72)))
  27. (should (make-color-float-lists-equal-p
  28. (make-color-shift-color-by-hsl '(0 0 0)
  29. :hue -0.3 :luminance 0.4 :saturation 0.1)
  30. '(0.376 0.36 0.44))))
  31. (ert-deftest make-color-test-get-color-from-face-spec ()
  32. "Test `make-color-get-color-from-face-spec'."
  33. (should (equal (make-color-get-color-from-face-spec
  34. :foreground '(:background "blue"))
  35. nil))
  36. (should (equal (make-color-get-color-from-face-spec
  37. :background '((font-lock-doc-face (:foreground "blue"))
  38. some-unknown-face (((:background "#123456")))))
  39. "#123456")))