branch: externals/hyperbole
commit 399e23286d3df1b5dc42e9ca0d173ff0968d8ea6
Author: Mats Lidell <[email protected]>
Commit: Mats Lidell <[email protected]>

    Add hywiki tests
    
    * test/hywiki-tests.el (hywiki-tests--get-page-headings):
      (hywiki-tests--get-references-at-al):
      (hywiki-tests--completion-at-point): New tests.
      (hywiki-tests--remove-keyword-args): Helper to ease comparison of
      completion candidates.
---
 ChangeLog            |  8 ++++++
 test/hywiki-tests.el | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 841e8c5a31..a934f7b219 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-02-28  Mats Lidell  <[email protected]>
+
+* test/hywiki-tests.el (hywiki-tests--get-page-headings):
+    (hywiki-tests--get-references-at-al):
+    (hywiki-tests--completion-at-point): New tests.
+    (hywiki-tests--remove-keyword-args): Helper to ease comparision of
+    completion candidates.
+
 2026-02-28  Bob Weiner  <[email protected]>
 
 * hywiki.el (hywiki--char-before): Add to communicate between
diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el
index 989a5c25da..12681d3c9e 100644
--- a/test/hywiki-tests.el
+++ b/test/hywiki-tests.el
@@ -2175,6 +2175,75 @@ expected result."
     (let (hywiki-referent-prompt-flag)
       (should (equal 'page (hywiki-word-create "WikiWord"))))))
 
+(ert-deftest hywiki-tests--get-page-headings ()
+  "Verify headings are found."
+  (hywiki-tests--preserve-hywiki-mode
+    (with-current-buffer (find-file wiki-page)
+      (insert "\
+* Header
+** SubHeader
+*** SubSubHeader
+")
+      (save-buffer))
+    (should (set:equal '("Header" "SubHeader" "SubSubHeader")
+                       (hywiki-get-page-headings wiki-page)))))
+
+(ert-deftest hywiki-tests--get-references-at-al ()
+  "Verify `hywiki-get-references' and `hywiki-get-reference-positions'."
+  (hywiki-tests--preserve-hywiki-mode
+    (hywiki-tests--insert "WikiWord")
+    (should (hywiki-get-references))
+    (should (hywiki-get-references (point-min) (point-max)))
+    (should (equal (list (cons 1 9))
+                   (hywiki-get-reference-positions)))
+    (should (equal (list (cons 1 9))
+                   (hywiki-get-reference-positions (point-min) (point-max))))))
+
+(defun hywiki-tests--remove-keyword-args (lst)
+  "Return LST with a keyworded args removed."
+  (let ((result nil)
+        (skip nil))
+    (dolist (item lst result)
+      (cond
+       (skip (setq skip nil))
+       ((keywordp item) (setq skip t))
+       (t (push item result))))
+    (nreverse result)))
+
+(ert-deftest hywiki-tests--completion-at-point ()
+  "Verify `hywiki-completion-at-point' returns proper completion candidates."
+  (hywiki-tests--preserve-hywiki-mode
+    (ert-info ("Nothing to complete")
+      (should-not (hywiki-tests--remove-keyword-args 
(hywiki-completion-at-point))))
+    (ert-info ("String 'ab' can't be completed")
+      (insert "ab")
+      (should-not (hywiki-tests--remove-keyword-args 
(hywiki-completion-at-point))))
+    (ert-info ("Word 'Wi' can be completed")
+      (erase-buffer)
+      (insert "Wi")
+      (should (equal (list 1 3 '(("WikiWord")))
+                     (hywiki-tests--remove-keyword-args 
(hywiki-completion-at-point)))))
+    (ert-info ("Word is extended to 'Wixx' so it can't be completed")
+      (insert "xx")
+      (should (equal (list 1 5 '(("WikiWord")))
+                     (hywiki-tests--remove-keyword-args 
(hywiki-completion-at-point)))))
+    (save-excursion
+      (with-current-buffer (find-file wiki-page)
+        (insert "\
+* Header
+** SubHeader
+*** SubSubHeader
+")
+        (save-buffer)))
+    (ert-info ("Word 'Wixx' can't be completed, no headers are returned")
+      (should (equal (list 1 5 '(("WikiWord")))
+                     (hywiki-tests--remove-keyword-args 
(hywiki-completion-at-point)))))
+    (ert-info ("Word 'Wiki' can be completed so headers too are returned")
+      (erase-buffer)
+      (insert "Wiki")
+      (should (equal (list 1 5 '(("WikiWord") ("WikiWord#Header") 
("WikiWord#SubHeader") ("WikiWord#SubSubHeader")))
+                     (hywiki-tests--remove-keyword-args 
(hywiki-completion-at-point)))))))
+
 (provide 'hywiki-tests)
 
 ;; This file can't be byte-compiled without the `el-mock' package

Reply via email to