Skip to content

Commit

Permalink
Refactor tests to use with-simulated-input
Browse files Browse the repository at this point in the history
  • Loading branch information
matsl committed Dec 28, 2024
1 parent fa82d43 commit da52254
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 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 16:05:44 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -677,21 +677,26 @@ Note special meaning of `hywiki-allow-plurals-flag'."

(ert-deftest hywiki-tests--add-bookmark ()
"Verify `hywiki-add-bookmark'."
(let ((hywiki-directory (make-temp-file "hywiki" t)))
(let ((hywiki-directory (make-temp-file "hywiki" t))
(bookmark-alist nil)
(file (make-temp-file "hypb.txt")))
(unwind-protect
(progn
(mocklet ((bookmark-completing-read => ""))
(find-file file)
(with-simulated-input "RET"
(should-error (hywiki-add-bookmark "WikiWord")))
(mocklet ((bookmark-completing-read => "bkmark"))
(should (equal '(bookmark . "bkmark") (hywiki-add-bookmark "WikiWord")))))
(should (bookmark-set "bookmark"))
(with-simulated-input "bookmark RET"
(should (equal '(bookmark . "bookmark") (hywiki-add-bookmark "WikiWord")))))
(hy-delete-file-and-buffer file)
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--add-command ()
"Verify `hywiki-add-command'."
(let ((hywiki-directory (make-temp-file "hywiki" t))
(wikiword "WikiWord"))
(unwind-protect
(mocklet ((hui:actype => 'hpath:find))
(with-simulated-input "hpath:find RET"
(hywiki-add-command wikiword)
(should (equal '(command . hpath:find)
(hywiki-get-referent wikiword))))
Expand Down Expand Up @@ -725,22 +730,19 @@ Note special meaning of `hywiki-allow-plurals-flag'."
"Verify `hywiki-add-info-index'."
(let ((hywiki-directory (make-temp-file "hywiki" t)))
(unwind-protect
(mocklet (((info) => t)
((Info-read-index-item-name "Info index item: ") => "index-name")
((Info-current-filename-sans-extension) => "info"))
(with-simulated-input "Top RET"
(info "emacs")
(hywiki-add-info-index "WikiWord")
(should (equal '(info-index . "(info)index-name") (hywiki-get-referent "WikiWord"))))
(should (equal '(info-index . "(emacs)Top") (hywiki-get-referent "WikiWord"))))
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--add-info-node ()
"Verify `hywiki-add-info-node'."
(let ((hywiki-directory (make-temp-file "hywiki" t)))
(unwind-protect
(mocklet (((info) => t)
((Info-read-node-name "Info node: ") => "node-name")
((Info-current-filename-sans-extension) => "info"))
(with-simulated-input "(emacs) RET"
(hywiki-add-info-node "WikiWord")
(should (equal '(info-node . "(info)node-name") (hywiki-get-referent "WikiWord"))))
(should (equal '(info-node . "(emacs)") (hywiki-get-referent "WikiWord"))))
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--add-key-series ()
Expand Down

0 comments on commit da52254

Please sign in to comment.