Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
2025-04-23 Mats Lidell <matsl@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 <matsl@gnu.org>

* test/hywiki-tests.el (hywiki-tests--wikiword-step-check): Update test
Expand Down
18 changes: 18 additions & 0 deletions test/hy-test-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 39 additions & 2 deletions test/hywiki-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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."
Expand Down