Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify creation of pages and movement to pages #635

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@
* test/hypb-tests.el (hypb--verify-info-index-is-correct): Ensure info
index is correct.

2024-12-29 Mats Lidell <[email protected]>

* test/hywiki-tests.el
(hywiki-tests--action-key-on-hy-wikiword-displays-page): Rename so
hy:WikiWord is mentioned. Fix removal of temp files.
(hywiki-tests--assist-key-on-hy-wikiword-displays-help): Rename so
hy:WikiWord is mentioned and refactor to verify help buffer is shown.
(hywiki-tests--action-key-on-wikiword-displays-page)
(hywiki-tests--action-key-on-wikiword-and-section-displays-page): New
tests for verifying display of pages with and without sections.
(hywiki-tests--wikiword-identified-with-delimiters): Add test for
WikiWord with a single hash mark.

2024-12-28 Bob Weiner <[email protected]>

* hywiki.el (hywiki-convert-words-to-org-links): Error if called within a
Expand Down
78 changes: 69 additions & 9 deletions test/hywiki-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell
;;
;; Orig-Date: 18-May-24 at 23:59:48
;; Last-Mod: 28-Dec-24 at 16:58:48 by Mats Lidell
;; Last-Mod: 28-Dec-24 at 22:14:33 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -53,7 +53,7 @@
(should-not (cdr (hywiki-add-page "notawikiword")))
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--action-key-on-wikiword-displays-page ()
(ert-deftest hywiki-tests--action-key-on-hy-wikiword-displays-page ()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a dash, just use 'hywikiword' instead of 'hy-wikiword'.

"Verify `action-key' on a prefixed WikiWord, outside of hywiki-directory, creates a new page."
(let ((hsys-org-enable-smart-keys t)
(hywiki-directory (make-temp-file "hywiki" t))
Expand All @@ -65,21 +65,72 @@
(goto-char 4)
(action-key)
(should (equal (cons 'page wikifile) (hywiki-get-referent "WikiWord"))))
(hy-delete-file-and-buffer wikifile))))
(hy-delete-file-and-buffer (expand-file-name wikifile hywiki-directory))
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--assist-key-on-wikiword-displays-help ()
(ert-deftest hywiki-tests--assist-key-on-hy-wikiword-displays-help ()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as prior comment.

"Verify `assist-key' on a prefixed WikiWord, outside of hywiki-directory, displays help for the WikiWord link."
(let ((hsys-org-enable-smart-keys t)
(hywiki-directory (make-temp-file "hywiki" t))
(wikifile (make-temp-file "wikifile" nil ".org")))
(hywiki-directory (make-temp-file "hywiki" t)))
(unwind-protect
(with-temp-buffer
(hywiki-mode 1)
(insert "[[hy:WikiWord]]")
(goto-char 4)
(goto-char 6)
(should (string= "WikiWord" (hywiki-word-at)))
(assist-key))
(hy-delete-file-and-buffer wikifile))))
(delete-other-windows)
(assist-key)
(other-window 1)
(should (string-prefix-p "*Help: Hyperbole " (buffer-name))))
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--action-key-on-wikiword-displays-page ()
"Verify `action-key' on a WikiWord, outside of hywiki-directory, creates a new page."
(let* ((hsys-org-enable-smart-keys t)
(hywiki-directory (make-temp-file "hywiki" t))
(hywiki-page-file (expand-file-name "WikiWord.org" hywiki-directory)))
(unwind-protect
(dolist (v '(nil t)) ;; Verify the file exists the second time
(if v
(should (file-exists-p hywiki-page-file))
(should-not (file-exists-p hywiki-page-file)))
(with-temp-buffer
(hywiki-mode 1)
(insert "WikiWord\n")
(goto-char 4)
(action-key)
(should (string= hywiki-page-file (buffer-file-name)))
(should (equal (cons 'page (file-name-nondirectory hywiki-page-file))
(hywiki-get-referent "WikiWord")))
(if v
(should (looking-at-p "WikiWord page"))
(insert "WikiWord page")
(goto-char (point-min)))))
(hy-delete-file-and-buffer hywiki-page-file)
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--action-key-on-wikiword-and-section-displays-page ()
"Verify `action-key' on a WikiWord with section moves to the section."
(let* ((hsys-org-enable-smart-keys t)
(hywiki-directory (make-temp-file "hywiki" t))
(hywiki-page-file (expand-file-name "WikiWord.org" hywiki-directory))
(sections '("* Header" "** SubHeader" "*** SubSubHeader")))
matsl marked this conversation as resolved.
Show resolved Hide resolved
(unwind-protect
(progn
(find-file hywiki-page-file)
(dolist (v sections)
(insert (format "%s\nbody\n" v)))
(save-buffer)
(hywiki-mode 1)
(dolist (v sections)
(with-temp-buffer
(insert "WikiWord#" (cadr (split-string v " ")))
(goto-char 4)
(action-key)
(should (string= hywiki-page-file (buffer-file-name)))
(should (looking-at-p (regexp-quote v))))))
(hy-delete-file-and-buffer hywiki-page-file)
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--not-a-wikiword-unless-in-hywiki-mode ()
"Verify WikiWord is not a WikiWord unless in `hywiki-mode'."
Expand Down Expand Up @@ -132,6 +183,15 @@
(goto-char 6)
(should (string= "WikiWord" (hywiki-word-at)))))

;; Does not match as a WikiWord
(dolist (v '("WikiWord#"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An Action Key press on a WikiWord with just a trailing # should probably either go to the first Org doc section or trigger an error. What do you prefer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An Action Key press on a WikiWord with just a trailing # should probably either go to the first Org doc section or trigger an error. What do you prefer?

I think it currently raises an error. (Hyperbole Action Key): No action defined for this context; try another location That is OK. Maybe just handle it as WikiWord would cause less questions from a user but will think about it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more on this I think WikiWord# should be treated just like WikiWord#non-existing-section.

Currently we just move to the WikiWord-page if the section does not exists, There is an error message that the section can't be found. With an empty section we should do something similar. We could even strip of the hash mark and treat it as a normal WikiWord.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a wikiword that links to a page will display an existing buffer page with point wherever it was before the button was activated. We need a way to say, display the beginning or first section of the page, so this is as good a way as any.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed my thought on this. With my next update, you'll be able to add :L1 at the end of a HyWikiWord referent to go to the first line of a wiki page, so if a # is given without a section name, it the HyWikiWord reference will just be ignored for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I will updated these tests when that change goes in.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That update has been made, so you can finish this PR.

(with-temp-buffer
(org-mode)
(insert v)
(newline nil t)
(goto-char 6)
(should-not (string= "WikiWord" (hywiki-word-at)))))

;; Identifies as org link (Note: Not checked if target
;; exists.) AND matches WikiWord
(dolist (v '("[[hy:WikiWord]]" "[[hy:WikiWord\\]]]"))
Expand Down
Loading