branch: externals/hyperbole
commit b0325316dfd7422355fe47dcd7050251af39798f
Author: Mats Lidell <[email protected]>
Commit: GitHub <[email protected]>
Verify highlighting range is in sync with WikiWord range (#861)
* Verify highlighting range is in sync with WikiWord range
* test/hywiki-tests.el (hywiki-tests--word-at): Extend verification to
verify that the range of the WikiWord and the range of the
highlighted text is equal iff a highlighted WikiWord exists.
---
ChangeLog | 11 +++++++----
test/hywiki-tests.el | 23 +++++++++++++++++------
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3bcd147e12..7a46db9994 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,12 @@
2026-02-09 Mats Lidell <[email protected]>
-* test/hywiki-tests.el (hywiki-tests--run-test-case): Use pos as given
- by the step definition. If an illegal position results the test
- specification is wrong and need to be changed. Give an error
- message that explains the problem.
+* test/hywiki-tests.el (hywiki-tests--word-at): Extend verification to
+ verify that the range of the WikiWord and the range of the
+ highlighted text is equal iff a highlighted WikiWord exists.
+ (hywiki-tests--run-test-case): Use pos as given by the step
+ definition. If an illegal position results the test specification is
+ wrong and need to be changed. Give an error message that explains the
+ problem.
2026-02-09 Bob Weiner <[email protected]>
diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el
index 62493b6048..a9aa5ac46e 100644
--- a/test/hywiki-tests.el
+++ b/test/hywiki-tests.el
@@ -1493,12 +1493,23 @@ comparison with expected overlays stable."
"Non-nil to perform face validation of WikiWord.")
(defun hywiki-tests--word-at ()
- "Test if there is a HyWikiWord reference at point with a referent.
-Choose what test to perform based on value of `hywiki-tests--with-face-test'."
- (when (hywiki-referent-exists-p)
- (if hywiki-tests--with-face-test
- (hywiki-highlighted-word-at)
- (hywiki-word-at))))
+ "Return potential HyWikiWord and optional #section:Lnum:Cnum at point or nil.
+When `hywiki-tests--with-face-test' is non-nil the HyWikiWord must be
+highlighted to be returned. When it is highlighted, the range of the
+highlighting and the range of the HyWikiWord is, as a side effect,
+checked for consistency."
+ (let* ((range (hywiki-referent-exists-p :range))
+ (wikiword (car range)))
+ (when wikiword
+ (if (not hywiki-tests--with-face-test)
+ wikiword
+ (save-excursion
+ (goto-char (round (/ (+ (cadr range) (caddr range)) 2.0)))
+ (let* ((highlighted-range (hywiki-highlighted-word-at :range))
+ (highlighted-wikiword (car highlighted-range)))
+ (when highlighted-wikiword
+ (should (equal range highlighted-range)))
+ highlighted-wikiword))))))
(defun hywiki-tests--verify-hywiki-word (step expected)
"Verify that `hywiki-word-at' returns t if a wikiword is EXPECTED.