diff --git a/ChangeLog b/ChangeLog index 3bcd147e..7a46db99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,12 @@ 2026-02-09 Mats Lidell -* 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 diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el index 62493b60..a9aa5ac4 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.