[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-goggles d4b0ea224d 169/225: Add tests covering the de
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-goggles d4b0ea224d 169/225: Add tests covering the decision whether to pulse or not |
Date: |
Wed, 12 Jan 2022 08:59:05 -0500 (EST) |
branch: elpa/evil-goggles
commit d4b0ea224d637cd3ec24e3f8f24f447a3a5da62e
Author: Evgeni Kolev <evgenysw@gmail.com>
Commit: Evgeni Kolev <evgenysw@gmail.com>
Add tests covering the decision whether to pulse or not
---
evil-goggles.el | 29 ++++++++++++++++++++-----
test/evil-goggles-test.el | 54 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 5 deletions(-)
diff --git a/evil-goggles.el b/evil-goggles.el
index 5688ff797a..e80e6f695b 100644
--- a/evil-goggles.el
+++ b/evil-goggles.el
@@ -180,22 +180,41 @@ non-nil, else for `evil-goggles-duration' seconds."
"Show or pulse overlay OV with face FACE.
DUR is used only when pulsing.
-The overlay is pulsed if variable `evil-goggles-pulse' is t."
+The overlay is pulsed if variable `evil-goggles-pulse' is t and the
+FACE is appropriate for pulsing, i.e. it has a background."
+ (pcase (evil-goggles--should-blink-or-pulse face)
+ (`(blink ,blink-face)
+ (overlay-put ov 'face blink-face))
+ (`(pulse ,pulse-bg)
+ (evil-goggles--pulse-overlay ov pulse-bg dur))))
+
+(defun evil-goggles--should-blink-or-pulse (face)
+ "Determine wheter to pulse or blink.
+
+The decision is made based on the value of `evil-goggles-pulse'.
+
+If the FACE has no background, pulsing is not supported, hence the
+decision is to blink. If the face has no foreground and/or background,
+this function tries to make the most appropriate decision whether to
+pulse or not, and whether to use the given FACE or use the fallback
+face `evil-goggles-default-face'.
+
+This function returns a list - either ('blink face) or ('pulse bg)."
(let ((fg (face-foreground face nil t))
(bg (face-background face nil t)))
(cond
;; pulse enabled and the face has a bg - pulse with the given face's bg
((and evil-goggles-pulse bg)
- (evil-goggles--pulse-overlay ov bg dur))
+ `(pulse ,bg))
;; pulse enabled and the face has no bg or fg - pulse with the default
face's bg
((and evil-goggles-pulse (null bg) (null fg))
- (evil-goggles--pulse-overlay ov (face-background
'evil-goggles-default-face nil t) dur))
+ `(pulse ,(face-background 'evil-goggles-default-face nil t)))
;; pulse disabled or face has fg only - show the hint with given face
((and (null bg) (null fg))
- (overlay-put ov 'face 'evil-goggles-default-face))
+ `(blink evil-goggles-default-face))
;; else show the hint with the given face
(t
- (overlay-put ov 'face face)))))
+ `(blink ,face)))))
(defmacro evil-goggles--if-hint-on (beg end body1 &rest body2)
"Run one block of code if hint is visible, run the other if not.
diff --git a/test/evil-goggles-test.el b/test/evil-goggles-test.el
index c951da261a..efd65a1597 100644
--- a/test/evil-goggles-test.el
+++ b/test/evil-goggles-test.el
@@ -6,6 +6,8 @@
(evil-goggles-mode)
+(defface evil-goggles--test-face '((t (:inherit region))) "Evil-goggles test
face.")
+
(ert-deftest evil-goggles-test ()
:tags '(evil-goggles)
(ert-info ("delete interactive")
@@ -27,3 +29,55 @@
"line 1\nAB[C]"
("gg\".P")
"AB[C]line 1\nABC"))
+
+(ert-deftest evil-goggles-test-show-or-pulse ()
+ "Test evil-goggles--should-blink-or-pulse - whether to pulse or blink "
+ (let ((evil-goggles-pulse t))
+ ;; enabled pusling, use fg-only - hints shouldn't pulse, hints should be
fg only (because pulsing requires a bg)
+ (progn
+ (custom-set-faces
+ '(evil-goggles--test-face ((t (:foreground "red")))))
+ (should (equal
+ (evil-goggles--should-blink-or-pulse 'evil-goggles--test-face)
+ '(blink evil-goggles--test-face))))
+
+ ;; enabled pusling, use bg-only - hints should pulse with the bg color
+ (progn
+ (custom-set-faces
+ '(evil-goggles--test-face ((t (:background "red")))))
+ (should (equal
+ (evil-goggles--should-blink-or-pulse 'evil-goggles--test-face)
+ '(pulse "red"))))
+
+ ;; enabled pulsing, use an invalid face (no fg, no bg) - hints should
pulse with default face's bg
+ (progn
+ (custom-set-faces
+ '(evil-goggles--test-face ((t (:underline nil)))))
+ (should (equal
+ (evil-goggles--should-blink-or-pulse 'evil-goggles--test-face)
+ `(pulse ,(face-background 'evil-goggles-default-face nil t))))))
+
+ (let ((evil-goggles-pulse nil))
+ ;; disabled pusling, use bg-only - hints shouldn't pulse, only bg
+ (progn
+ (custom-set-faces
+ '(evil-goggles--test-face ((t (:background "red")))))
+ (should (equal
+ (evil-goggles--should-blink-or-pulse 'evil-goggles--test-face)
+ '(blink evil-goggles--test-face))))
+
+ ;; disabled pusling, use fg-only - hints shouldn't pulse, only fg
+ (progn
+ (custom-set-faces
+ '(evil-goggles--test-face ((t (:foreground "red")))))
+ (should (equal
+ (evil-goggles--should-blink-or-pulse 'evil-goggles--test-face)
+ '(blink evil-goggles--test-face))))
+
+ ;; disalbed pulsing, use an invalid face (no fg, no bg) - hints should
blink with default face
+ (progn
+ (custom-set-faces
+ '(evil-goggles--test-face ((t (:underline nil)))))
+ (should (equal
+ (evil-goggles--should-blink-or-pulse 'evil-goggles--test-face)
+ '(blink evil-goggles-default-face))))))
- [nongnu] elpa/evil-goggles 4645be7ac2 150/225: Fix block hint using only the bg of the face, ignoring the fg, (continued)
- [nongnu] elpa/evil-goggles 4645be7ac2 150/225: Fix block hint using only the bg of the face, ignoring the fg, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 691bd2ef28 148/225: Make comments compatible with outline, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 546fdafd8f 144/225: Add comment for internal APIs, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles be3acc9142 152/225: Merge branch 'per-action-duration', ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 787b8dcabd 159/225: Fix macro indentation, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 52e77e9a3a 146/225: Simplify customization: remove duration options for each advised command, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 9a1ddbda3e 164/225: Add helper function on inherit from diff-refine-* faces, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles b611a140a2 162/225: Highlight the whole line when pasting a whole line, not just the text, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 690dd7aba3 165/225: Pulse only if the face defines a background, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles d1683b3353 167/225: Pulse if the face inherits a background, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles d4b0ea224d 169/225: Add tests covering the decision whether to pulse or not,
ELPA Syncer <=
- [nongnu] elpa/evil-goggles b620c7512c 170/225: Update README, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 2670fdf664 172/225: Revert `evaporate` overlay property, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 6d3247db6c 173/225: Enable pulsing by default on graphical displays, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles e2cccdf0c0 174/225: Tweak Makefile, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles a1a62d2b56 175/225: Fix failing CI by using latest evil-tests.el, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 1fd103dc13 177/225: evil-goggles--show-p: allow the "whitespace-only" check to be skipped, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles aad4b44727 181/225: evil-goggles--show-hint: fix value of evil-goggles--force-block, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles deab4966d7 183/225: README: reverse NEWS, newest on top, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles a7340dbb49 185/225: Run travis tests on Emacs 25.3, set `load-prefer-newer` to t in tests, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 89fcaebb6e 187/225: Add hint for `c`, `C` and `S` actions #18, ELPA Syncer, 2022/01/12