Skip to content

Commit 349ffa1

Browse files
committed
Merge branch 'master' into rsw and fix a few tests
2 parents 79441e9 + 4f8fa6f commit 349ffa1

File tree

2 files changed

+129
-30
lines changed

2 files changed

+129
-30
lines changed

ChangeLog

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
2024-12-26 Bob Weiner <[email protected]>
22

3+
* test/hywiki-tests.el (hywiki-tests--add-activity,
4+
hywiki-tests--add-org-id): Fix Mats prior updates
5+
to work with new typed referents.
6+
37
* hywiki.el (hywiki-add-path-link): Add optional FILE and POS arguments
48
to better evaluate intermittent test bug in 'hywiki-tests--add-path-link'.
59
It fails on a call to this function only when all tests are run; never
@@ -56,6 +60,12 @@
5660
to 'hywiki-maybe-highlight-wikiwords-in-frame'.
5761
Rename 'hywiki-get-page-list' to 'hywiki-get-wikiword-list'.
5862

63+
2024-12-24 Mats Lidell <[email protected]>
64+
65+
* test/hywiki-tests.el (hywiki-tests--a-wikiword-in-hywiki-directory)
66+
(hywiki-tests--wikiword-identified-with-delimiters): Add tests for
67+
hywiki words with delimiters.
68+
5969
2024-12-23 Bob Weiner <[email protected]>
6070

6171
* test/hywiki-tests.el (hywiki-tests--add-*): Rewrite to handle typed
@@ -82,6 +92,11 @@
8292
(hywiki-create-page): Add type to hash value so is a cons of
8393
(page . <page-file-path>).
8494

95+
2024-12-23 Mats Lidell <[email protected]>
96+
97+
* test/hywiki-tests.el (hywiki-tests--add-activity)
98+
(hywiki-tests--add-org-roam-node): Add tests.
99+
85100
2024-12-22 Bob Weiner <[email protected]>
86101

87102
* hywiki.el (hywiki-find-referent): Fix doc string to describe how

test/hywiki-tests.el

+114-30
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Mats Lidell
44
;;
55
;; Orig-Date: 18-May-24 at 23:59:48
6-
;; Last-Mod: 26-Dec-24 at 22:49:26 by Bob Weiner
6+
;; Last-Mod: 26-Dec-24 at 23:34:51 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -22,6 +22,7 @@
2222
(require 'with-simulated-input)
2323
(require 'hy-test-helpers)
2424
(require 'hywiki)
25+
(require 'hsys-org)
2526
(require 'ox-publish)
2627

2728
(ert-deftest hywiki-tests--hywiki-create-page--adds-file-in-wiki-folder ()
@@ -95,6 +96,68 @@
9596
(hywiki-mode 0)
9697
(hy-delete-dir-and-buffer hywiki-directory))))
9798

99+
(ert-deftest hywiki-tests--a-wikiword-in-hywiki-directory ()
100+
"Verify WikiWord is identified if in `hywiki-directory'."
101+
(let* ((hsys-org-enable-smart-keys t)
102+
(hywiki-directory (make-temp-file "hywiki" t))
103+
(referent (hywiki-add-page "WikiWord"))
104+
(wiki-page (cdr referent)))
105+
(unwind-protect
106+
(with-current-buffer (find-file-noselect wiki-page)
107+
(hywiki-mode 0)
108+
(insert "AnotherWikiWord")
109+
(newline nil t)
110+
(goto-char 4)
111+
(should (hywiki-word-at)))
112+
(hy-delete-file-and-buffer wiki-page)
113+
(hy-delete-dir-and-buffer hywiki-directory))))
114+
115+
(ert-deftest hywiki-tests--wikiword-identified-with-delimiters ()
116+
"Verify WikiWord is identified when surrounded by delimiters."
117+
(let ((hsys-org-enable-smart-keys t)
118+
(hywiki-directory (make-temp-file "hywiki" t)))
119+
(unwind-protect
120+
(progn
121+
(hywiki-mode 1)
122+
123+
;; Matches a WikiWord
124+
(dolist (v '("WikiWord" "[WikiWord]" "[[WikiWord]]" "{WikiWord}" "(WikiWord)"
125+
"<WikiWord>" "<<WikiWord>>" "{[[WikiWord]]}" "([[WikiWord]])"
126+
"[WikiWord AnotherWord]"
127+
))
128+
(with-temp-buffer
129+
(org-mode)
130+
(insert v)
131+
(newline nil t)
132+
(goto-char 6)
133+
(should (string= "WikiWord" (hywiki-word-at)))))
134+
135+
;; Identifies as org link (Note: Not checked if target
136+
;; exists.) AND matches WikiWord
137+
(dolist (v '("[[hy:WikiWord]]" "[[hy:WikiWord\\]]]"))
138+
(with-temp-buffer
139+
(org-mode)
140+
(insert v)
141+
(newline nil t)
142+
(goto-char 6)
143+
(font-lock-ensure)
144+
(should (hsys-org-face-at-p 'org-link))
145+
(should (string= "WikiWord" (hywiki-word-at)))))
146+
147+
;; Identifies as org link (Note: Not checked if target
148+
;; exists.) AND DOES NOT match WikiWord
149+
(dolist (v '("[[WikiWord AnotherWord]]"))
150+
(with-temp-buffer
151+
(org-mode)
152+
(insert v)
153+
(newline nil t)
154+
(goto-char 6)
155+
(font-lock-ensure)
156+
(should (hsys-org-face-at-p 'org-link))
157+
(should-not (string= "WikiWord" (hywiki-word-at))))))
158+
(hywiki-mode 0)
159+
(hy-delete-dir-and-buffer hywiki-directory))))
160+
98161
(ert-deftest hywiki-tests--at-wikiword-finds-word-and-section ()
99162
"Verify `hywiki-word-at' finds WikiWord and section if available."
100163
(let ((hywiki-directory (make-temp-file "hywiki" t)))
@@ -600,7 +663,17 @@ Note special meaning of `hywiki-allow-plurals-flag'."
600663
(should (equal referent (hywiki-get-referent "WikiWord"))))
601664
(hy-delete-dir-and-buffer hywiki-directory))))
602665

603-
;; hywiki-add-activity -- Requires activities
666+
(ert-deftest hywiki-tests--add-activity ()
667+
"Verify `hywiki-add-activity'."
668+
(let ((hywiki-directory (make-temp-file "hywiki" t))
669+
(wikiword "WikiWord"))
670+
(unwind-protect
671+
(mocklet ((require => t)
672+
(activities-completing-read => "activity"))
673+
(hywiki-add-activity wikiword)
674+
(should (equal '(activity . "activity")
675+
(hywiki-get-referent wikiword))))
676+
(hy-delete-dir-and-buffer hywiki-directory))))
604677

605678
(ert-deftest hywiki-tests--add-bookmark ()
606679
"Verify `hywiki-add-bookmark'."
@@ -696,34 +769,45 @@ Note special meaning of `hywiki-allow-plurals-flag'."
696769
(ert-deftest hywiki-tests--add-org-id ()
697770
"Verify `hywiki-add-org-id'."
698771
;; Error case - Non org-mode buffer
699-
(let ((filea (make-temp-file "hypb" nil ".txt")))
700-
(unwind-protect
701-
(with-current-buffer (find-file filea)
702-
(mocklet (((hmouse-choose-link-and-referent-windows) => (list nil (get-buffer-window))))
703-
(should-error (hywiki-add-org-id "WikiWord") :type '(error))))
704-
(hy-delete-file-and-buffer filea)))
705-
706-
(let ((filea (make-temp-file "hypb" nil ".org")))
707-
(unwind-protect
708-
(with-current-buffer (find-file filea)
709-
(insert "* header\n")
710-
711-
;; Error-case - No Org ID and read only
712-
(setq buffer-read-only t)
713-
(mocklet (((hmouse-choose-link-and-referent-windows) => (list nil (get-buffer-window))))
714-
(should-error (hywiki-add-org-id "WikiWord") :type '(error))
715-
716-
;; Normal case - Org-mode with Org ID
717-
(goto-char (point-max))
718-
(setq buffer-read-only nil)
719-
(defvar hywiki-test--org-id)
720-
(let ((referent-value (cdr (hywiki-add-org-id "WikiWord"))))
721-
(if (stringp referent-value)
722-
(should (string-prefix-p "ID: " referent-value))
723-
(error "(hywiki-tests--add-org-id): referent value is a non-string: %s" referent-value)))))
724-
(hy-delete-file-and-buffer filea))))
725-
726-
;; hywiki-add-org-roam-node -- Requires org-roam
772+
(let ((wikiword "WikiWord"))
773+
(let ((filea (make-temp-file "hypb" nil ".txt")))
774+
(unwind-protect
775+
(with-current-buffer (find-file filea)
776+
(mocklet (((hmouse-choose-link-and-referent-windows) => (list nil (get-buffer-window))))
777+
(should-error (hywiki-add-org-id wikiword) :type '(error))))
778+
(hy-delete-file-and-buffer filea)))
779+
780+
(let ((filea (make-temp-file "hypb" nil ".org")))
781+
(unwind-protect
782+
(with-current-buffer (find-file filea)
783+
(insert "* header\n")
784+
785+
;; Error-case - No Org ID and read only
786+
(setq buffer-read-only t)
787+
(mocklet (((hmouse-choose-link-and-referent-windows) => (list nil (get-buffer-window))))
788+
(should-error (hywiki-add-org-id wikiword) :type '(error))
789+
790+
;; Normal case - Org-mode with Org ID
791+
(goto-char (point-max))
792+
(setq buffer-read-only nil)
793+
(defvar hywiki-test--org-id)
794+
(let ((referent-value (cdr (hywiki-add-org-id wikiword))))
795+
(if (stringp referent-value)
796+
(should (string-prefix-p "ID: " referent-value))
797+
(error "(hywiki-tests--add-org-id): referent value is a non-string: %s" referent-value)))))
798+
(hy-delete-file-and-buffer filea)))))
799+
800+
(ert-deftest hywiki-tests--add-org-roam-node ()
801+
"Verify `hywiki-add-org-roam-node'."
802+
(let ((hywiki-directory (make-temp-file "hywiki" t))
803+
(wikiword "WikiWord"))
804+
(unwind-protect
805+
(mocklet ((require => t)
806+
((org-roam-node-read) => "org-roam-node"))
807+
(hywiki-add-org-roam-node wikiword)
808+
(should (equal '(org-roam-node . "org-roam-node")
809+
(hywiki-get-referent wikiword))))
810+
(hy-delete-dir-and-buffer hywiki-directory))))
727811

728812
(provide 'hywiki-tests)
729813
;;; hywiki-tests.el ends here

0 commit comments

Comments
 (0)