branch: externals/hyperbole
commit 0f0eb92c7701130bed2cda09bbeb45231fd9eded
Author: Mats Lidell <mats.lid...@lidells.se>
Commit: GitHub <nore...@github.com>

    Add face verification for hywiki--word-face (#711)
---
 ChangeLog               | 17 +++++++++++++++++
 test/hy-test-helpers.el | 18 ++++++++++++++++++
 test/hywiki-tests.el    | 41 +++++++++++++++++++++++++++++++++++++++--
 3 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e2c20fe292..b141b29bc2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2025-04-23  Mats Lidell  <ma...@gnu.org>
+
+* test/hywiki-tests.el (hywiki-tests--word-n-face-at): Verify that point
+    is at a WikiWord where WikiWord has hywiki--word-face set.
+    (hywiki-tests--with-face-test): Control type of WikiWord check.
+    (hywiki-tests--word-at): Use either hywiki-word-at or
+    hywiki-tests--word-n-face-at controlled by
+    hywiki-tests--with-face-test.
+    (hywiki-tests--verify-hywiki-word): Use hywiki-tests--word-at.
+    (hywiki-tests--wikiword-step-check-verification-with-faces): Run the
+    step-check test verifying WikiWords and faces. Test is behind failure
+    flag.
+
+* test/hy-test-helpers.el (hy-test-word-face-at-point): Check if
+    hywiki--word-face is set at point.
+    (hy-test-word-face-at-region): Check that region has hywiki--word-face set.
+
 2025-04-21  Mats Lidell  <ma...@gnu.org>
 
 * test/hywiki-tests.el (hywiki-tests--wikiword-step-check): Update test
diff --git a/test/hy-test-helpers.el b/test/hy-test-helpers.el
index c9ada7d34e..f5eef8debc 100644
--- a/test/hy-test-helpers.el
+++ b/test/hy-test-helpers.el
@@ -127,5 +127,23 @@ and the default WORD-LENGTH is 4."
 (defvar hy-test-run-failing-flag nil
   "Non-nil means test cases that are known to fail will be tried.")
 
+(defun hy-test-word-face-at-point (&optional pos)
+  "Non-nil if `hywiki--word-face' at POS."
+  (unless pos
+    (setq pos (point)))
+  (cl-dolist (ol (overlays-at pos) nil)
+    (if (equal (overlay-get ol 'face) 'hywiki--word-face)
+        (cl-return t))))
+
+(defun hy-test-word-face-at-region (beg end)
+  "Non-nil if all chars in region [BEG, END] have `hywiki--word-face'."
+  (interactive "r")
+  (let (no-face)
+    (while (and (< beg end) (not no-face))
+      (unless (hy-test-word-face-at-point beg)
+        (setq no-face t))
+      (setq beg (1+ beg)))
+    (not no-face)))
+
 (provide 'hy-test-helpers)
 ;;; hy-test-helpers.el ends here
diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el
index 000cbaae0a..50ce75f379 100644
--- a/test/hywiki-tests.el
+++ b/test/hywiki-tests.el
@@ -1273,13 +1273,29 @@ See gh#rswgnu/hyperbole/669."
         (hy-delete-file-and-buffer wiki-page)
         (hy-delete-dir-and-buffer hywiki-directory)))))
 
+(defun hywiki-tests--word-n-face-at ()
+  "Non-nil if at a WikiWord and it has `hywiki--word-face'."
+  (cl-destructuring-bind (word beg end) (hywiki-word-at :range)
+    (when word
+      (when (hy-test-word-face-at-region beg end)
+        word))))
+
+(defvar hywiki-tests--with-face-test nil
+  "Non-nil to perform face validation of WikiWord.")
+
+(defun hywiki-tests--word-at ()
+  "Choose what test to perform based on value of 
`hywiki-tests--with-face-test'."
+  (if hywiki-tests--with-face-test
+      (hywiki-tests--word-n-face-at)
+    (hywiki-word-at)))
+
 (defun hywiki-tests--verify-hywiki-word (expected)
   "Verify that `hywiki-word-at' returns t if a wikiword is EXPECTED.
 If EXPECTED is a string also verify that the wikiword matches the
 string."
   (if (not expected)
-      (should-not (hywiki-word-at))
-    (let ((hywiki-word-found (hywiki-word-at)))
+      (should-not (hywiki-tests--word-at))
+    (let ((hywiki-word-found (hywiki-tests--word-at)))
       (if (stringp expected)
           (should (string= expected hywiki-word-found))
         (should hywiki-word-found))
@@ -1366,6 +1382,27 @@ resulting state at point is a WikiWord or not."
               (hywiki-tests--run-test-case testcase))))
       (hy-delete-dir-and-buffer hywiki-directory)))))
 
+(ert-deftest hywiki-tests--wikiword-step-check-verification-with-faces ()
+  "Run the step check to verify WikiWord is identified under change.
+Performs each operation from the step check and verifies if the
+resulting state at point is a WikiWord or not."
+  (skip-unless hy-test-run-failing-flag)
+  (hywiki-tests--preserve-hywiki-mode
+    (let* ((hywiki-directory (make-temp-file "hywiki" t))
+           (wikiHiHo (cdr (hywiki-add-page "HiHo")))
+           (wikiHi (cdr (hywiki-add-page "Hi")))
+           (wikiHo (cdr (hywiki-add-page "Ho")))
+           (wiki-page-list (list wikiHiHo wikiHi wikiHo))
+           (hywiki-tests--with-face-test t))
+      (unwind-protect
+          (progn
+            (hywiki-mode 1)
+            (dolist (testcase hywiki-tests--wikiword-step-check)
+              (with-temp-buffer
+                (hywiki-tests--run-test-case testcase))))
+        (hy-delete-files-and-buffers wiki-page-list)
+        (hy-delete-dir-and-buffer hywiki-directory)))))
+
 (defconst hywiki-tests--lorem-ipsum "\
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
 aliquet diam euismod turpis ultricies, et porta sem blandit. Sed vitae."

Reply via email to