Skip to content

Commit

Permalink
Return hasht when rebuilding from load data (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
matsl authored Feb 8, 2025
1 parent e81710d commit 3558ba5
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2025-02-07 Mats Lidell <[email protected]>

* test/hywiki-tests.el (hywiki-tests--save-referent)
(hywiki-tests--save-referent-use-hyperbole-menu): Tests for using the
cached page and referent data.

* hywiki.el (hywiki-make-referent-hasht): Return hasht when rebuilding from
load data.

2025-02-05 Mats Lidell <[email protected]>

* hywiki.el (hywiki-add-org-id): Suppress byte compile warnings for calling org-id-get with
Expand Down
8 changes: 4 additions & 4 deletions hywiki.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 21-Acpr-24 at 22:41:13
;; Last-Mod: 5-Feb-25 at 22:21:38 by Mats Lidell
;; Last-Mod: 6-Feb-25 at 23:35:41 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -2455,10 +2455,10 @@ save and potentially set `hywiki--directory-mod-time' and
(progn (eval (read (buffer-string)))
t)
(error nil)))))))
(if (and hywiki-loaded-flag (not (hywiki-directory-modified-p)))
(if (and hywiki-loaded-flag (not (hywiki-directory-modified-p)))
;; Rebuild from loaded data
(setq hywiki--referent-hasht (hash-make hywiki--referent-alist t)
hywiki--referent-alist nil)
(prog1 (setq hywiki--referent-hasht (hash-make hywiki--referent-alist t))
(setq hywiki--referent-alist nil))
;; Read `hywiki-directory' for current page files and merge with
;; non-page referents
(let* ((page-files (hywiki-get-page-files))
Expand Down
60 changes: 59 additions & 1 deletion 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-Jan-25 at 18:22:58 by Bob Weiner
;; Last-Mod: 7-Feb-25 at 10:01:25 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -922,5 +922,63 @@ Note special meaning of `hywiki-allow-plurals-flag'."
;; (hywiki-get-referent wikiword))))
;; (hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--save-referent ()
"Verify saving and loading a referent works."
(let* ((hywiki-directory (make-temp-file "hywiki" t))
(wiki-page (cdr (hywiki-add-page "WikiPage" )))
(wiki-referent "WikiReferent"))
(unwind-protect
(progn
(find-file wiki-page)
(insert wiki-referent)
(goto-char 4)
(with-simulated-input "ABC RET"
(hywiki-add-key-series wiki-referent))
(should (equal '(key-series . "{ABC}") (hywiki-get-referent wiki-referent)))
(should (string= wiki-referent (buffer-string)))
(should (file-exists-p (hywiki-cache-default-file)))

;; Simulate reload from cache
(setq hywiki--referent-hasht nil)
(hywiki-make-referent-hasht)
(should (equal '(key-series . "{ABC}") (hywiki-get-referent wiki-referent))))
(hy-delete-files-and-buffers (list wiki-page (hywiki-cache-default-file)))
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--save-referent-use-hyperbole-menu ()
"Verify saving and loading a referent works when using Hyperbole's menu."
:expected-result :failed
;; The entered key series is inserted into the WikiWord file. See
;; comment below.
(skip-unless (not noninteractive))
(let* ((hywiki-directory (make-temp-file "hywiki" t))
(wiki-page (cdr (hywiki-add-page "WikiPage" )))
(wiki-referent "WikiReferent"))
(unwind-protect
(progn
(find-file wiki-page)
(insert wiki-referent)
(goto-char 4)

(should (hact 'kbd-key "C-u C-h hhck{ABC} RET"))
(hy-test-helpers:consume-input-events)

;; The buffer contents is changed and now reads
;; "Wik{ABC}iReferent" as the next should verifies. The
;; second should is the expected behavior. No change in the
;; WikiPage buffer.
(should (string= "Wik{ABC}iReferent" (buffer-substring-no-properties (point-min) (point-max))))
(should (string= wiki-referent (buffer-substring-no-properties (point-min) (point-max))))

(should (file-exists-p (hywiki-cache-default-file)))
(should (equal '(key-series . "{ABC}") (hywiki-get-referent wiki-referent)))

;; Simulate reload from cache
(setq hywiki--referent-hasht nil)
(hywiki-make-referent-hasht)
(should (equal '(key-series . "{ABC}") (hywiki-get-referent wiki-referent))))
(hy-delete-files-and-buffers (list wiki-page (hywiki-cache-default-file)))
(hy-delete-dir-and-buffer hywiki-directory))))

(provide 'hywiki-tests)
;;; hywiki-tests.el ends here

0 comments on commit 3558ba5

Please sign in to comment.