branch: externals/hyperbole
commit decaa4ea25a77b813f4a22219980f933812f840e
Author: bw <[email protected]>
Commit: bw <[email protected]>
hywiki.el - Update tests with hywiki-tests--preserve-hywiki-mode
---
ChangeLog | 27 +++
hproperty.el | 15 +-
hywiki.el | 79 +++++----
test/hywiki-tests.el | 445 ++++++++++++++++++++---------------------------
test/hywiki-yki-tests.el | 4 +-
5 files changed, 276 insertions(+), 294 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9f11892f9f..638a3d5582 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2026-01-18 Bob Weiner <[email protected]>
+
+* hywiki.el (hywiki--get-all-references): Handle ref ordering diffs between
+ Emacs prior to 29 and after so callers do not have to handle.
+
+* test/hywiki-tests.el (hywiki-tests--hywiki-face-region-at): Remove, unused.
+
+* hywiki.el (hywiki-highlight-word-get-range): Rename to
'hywiki-word-range-at'.
+ (hywiki-get-reference-range): Add and use in tests.
+ (hywiki-word-highlighted-at): Rename to
'hywiki-highlighted-word-at'.
+
+* test/hywiki-tests.el (hywiki-tests--word-n-face-at): Remove and replace
+ with calls to 'hywiki-highlighted-word-at'.
+
+* hproperty.el (hproperty:char-property-face-p): Fix doc to not refer to
HyWiki.
+ (hproperty:but-is-p): Add.
+
+* test/hywiki-tests.el (hywiki-tests--preserve-hywiki-mode): Fix to use the
+ actual prior value of 'hywiki-mode' since there are now 3 valid states.
+ Also setup more of the test scenarios and rewrite tests to not duplicate
+ this behavior.
+ (hywiki-tests--face-property-for-wikiword-with-wikipage): Fix this test.
+
+* test/hywiki-yki-tests.el
(hywiki-test--set-buffer-text-with-point-and-highlight):
+ For clarity change 'hywiki-mode' arg from 1 to :all and move before
+ 'erase-buffer' call.
+
2026-01-12 Bob Weiner <[email protected]>
* hywiki.el: (hywiki-word-highlight-in-buffers,
hywiki-word-highlight-in-frame):
diff --git a/hproperty.el b/hproperty.el
index 5c63146a28..9071b744e3 100644
--- a/hproperty.el
+++ b/hproperty.el
@@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 21-Aug-92
-;; Last-Mod: 31-Dec-25 at 16:02:19 by Mats Lidell
+;; Last-Mod: 18-Jan-26 at 12:04:29 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -14,7 +14,7 @@
;;; Commentary:
;;
-;; Can't use read-only buttons here because then outline-mode
+;; Can't use read-only buttons here because then `outline-mode'
;; becomes unusable.
;;; Code:
@@ -28,12 +28,13 @@
;;; ************************************************************************
(declare-function hattr:get "hbut")
+(declare-function hbut:is-p "hbut")
(declare-function ibut:map "hbut")
(declare-function ebut:map "hbut")
-;; Comment out next line out because this triggers loads of kview
-;; which loads klink which contains a defib whose priority should be set
-;; by loading klink from hibtypes.el instead.
+;; Comment out next line out because this loads kview which loads
+;; klink which contains a defib whose priority should be set by
+;; loading klink from hibtypes.el instead.
;; (eval-when-compile (require 'hyrolo))
;;; ************************************************************************
@@ -324,6 +325,7 @@ Return nil if none."
(overlays-in start end))
nil))
+(defalias 'hproperty:but-is-p 'hbut:is-p)
(defun hproperty:but-move (hproperty-but start end &optional buffer)
"Set the endpoints of HPROPERTY-BUT to START and END in optional BUFFER.
If BUFFER is nil and HPROPERTY-BUT has no buffer, put it in the current buffer;
@@ -371,8 +373,7 @@ See `hproperty:but-get'."
value)))
(defun hproperty:char-property-face-p (pos face-list)
- "At POS, skip HyWikiWord highlighting if find any face in FACE-LIST.
-Return non-nil in any such case, else nil."
+ "At POS, return non-nil if find any face in FACE-LIST, else nil."
(save-excursion
(goto-char pos)
(seq-intersection (face-at-point nil t) face-list #'eq)))
diff --git a/hywiki.el b/hywiki.el
index 578e84d693..000814dc8e 100644
--- a/hywiki.el
+++ b/hywiki.el
@@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 21-Apr-24 at 22:41:13
-;; Last-Mod: 18-Jan-26 at 08:31:39 by Bob Weiner
+;; Last-Mod: 18-Jan-26 at 17:34:29 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -553,6 +553,7 @@ Non-nil is the default."
(defun hywiki-word-store-around-point ()
"Store any HyWikiWord before or after point for post-command comparison.
+Markers are stored into `hywiki--buttonize-start' and `hywiki--buttonize-end'.
HyWikiWords are stored only outside of `hywiki-non-hook-context-p' contexts.
This is triggered by `pre-command-hook' for non-character commands,
including deletion commands and those in `hywiki-non-character-commands'."
@@ -1747,6 +1748,30 @@ After successfully finding any kind of referent, run
(run-hooks 'hywiki-find-referent-hook)
referent))
+(defun hywiki-highlighted-word-at (&optional range-flag)
+ "Return highlighted HyWikiWord and optional #section:Lnum:Cnum at point or
nil.
+If the HyWikiWord is delimited, point must be within the delimiters.
+
+With optional RANGE-FLAG, return a list of (HyWikiWord start-position
+end-position); the positions include the entire
+HyWikiWord#section:Lnum:Cnum string but exclude any delimiters.
+
+This does not test whether a referent exists for the HyWikiWord; call
+`hywiki-referent-exists-p' without an argument for that.
+
+A call to `hywiki-active-in-current-buffer-p' at point must return non-nil
+or this will return nil."
+ (when (and (hywiki-active-in-current-buffer-p)
+ (setq hywiki--range
+ (hproperty:char-property-range (point) 'face
hywiki-word-face)))
+ (let ((wikiword (buffer-substring-no-properties (car hywiki--range) (cdr
hywiki--range))))
+ (if (string-match hywiki-word-with-optional-suffix-exact-regexp wikiword)
+ (if range-flag
+ (list wikiword (car hywiki--range) (cdr hywiki--range))
+ wikiword)
+ (when range-flag
+ '(nil nil nil))))))
+
(defun hywiki-highlight-on-yank (_prop-value start end)
"Used in `yank-handled-properties' called with START and END pos of the
text."
;; When yank only part of a delimited pair, expand the range to
@@ -2649,13 +2674,19 @@ regexps of wikiwords, if the hash table is out-of-date."
;; walk across all frames here, rehighlighting HyWikiWords.
(hywiki-maybe-highlight-wikiwords-in-frame t t))))
+(defun hywiki-get-reference-range (reference)
+ "Return a (start . end) cons cell from a highlighted HyWikiWord REFERENCE."
+ (when (hproperty:but-is-p reference)
+ (cons (hproperty:but-start reference)
+ (hproperty:but-end reference))))
+
(defun hywiki-get-references (&optional start end)
"Return a list of all highlighted HyWikiWord references in the current
buffer.
Optional START and END arguments limit the search to references that at
least partially overlap that region."
(hywiki--get-all-references #'hproperty:but-get-all-in-region start end))
-(defun hywiki-get-reference-positions (&optional start end)
+ (defun hywiki-get-reference-positions (&optional start end)
"Return a list of all highlighted HyWikiWord reference (start . end)
positions.
Optional START and END arguments limit the search to references that at
least partially overlap that region."
@@ -3164,30 +3195,6 @@ Action Key press; with a prefix ARG, emulate an Assist
Key press."
(hywiki-find-referent word)
(hkey-either arg))))
-(defun hywiki-word-highlighted-at-p (&optional range-flag)
- "Return highlighted HyWikiWord and optional #section:Lnum:Cnum at point or
nil.
-If the HyWikiWord is delimited, point must be within the delimiters.
-
-With optional RANGE-FLAG, return a list of (HyWikiWord start-position
-end-position); the positions include the entire
-HyWikiWord#section:Lnum:Cnum string but exclude any delimiters.
-
-This does not test whether a referent exists for the HyWikiWord; call
-`hywiki-referent-exists-p' without an argument for that.
-
-A call to `hywiki-active-in-current-buffer-p' at point must return non-nil
-or this will return nil."
- (when (hywiki-active-in-current-buffer-p)
- (if (setq hywiki--range
- (hproperty:char-property-range (point) 'face hywiki-word-face))
- (let ((wikiword (buffer-substring-no-properties (car hywiki--range)
(cdr hywiki--range))))
- (if (string-match hywiki-word-with-optional-suffix-exact-regexp
wikiword)
- (if range-flag
- (list wikiword (car hywiki--range) (cdr hywiki--range))
- wikiword)
- (when range-flag
- '(nil nil nil)))))))
-
(defun hywiki-word-at (&optional range-flag)
"Return potential HyWikiWord and optional #section:Lnum:Cnum at point or nil.
`hywiki-mode' must be enabled or this will return nil.
@@ -3412,7 +3419,7 @@ Hyperbole button names."
(hproperty:but-add start end hywiki-word-face)))
(defun hywiki-highlight-word-get-range ()
- "Return list of potential (HyWikiWord#section:Lnum:Cnum start end).
+ "Return list of (HyWikiWord#section:Lnum:Cnum start end) around point.
Also highlight HyWikiWord as necessary.
If the HyWikiWord reference is delimited, point must be within the
@@ -3420,7 +3427,8 @@ delimiters. The delimiters are excluded from start and
end. If not
at a HyWikiWord, return \\='(nil nil nil).
This works regardless of whether the HyWikiWord has been highlighted
-or not.
+or not. Call `hywiki-highlighted-word-at' to test for a highlighted
+HyWikiWord at point.
This does not test whether a referent exists for the HyWikiWord; call
`hywiki-referent-exists-p' without an argument for that.
@@ -3491,7 +3499,8 @@ a HyWikiWord at point."
range))))))
(defun hywiki-word-face-at-p (&optional pos)
- "Non-nil if but at point or optional POS has `hywiki-word-face' property."
+ "Non-nil if point or optional POS has the `hywiki-word-face' property.
+Return any HyWikiWord reference found."
;; Sometimes this can return a left over button/overlay that points
;; to no buffer. Ignore this case.
(hproperty:but-get (or pos (point)) 'face hywiki-word-face))
@@ -3767,10 +3776,14 @@ delimiters."
FUNCTION must take four arguments: (buffer-start-pos buffer-end-pos
\\='face hywiki-word-face). Optional START and END are sent to the function as
the first two arguments; otherwise, the entire buffer is scanned."
- (funcall function
- (or start (point-min))
- (or end (point-max))
- 'face hywiki-word-face))
+ (let ((refs (funcall function
+ (or start (point-min))
+ (or end (point-max))
+ 'face hywiki-word-face)))
+ (if (version< emacs-version "29")
+ refs
+ ;; Button/overlay ordering is reversed after Emacs 28
+ (nreverse refs))))
(defun hywiki--get-delimited-range-backward ()
"Return a list of (start end) if not between/after end ]] or >>.
diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el
index ebe5864aa6..a06a391b45 100644
--- a/test/hywiki-tests.el
+++ b/test/hywiki-tests.el
@@ -3,7 +3,7 @@
;; Author: Mats Lidell
;;
;; Orig-Date: 18-May-24 at 23:59:48
-;; Last-Mod: 11-Jan-26 at 10:42:51 by Bob Weiner
+;; Last-Mod: 18-Jan-26 at 18:22:23 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -62,8 +62,7 @@
Last two elements are optional.")
(ert-deftest hywiki-tests--edit ()
- (let ((hywiki-directory (make-temp-file "hywiki" t))
- (test-num 0)
+ (let ((test-num 0)
before
after
name
@@ -73,11 +72,10 @@ Last two elements are optional.")
start
end
hywiki-ref-positions)
- (unwind-protect
- (with-temp-buffer
- (hywiki-tests--preserve-hywiki-mode
+ (hywiki-tests--preserve-hywiki-mode
+ (unwind-protect
+ (progn
(org-mode)
- (hywiki-mode :all)
(mapc
(lambda (before-after)
(condition-case err
@@ -90,23 +88,19 @@ Last two elements are optional.")
;; created so their references will be highlighted.
(mapc #'hywiki-add-page
(delq nil
- (mapcar #'hywiki-get-singular-wikiword
- (seq-remove #'string-empty-p
+ (mapcar #'hywiki-get-singular-wikiword
+ (seq-remove #'string-empty-p
(mapcar #'string-trim
(hywiki-tests--get-brace-strings after))))))
(unwind-protect
- (progn
+ (progn
(pop-to-buffer (current-buffer))
(erase-buffer)
(hywiki-tests--insert-by-char before)
(hywiki-tests--interpolate-buffer)
;; Markup before string in temp buffer
;; Surround any HyWikiWord refs with braces to match
after string.
- (setq hywiki-ref-positions
- (if (version< emacs-version "29")
- (hywiki-get-reference-positions)
- ;; Button/overlay ordering is reversed after
Emacs 28
- (nreverse (hywiki-get-reference-positions))))
+ (setq hywiki-ref-positions
(hywiki-get-reference-positions))
(dolist (start-end hywiki-ref-positions)
(setq start (car start-end)
end (cdr start-end))
@@ -139,13 +133,12 @@ Last two elements are optional.")
:before before :after
after))))
(cl-incf test-num))
(goto-char (point-min))))
- (error (error "%s ---- %S" err (list :markedup markedup-before
+ (error (error "%s ---- %S" err (list :markedup markedup-before
:test-num test-num
:before before :after
after)))))
- hywiki-tests--edit-string-pairs)))
- (dolist (f '("AI.org" "Hi.org" "HiHo.org" "HyWikiWord.org"
"MyWikiWord.org" "Non.org" "WikiWord.org"))
- (hy-delete-file-and-buffer (expand-file-name f hywiki-directory)))
- (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory))))
+ hywiki-tests--edit-string-pairs))
+ (dolist (f '("AI.org" "Hi.org" "HiHo.org" "HyWikiWord.org"
"MyWikiWord.org" "Non.org"))
+ (hy-delete-file-and-buffer (expand-file-name f
hywiki-directory)))))))
(defun hywiki-tests--get-brace-strings (s)
"Return the substrings in S delimited by curly braces {…}, excluding braces.
@@ -220,11 +213,12 @@ Assume no nesting of braces, nor any quoting of braces."
;; This creates the 'hbut:current in-memory ibut
(ibut:at-type-p 'action))
;; Force HyWikiWord highlighting
- (hywiki-tests--command-execute
- 'hbut:act 'hbut:current)))))
+ (hywiki-tests--command-execute 'hbut:act 'hbut:current)
+ ;; (hywiki-word-highlight-post-command)
+ ))))
(defun hywiki-tests--command-execute (sexp &rest rest)
- "Apply SEXP to REST of arguments as a command and return the result.
+ "Apply SEXP to REST of arguments as a HyWiki command and return the result.
Run pre and post command hooks around the call.
This is for simulating the command loop."
(let ((buf (current-buffer))
@@ -251,20 +245,29 @@ This is for simulating the command loop."
(defmacro hywiki-tests--preserve-hywiki-mode (&rest body)
"Restore hywiki-mode after running BODY."
(declare (indent 0) (debug t))
- `(let ((current-hywiki-mode hywiki-mode))
+ `(let* ((prior-hywiki-mode hywiki-mode)
+ (hywiki-directory (make-temp-file "hywiki" t))
+ (wiki-page (cdr (hywiki-add-page "WikiWord"))))
(unwind-protect
- (progn ,@body)
- (hywiki-mode (if current-hywiki-mode 1 0)))))
+ (save-window-excursion
+ (with-temp-buffer
+ (set-window-buffer (selected-window) (current-buffer))
+ (hywiki-mode :all)
+ (sit-for 0.01)
+ ,@body))
+ (hywiki-mode prior-hywiki-mode)
+ (hy-delete-file-and-buffer wiki-page)
+ (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--verify-preserve-hywiki-mode ()
"Verify `hywiki-tests--preserve-hywiki-mode' restores `hywiki-mode'."
(hywiki-tests--preserve-hywiki-mode
(hywiki-mode :all)
(hywiki-tests--preserve-hywiki-mode
- (should hywiki-mode)
+ (should (eq hywiki-mode :all))
(hywiki-mode nil)
(should-not hywiki-mode))
- (should hywiki-mode)))
+ (should (eq hywiki-mode :all))))
(ert-deftest hywiki-tests--hywiki-create-page--adds-file-in-wiki-folder ()
"Verify add page creates file in wiki folder and sets hash table."
@@ -753,24 +756,17 @@ Both mod-time and checksum must be changed for a test to
return true."
"Verify WikiWord for a wiki page gets face property hywiki-word-face."
(skip-unless (not noninteractive))
(hywiki-tests--preserve-hywiki-mode
- (let* ((hsys-org-enable-smart-keys t)
- (hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (cdr (hywiki-add-page "WikiWord"))))
- (unwind-protect
- (progn
- (hywiki-mode :all)
- (with-temp-buffer
- (insert "WikiWor")
- (hywiki-tests--command-execute #'self-insert-command 1 ?d)
- (goto-char 4)
- (should (hywiki-word-face-at-p)))
- (with-temp-buffer
- (insert "WikiWord")
- (hywiki-tests--command-execute #'newline 1 'interactive)
- (goto-char 4)
- (should (hywiki-word-face-at-p))))
- (hy-delete-file-and-buffer wikipage)
- (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory)))))
+ (let* ((hsys-org-enable-smart-keys t))
+ (insert "WikiWor")
+ (hywiki-tests--command-execute #'self-insert-command 1 ?d)
+ (goto-char 4)
+ (should (hywiki-word-face-at-p))
+
+ (erase-buffer)
+ (insert "WikiWord")
+ (hywiki-tests--command-execute #'newline 1 'interactive)
+ (goto-char 4)
+ (should (hywiki-word-face-at-p)))))
(ert-deftest hywiki-tests--no-face-property-for-no-wikipage ()
"Verify WikiWord for no wiki page does not get face property
hywiki-word-face."
@@ -792,53 +788,38 @@ Both mod-time and checksum must be changed for a test to
return true."
"Verify face property changes when WikiWord is edited."
(skip-unless (not noninteractive))
(hywiki-tests--preserve-hywiki-mode
- (let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (cdr (hywiki-add-page "WikiWord"))))
- (unwind-protect
- (with-temp-buffer
- (hywiki-mode :all)
- (insert "Wikiord ")
- (goto-char 5)
- (should (looking-at-p "ord "))
- (should-not (hywiki-word-face-at-p))
-
- (hywiki-tests--command-execute #'self-insert-command 1 ?W)
- (goto-char 5)
- (should (looking-at-p "Word "))
- (should (hywiki-word-face-at-p))
-
- (hywiki-tests--command-execute #'delete-char 1)
- (should (looking-at-p "ord "))
- (should-not (hywiki-word-face-at-p)))
- (hy-delete-files-and-buffers (list wikipage))
- (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory)))))
+ (insert "Wikiord ")
+ (goto-char 5)
+ (should (looking-at-p "ord "))
+ (should-not (hywiki-word-face-at-p))
+
+ (hywiki-tests--command-execute #'self-insert-command 1 ?W)
+ (goto-char 5)
+ (should (looking-at-p "Word "))
+ (should (hywiki-word-face-at-p))
+
+ (hywiki-tests--command-execute #'delete-char 1)
+ (should (looking-at-p "ord "))
+ (should-not (hywiki-word-face-at-p))))
(ert-deftest
hywiki-tests--verify-face-property-when-editing-wikiword-first-char ()
"Verify face property changes when WikiWord is edited in the first char
position."
(skip-unless (not noninteractive))
(hywiki-tests--preserve-hywiki-mode
- (let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (cdr (hywiki-add-page "WikiWord"))))
- (unwind-protect
- (progn
- (with-temp-buffer
- (hywiki-mode :all)
- (insert "WikiWord")
- (hywiki-tests--command-execute #'self-insert-command 1 ? )
- (goto-char 1)
- (should (looking-at-p "WikiWord"))
- (should (hywiki-word-face-at-p))
+ (insert "WikiWord")
+ (hywiki-tests--command-execute #'self-insert-command 1 ? )
+ (goto-char 1)
+ (should (looking-at-p "WikiWord"))
+ (should (hywiki-word-face-at-p))
- (hywiki-tests--command-execute #'delete-char 1)
- (should (looking-at-p "ikiWord"))
- (should-not (hywiki-word-face-at-p))
+ (hywiki-tests--command-execute #'delete-char 1)
+ (should (looking-at-p "ikiWord"))
+ (should-not (hywiki-word-face-at-p))
- (hywiki-tests--command-execute #'self-insert-command 1 ?W)
- (goto-char 1)
- (should (looking-at-p "WikiWord"))
- (should (hywiki-word-face-at-p))))
- (hy-delete-files-and-buffers (list wikipage))
- (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory)))))
+ (hywiki-tests--command-execute #'self-insert-command 1 ?W)
+ (goto-char 1)
+ (should (looking-at-p "WikiWord"))
+ (should (hywiki-word-face-at-p))))
(ert-deftest hywiki-tests--references-to-org-link ()
"Verify `hywiki-references-to-org-links' converts WikiWords to org links."
@@ -1019,22 +1000,22 @@ would return org7c18f23."
;; org-publish does not work properly to support HyWiki export prior
;; to version 9.7, so this will be skipped for Emacs 28 and 29.
(skip-unless (string-greaterp org-version "9.6.999"))
- (let* ((hywiki-directory (make-temp-file "hywiki_" t))
- org-publish-project-alist
- (hywiki-org-publishing-directory (make-temp-file "public_html_" t))
- (wikipage (cdr (hywiki-add-page "WikiPage")))
- (wikipage-html (expand-file-name "WikiPage.html"
hywiki-org-publishing-directory))
- (wikiword (cdr (hywiki-add-page "WikiWord")))
- (wikiword-html (expand-file-name "WikiWord.html"
hywiki-org-publishing-directory)))
- (unwind-protect
- (progn
- (hywiki-org-set-publish-project)
- (should (file-exists-p hywiki-directory))
- (should (file-exists-p wikipage))
- (should (file-exists-p wikiword))
+ (hywiki-tests--preserve-hywiki-mode
+ (let* (org-publish-project-alist
+ (hywiki-org-publishing-directory (make-temp-file "public_html_" t))
+ (wikipage (cdr (hywiki-add-page "WikiPage")))
+ (wikipage-html (expand-file-name "WikiPage.html"
hywiki-org-publishing-directory))
+ (wikiword (cdr (hywiki-add-page "WikiWord")))
+ (wikiword-html (expand-file-name "WikiWord.html"
hywiki-org-publishing-directory)))
+ (unwind-protect
+ (progn
+ (hywiki-org-set-publish-project)
+ (should (file-exists-p hywiki-directory))
+ (should (file-exists-p wikipage))
+ (should (file-exists-p wikiword))
- ;; Setup wiki pages for WikiWord and WikiPage.
- (with-current-buffer (find-file-noselect wikiword)
+ ;; Setup wiki pages for WikiWord and WikiPage.
+ (find-file wikiword)
(insert "\
First line
* Asection
@@ -1044,111 +1025,109 @@ body B
*** Csection-subsection
body C
")
- (save-buffer))
- (with-current-buffer (find-file-noselect wikipage)
+ (save-buffer)
+ (find-file wikipage)
(insert "\
WikiWord
WikiWord#Asection
\"WikiWord#Bsection subsection\"
WikiWord#Csection-subsection
")
- (save-buffer))
-
- ;; Export the wiki
- (hywiki-publish-to-html t)
-
- ;; Verify files and folder are generated
- (should (file-exists-p hywiki-org-publishing-directory))
- (should (file-exists-p wikipage-html))
- (should (file-exists-p wikiword-html))
-
- (let (idA idB idC)
- ;; Verify anchors are generated and fetch their ids
- (with-current-buffer (find-file-noselect wikiword-html)
- (setq idA (should (hywiki-tests--search-section "Asection")))
- (setq idB (should (hywiki-tests--search-section "Bsection
subsection")))
- (setq idC (should (hywiki-tests--search-section
"Csection-subsection"))))
-
- ;; Verify links are generated
- (with-current-buffer (find-file-noselect wikipage-html)
- ;; (First check we even get the wikipage with sections)
- (should (<= 1 (count-matches (regexp-quote "WikiWord") (point-min)
(point-max))))
- (should (= 1 (count-matches (regexp-quote "WikiWord#Asection")
(point-min) (point-max))))
- (should (= 1 (count-matches (regexp-quote "WikiWord#Bsection
subsection") (point-min) (point-max))))
- (should (= 1 (count-matches (regexp-quote
"WikiWord#Csection-subsection") (point-min) (point-max))))
-
- ;; Then verify the href links are generated
- (should (= 1 (count-matches (regexp-quote "<a
href=\"WikiWord.html\">WikiWord</a>") (point-min) (point-max))))
- (should (= 1 (count-matches
- (format "<a
href=\"WikiWord.html#%s\">WikiWord#Asection</a>" idA) (point-min) (point-max))))
- (should (= 1 (count-matches
- (format "<a
href=\"WikiWord.html#%s\">WikiWord#Bsection subsection</a>" idB) (point-min)
(point-max))))
- (should (= 1 (count-matches
- (format "<a
href=\"WikiWord.html#%s\">WikiWord#Csection-subsection</a>" idC) (point-min)
(point-max)))))))
- (hy-delete-files-and-buffers (list wikipage wikiword wikipage-html
wikiword-html
- (expand-file-name "index.org"
hywiki-directory)
- (expand-file-name "index.html"
hywiki-org-publishing-directory)))
- (hy-delete-dir-and-buffer hywiki-org-publishing-directory)
- (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory))))
+ (save-buffer)
+
+ ;; Export the wiki
+ (hywiki-publish-to-html t)
+
+ ;; Verify files and folder are generated
+ (should (file-exists-p hywiki-org-publishing-directory))
+ (should (file-exists-p wikipage-html))
+ (should (file-exists-p wikiword-html))
+
+ (let (idA idB idC)
+ ;; Verify anchors are generated and fetch their ids
+ (with-current-buffer (find-file-noselect wikiword-html)
+ (setq idA (should (hywiki-tests--search-section "Asection")))
+ (setq idB (should (hywiki-tests--search-section "Bsection
subsection")))
+ (setq idC (should (hywiki-tests--search-section
"Csection-subsection"))))
+
+ ;; Verify links are generated
+ (find-file wikipage-html)
+ ;; (First check we even get the wikipage with sections)
+ (should (<= 1 (count-matches (regexp-quote "WikiWord")
(point-min) (point-max))))
+ (should (= 1 (count-matches (regexp-quote "WikiWord#Asection")
(point-min) (point-max))))
+ (should (= 1 (count-matches (regexp-quote "WikiWord#Bsection
subsection") (point-min) (point-max))))
+ (should (= 1 (count-matches (regexp-quote
"WikiWord#Csection-subsection") (point-min) (point-max))))
+
+ ;; Then verify the href links are generated
+ (should (= 1 (count-matches (regexp-quote "<a
href=\"WikiWord.html\">WikiWord</a>") (point-min) (point-max))))
+ (should (= 1 (count-matches
+ (format "<a
href=\"WikiWord.html#%s\">WikiWord#Asection</a>" idA) (point-min) (point-max))))
+ (should (= 1 (count-matches
+ (format "<a
href=\"WikiWord.html#%s\">WikiWord#Bsection subsection</a>" idB) (point-min)
(point-max))))
+ (should (= 1 (count-matches
+ (format "<a
href=\"WikiWord.html#%s\">WikiWord#Csection-subsection</a>" idC) (point-min)
(point-max))))))
+ (hy-delete-files-and-buffers (list wikipage wikiword wikipage-html
wikiword-html
+ (expand-file-name "index.org"
hywiki-directory)
+ (expand-file-name "index.html"
hywiki-org-publishing-directory)))
+ (hy-delete-dir-and-buffer hywiki-org-publishing-directory)))))
(ert-deftest hywiki-tests--publish-special-cases ()
"Verify different special cases."
;; org-publish does not work properly to support HyWiki export prior
;; to version 9.7, so this will be skipped for Emacs 28 and 29.
(skip-unless (string-greaterp org-version "9.6.999"))
- (let* ((hywiki-directory (make-temp-file "hywiki_" t))
- org-publish-project-alist
- (hywiki-org-publishing-directory (make-temp-file "public_html_" t))
- (wikipage (cdr (hywiki-add-page "WikiPage")))
- (wikipage-html (expand-file-name "WikiPage.html"
hywiki-org-publishing-directory))
- (wikiword (cdr (hywiki-add-page "WikiWord")))
- (wikiword-html (expand-file-name "WikiWord.html"
hywiki-org-publishing-directory))
- (href "<a href=\"WikiWord.html\">WikiWord</a>"))
- (unwind-protect
- (progn
- (hywiki-org-set-publish-project)
+ (hywiki-tests--preserve-hywiki-mode
+ (let* (org-publish-project-alist
+ (hywiki-org-publishing-directory (make-temp-file "public_html_" t))
+ (wikipage (cdr (hywiki-add-page "WikiPage")))
+ (wikipage-html (expand-file-name "WikiPage.html"
hywiki-org-publishing-directory))
+ (wikiword (cdr (hywiki-add-page "WikiWord")))
+ (wikiword-html (expand-file-name "WikiWord.html"
hywiki-org-publishing-directory))
+ (href "<a href=\"WikiWord.html\">WikiWord</a>"))
+ (unwind-protect
+ (progn
+ (hywiki-org-set-publish-project)
- (with-current-buffer (find-file-noselect wikiword)
+ (find-file wikiword)
(erase-buffer)
(insert "Text\n")
- (save-buffer))
-
- (should (file-exists-p hywiki-directory))
- (should (file-exists-p wikipage))
- (should (file-exists-p wikiword))
-
- (dolist (v `(("WikiWord WikiWord" . ,(format "%s %s" href href))
- ("\"WikiWord WikiWord\"" . ,(format "\"%s%s\"" href
href))
- ;; ^ Missing a
space!?
- ("WikiWord Text WikiWord" . ,(format "%s Text %s" href
href))
- ("\"WikiWord Text WikiWord\"" . ,(format "\"%s%s\""
href href))
- ;; ^ Missing
" Text "
- ("WikiWord WikiWord WikiWord" . ,(format "%s %s %s"
href href href))
- ;; (cons "\"WikiWord WikiWord WikiWord\"" (format "\"%s
%s %s\"" href href href))
- ;; ^ Crashes due to (wrong-type-argument
integer-or-marker-p nil) caused by buffer-substring-no-properties(nil nil)
- ))
- (let ((input (car v))
- (regex-output (cdr v)))
- ;; Setup WikiPage.
- (with-current-buffer (find-file-noselect wikipage)
+ (save-buffer)
+
+ (should (file-exists-p hywiki-directory))
+ (should (file-exists-p wikipage))
+ (should (file-exists-p wikiword))
+
+ (dolist (v `(("WikiWord WikiWord" . ,(format "%s %s" href href))
+ ("\"WikiWord WikiWord\"" . ,(format "\"%s%s\"" href
href))
+ ;; ^ Missing a
space!?
+ ("WikiWord Text WikiWord" . ,(format "%s Text %s" href
href))
+ ("\"WikiWord Text WikiWord\"" . ,(format "\"%s%s\""
href href))
+ ;; ^
Missing " Text "
+ ("WikiWord WikiWord WikiWord" . ,(format "%s %s %s"
href href href))
+ ;; (cons "\"WikiWord WikiWord WikiWord\"" (format
"\"%s %s %s\"" href href href))
+ ;; ^ Crashes due to (wrong-type-argument
integer-or-marker-p nil) caused by buffer-substring-no-properties(nil nil)
+ ))
+ (let ((input (car v))
+ (regex-output (cdr v)))
+ ;; Setup WikiPage.
+ (find-file wikipage)
(erase-buffer)
(insert input)
- (save-buffer))
+ (save-buffer)
- ;; Export the wiki
- (hywiki-publish-to-html t)
+ ;; Export the wiki
+ (hywiki-publish-to-html t)
- ;; Verify Export
- (ert-info ((format "Publish '%s' => Expect '%s'" input
regex-output))
- (with-current-buffer (find-file-noselect wikipage-html t)
+ ;; Verify Export
+ (ert-info ((format "Publish '%s' => Expect '%s'" input
regex-output))
+ (find-file wikipage-html t)
(revert-buffer t t)
- (should (= 1 (count-matches regex-output (point-min)
(point-max)))))))))
- ;; Unwind
- (hy-delete-files-and-buffers (list wikipage wikiword wikipage-html
wikiword-html
- (expand-file-name "index.org"
hywiki-directory)
- (expand-file-name "index.html"
hywiki-org-publishing-directory)))
- (hy-delete-dir-and-buffer hywiki-org-publishing-directory)
- (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory))))
+ (should (= 1 (count-matches regex-output (point-min)
(point-max))))))))
+ ;; Unwind
+ (hy-delete-files-and-buffers (list wikipage wikiword wikipage-html
wikiword-html
+ (expand-file-name "index.org"
hywiki-directory)
+ (expand-file-name "index.html"
hywiki-org-publishing-directory)))
+ (hy-delete-dir-and-buffer hywiki-org-publishing-directory)))))
(ert-deftest hywiki-tests--get-singular-wikiword ()
"Verify plural WikiWord is converted to singular.
@@ -1342,7 +1321,7 @@ Note special meaning of `hywiki-allow-plurals-flag'."
(hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory))))
(defmacro hywiki-tests--referent-test (expected-referent &rest prepare)
- "Template macro for generated a non-page HyWikiWord referent.
+ "Template macro for generating a non-page HyWikiWord referent.
EXPECTED-REFERENT is the result expected from `hywiki-get-referent'.
The template runs the PREPARE body, and that must add the HyWikiWord
named WikiReferent with a non-page referent type."
@@ -1613,24 +1592,18 @@ See gh#rswgnu/hyperbole/669."
"Verify `hywiki-word-face-at-p'."
(skip-unless (not noninteractive))
(hywiki-tests--preserve-hywiki-mode
- (let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wiki-page (cdr (hywiki-add-page "WikiWord"))))
- (with-temp-buffer
- (hywiki-mode nil)
- (insert "WikiWor")
- (hywiki-tests--command-execute #'self-insert-command 1 ?d)
- (goto-char 4)
- (should-not (hywiki-word-face-at-p)))
- (unwind-protect
- (progn
- (with-temp-buffer
- (hywiki-mode :all)
- (insert "WikiWor")
- (hywiki-tests--command-execute #'self-insert-command 1 ?d)
- (goto-char 4)
- (should (hywiki-word-face-at-p))))
- (hy-delete-file-and-buffer wiki-page)
- (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory)))))
+ (hywiki-mode nil)
+ (insert "WikiWor")
+ (hywiki-tests--command-execute #'self-insert-command 1 ?d)
+ (goto-char 4)
+ (should-not (hywiki-word-face-at-p))
+
+ (erase-buffer)
+ (hywiki-mode :all)
+ (insert "WikiWor")
+ (hywiki-tests--command-execute #'self-insert-command 1 ?d)
+ (goto-char 4)
+ (should (hywiki-word-face-at-p))))
(defun hywiki-tests--hywiki-face-regions ()
"Return (start . end) for all hywiki--word-face overlays in buffer.
@@ -1646,38 +1619,18 @@ comparison with expected overlays stable."
(and (= (car x) (car y))
(< (cdr x) (cdr y))))))))
-(defun hywiki-tests--hywiki-face-region-at (&optional pos)
- "Get the start and end of the hywiki--word-face overlay at POS or point.
-Return nil if not at a `hywiki--word-face' overlay."
- (let ((overlays (overlays-at (or pos (point))))
- result)
- (when overlays
- (dolist (overlay overlays result)
- (when (equal (overlay-get overlay 'face) 'hywiki--word-face)
- (cl-assert (not result) "There can only be one overlay with
`hywiki--word-face'")
- (setq result (cons (overlay-start overlay) (overlay-end
overlay))))))))
-
-(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-highlight-word-get-range)
- (when word
- (when (hy-test-word-face-at-region beg end)
- (should (equal (hywiki-tests--hywiki-face-region-at beg) (cons beg
end)))
- word))))
-
(defvar hywiki-tests--with-face-test t
"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-highlighted-word-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
+If EXPECTED is a string, also verify that the wikiword matches the
string."
(if (not expected)
(should-not (hywiki-tests--word-at))
@@ -1776,20 +1729,16 @@ Perform each operation from the step check and verify
whether there
is a WikiWord at point or not."
(skip-unless (not noninteractive))
(hywiki-tests--preserve-hywiki-mode
- (let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wikiHiHo (cdr (hywiki-add-page "HiHo")))
+ (let* ((wikiHiHo (cdr (hywiki-add-page "HiHo")))
(wikiHiho (cdr (hywiki-add-page "Hiho")))
(wikiHi (cdr (hywiki-add-page "Hi")))
(wikiHo (cdr (hywiki-add-page "Ho")))
(wiki-page-list (list wikiHiHo wikiHiho wikiHi wikiHo)))
(unwind-protect
- (progn
- (hywiki-mode :all)
- (dolist (testcase hywiki-tests--wikiword-step-check)
- (with-temp-buffer
- (hywiki-tests--run-test-case testcase))))
- (hy-delete-files-and-buffers wiki-page-list)
- (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory)))))
+ (dolist (testcase hywiki-tests--wikiword-step-check)
+ (erase-buffer)
+ (hywiki-tests--run-test-case testcase))
+ (hy-delete-files-and-buffers wiki-page-list)))))
(defconst hywiki-tests--lorem-ipsum "\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
@@ -1834,26 +1783,18 @@ Insert test in the middle of other text."
A WikiWord is completed, then last char is deleted and reinserted. The
face is verified during the change."
(hywiki-tests--preserve-hywiki-mode
- (let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wiki-page (cdr (hywiki-add-page "WikiWord"))))
- (unwind-protect
- (progn
- (hywiki-mode :all)
- (with-temp-buffer
- (emacs-lisp-mode)
- (insert "\
+ (emacs-lisp-mode)
+ (insert "\
(defun func ()
\"WikiWor)
")
- ;; Set point after WikiWor
- (goto-char 1)
- (should (search-forward "WikiWor"))
+ ;; Set point after WikiWor
+ (goto-char 1)
+ (should (search-forward "WikiWor"))
- ;; Complete WikiWord and verify highlighting
- (hywiki-tests--run-test-case
- '(("d\"" . "WikiWord") (p2 . t) (-1) ("d" . "WikiWord")))))
- (hy-delete-file-and-buffer wiki-page)
- (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory)))))
+ ;; Complete WikiWord and verify highlighting
+ (hywiki-tests--run-test-case
+ '(("d" . "WikiWord") ("\"" . "WikiWord") (p2 . t) (-1) ("d" .
"WikiWord")))))
(ert-deftest hywiki-tests--wikiword-identified-in-emacs-lisp-mode ()
"Verify WikiWord is identified when surrounded by delimiters in
`emacs-lisp-mode'."
diff --git a/test/hywiki-yki-tests.el b/test/hywiki-yki-tests.el
index 4257a58257..4beff36960 100644
--- a/test/hywiki-yki-tests.el
+++ b/test/hywiki-yki-tests.el
@@ -3,7 +3,7 @@
;; Author: Mats Lidell
;;
;; Orig-Date: 13-Jul-25 at 19:50:37
-;; Last-Mod: 11-Jan-26 at 10:35:55 by Bob Weiner
+;; Last-Mod: 18-Jan-26 at 08:45:21 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -132,8 +132,8 @@ buffer.
End the insertion of text by turning on hywiki-mode and perform a dummy
command to get the pre- and post-hooks executed. This creates the
highlighting overlays we want to test."
+ (hywiki-mode :all)
(erase-buffer)
- (hywiki-mode 1)
(goto-char (hywiki-test--insert-with-point description)))
(defun hywiki-test--get-buffer-text-with-point-and-highlight ()