Skip to content

Commit

Permalink
Merge pull request #635 from rswgnu/verify-creation-of-and-movement-t…
Browse files Browse the repository at this point in the history
…o-pages

Verify creation of pages and movement to pages
  • Loading branch information
rswgnu authored Jan 19, 2025
2 parents 31d77e4 + f656f52 commit cbbf963
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 8 deletions.
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@
(hywiki-mode): Improve doc.
(hywiki-display-info-node): Use 'link-to-Info-node' action type.

2025-01-12 Mats Lidell <[email protected]>

* test/hywiki-tests.el
(hywiki-tests--action-key-on-hywikiword-displays-page): Rename so
hy:WikiWord is mentioned. Fix removal of temp files.
(hywiki-tests--assist-key-on-hywikiword-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.
(hywiki-tests--action-key-on-wikiword-and-line-column-displays-page):
Test line and column specifiers with WikiWords.

2025-01-09 Mats Lidell <[email protected]>

* test/MANIFEST: Add hycontrol-tests.el
Expand Down
107 changes: 99 additions & 8 deletions test/hywiki-tests.el
Original file line number Diff line number Diff line change
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-hywikiword-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,103 @@
(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-hywikiword-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."
:expected-result :failed
(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))))))
(hywiki-mode 0)
(hy-delete-file-and-buffer hywiki-page-file)
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--action-key-on-wikiword-and-line-column-displays-page ()
"Verify `action-key' on a WikiWord with line and column specifications goes to expected point."
:expected-result :failed
(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
(progn
(find-file hywiki-page-file)
(insert "\
line 1
line 2
")
(save-buffer)
(hywiki-mode 1)
(dolist (l '(1 2))
(dolist (c '("" ":C0" ":C5"))
(with-temp-buffer
(insert (format "WikiWord:L%s%s" l c))
(goto-char 4)
(action-key)
(should (string= hywiki-page-file (buffer-file-name)))
(if (string= c ":C5")
(should (looking-at-p (regexp-quote (format "%s$" l))))
(should (looking-at-p (regexp-quote (format "line %s$" l)))))))))
(hywiki-mode 0)
(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 +214,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 cbbf963

Please sign in to comment.