Skip to content

Commit

Permalink
Verify creation of pages and movement to pages
Browse files Browse the repository at this point in the history
  • Loading branch information
matsl committed Dec 29, 2024
1 parent 2a25322 commit 1083ddf
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 9 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
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: 26-Dec-24 at 23:34:51 by Bob Weiner
;; 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 ()
"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 ()
"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")))
(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#"))
(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

0 comments on commit 1083ddf

Please sign in to comment.