(tests): test org-roam--build-cache-async (#92)
This commit is contained in:
parent
159b64b538
commit
9ae03532da
6 changed files with 77 additions and 3 deletions
7
tests/roam-files/f1.org
Normal file
7
tests/roam-files/f1.org
Normal file
|
@ -0,0 +1,7 @@
|
|||
#+TITLE: File 1
|
||||
|
||||
link to [[file:nested/f1.org][Nested File 1]]
|
||||
link to [[file:f2.org][File 2]]
|
||||
|
||||
Arbitrary [[https://google.com][HTML]] link
|
||||
Arbitrary text
|
3
tests/roam-files/f2.org
Normal file
3
tests/roam-files/f2.org
Normal file
|
@ -0,0 +1,3 @@
|
|||
#+TITLE: File 2
|
||||
|
||||
This file has no links.
|
4
tests/roam-files/nested/f1.org
Normal file
4
tests/roam-files/nested/f1.org
Normal file
|
@ -0,0 +1,4 @@
|
|||
#+TITLE: Nested File 1
|
||||
|
||||
Link to [[file:f2.org][Nested File 2]]
|
||||
Link to [[file:../f1.org][File 1]]
|
3
tests/roam-files/nested/f2.org
Normal file
3
tests/roam-files/nested/f2.org
Normal file
|
@ -0,0 +1,3 @@
|
|||
#+TITLE: Nested File 2
|
||||
|
||||
Link to [[file:f1.org][Nested File 1]]
|
1
tests/roam-files/no-title.org
Normal file
1
tests/roam-files/no-title.org
Normal file
|
@ -0,0 +1 @@
|
|||
no title in this file :O
|
|
@ -29,7 +29,63 @@
|
|||
(require 'buttercup)
|
||||
(require 'org-roam)
|
||||
|
||||
(defun abs-path (file-path)
|
||||
(file-truename (expand-file-name file-path org-roam-directory)))
|
||||
|
||||
;;; Tests
|
||||
(describe "Org-roam cache"
|
||||
(it "Mock Test"
|
||||
(expect t :to-be t)))
|
||||
(describe "org-roam"
|
||||
(before-all
|
||||
(setq org-roam-directory (file-truename (concat default-directory "tests/roam-files"))))
|
||||
|
||||
(it "org-roam--build-cache-async"
|
||||
(expect org-roam-cache-initialized :to-be nil)
|
||||
(expect (hash-table-count org-roam-forward-links-cache) :to-be 0)
|
||||
(expect (hash-table-count org-roam-backward-links-cache) :to-be 0)
|
||||
(expect (hash-table-count org-roam-titles-cache) :to-be 0)
|
||||
|
||||
(org-roam--build-cache-async)
|
||||
(sleep-for 3) ;; Because it's async
|
||||
|
||||
;; Caches should be populated
|
||||
(expect org-roam-cache-initialized :to-be t)
|
||||
(expect (hash-table-count org-roam-forward-links-cache) :to-be 3)
|
||||
(expect (hash-table-count org-roam-backward-links-cache) :to-be 4)
|
||||
(expect (hash-table-count org-roam-titles-cache) :to-be 4)
|
||||
|
||||
;; Forward cache
|
||||
(let ((f1 (gethash (abs-path "f1.org") org-roam-forward-links-cache))
|
||||
(f2 (gethash (abs-path "f2.org") org-roam-forward-links-cache))
|
||||
(nested-f1 (gethash (abs-path "nested/f1.org") org-roam-forward-links-cache))
|
||||
(nested-f2 (gethash (abs-path "nested/f2.org") org-roam-forward-links-cache))
|
||||
(expected-f1 (list (abs-path "nested/f1.org")
|
||||
(abs-path "f2.org")))
|
||||
(expected-nested-f1 (list (abs-path "nested/f2.org")
|
||||
(abs-path "f1.org")))
|
||||
(expected-nested-f2 (list (abs-path "nested/f1.org"))))
|
||||
|
||||
(expect f1 :to-have-same-items-as expected-f1)
|
||||
(expect f2 :to-be nil)
|
||||
(expect nested-f1 :to-have-same-items-as expected-nested-f1)
|
||||
(expect nested-f2 :to-have-same-items-as expected-nested-f2))
|
||||
|
||||
;; Backward cache
|
||||
(let ((f1 (hash-table-keys (gethash (abs-path "f1.org") org-roam-backward-links-cache)))
|
||||
(f2 (hash-table-keys (gethash (abs-path "f2.org") org-roam-backward-links-cache)))
|
||||
(nested-f1 (hash-table-keys(gethash (abs-path "nested/f1.org") org-roam-backward-links-cache)))
|
||||
(nested-f2 (hash-table-keys (gethash (abs-path "nested/f2.org") org-roam-backward-links-cache)))
|
||||
(expected-f1 (list (abs-path "nested/f1.org")))
|
||||
(expected-f2 (list (abs-path "f1.org")))
|
||||
(expected-nested-f1 (list (abs-path "nested/f2.org")
|
||||
(abs-path "f1.org")))
|
||||
(expected-nested-f2 (list (abs-path "nested/f1.org"))))
|
||||
(expect f1 :to-have-same-items-as expected-f1)
|
||||
(expect f2 :to-have-same-items-as expected-f2)
|
||||
(expect nested-f1 :to-have-same-items-as expected-nested-f1)
|
||||
(expect nested-f2 :to-have-same-items-as expected-nested-f2))
|
||||
|
||||
;; Titles Cache
|
||||
(expect (gethash (abs-path "f1.org") org-roam-titles-cache) :to-equal "File 1")
|
||||
(expect (gethash (abs-path "f2.org") org-roam-titles-cache) :to-equal "File 2")
|
||||
(expect (gethash (abs-path "nested/f1.org") org-roam-titles-cache) :to-equal "Nested File 1")
|
||||
(expect (gethash (abs-path "nested/f2.org") org-roam-titles-cache) :to-equal "Nested File 2")
|
||||
(expect (gethash (abs-path "no-title.org") org-roam-titles-cache) :to-be nil)))
|
||||
|
|
Loading…
Reference in a new issue