Skip to content

Commit

Permalink
Test cache indexing function
Browse files Browse the repository at this point in the history
  • Loading branch information
l3kn committed Mar 16, 2024
1 parent 0ee02d7 commit c78aa99
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions tests/org-fc-indexer-test.el
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
(require 'org-fc)
(require 'org-fc-cache)
(require 'org-fc-test-helper)
(require 'ert)

(ert-deftest org-fc-test-index-malformed ()
(let ((files
(mapcar
#'org-fc-test-fixture
'("malformed/no_review_data.org"
"malformed/no_properties.org"
"malformed/normal_swapped_drawers.org"
"malformed/unclosed_drawer1.org"
"malformed/unclosed_drawer2.org"))))
(dolist (file files)
(org-fc-test-check-structure '()
(org-fc-awk-index (list file))))))

(ert-deftest org-fc-test-escaping ()
(org-fc-test-check-structure
'((:cards ((:id "33645f3a-384d-44ed-aed2-a2d56b973800"))))
(org-fc-awk-index
(list (org-fc-test-fixture "escaping/spaces in filename.org")))))

(ert-deftest org-fc-test-index-keywords ()
(org-fc-test-check-structure
'((:title "File Title Uppercase"
:cards ((:tags ("tag1" "tag2" "fc"))))
(:title "File Title Lowercase"
:cards ((:tags ("tag3" "tag4" "fc")))))
(org-fc-awk-index
(list (org-fc-test-fixture "index/uppercase.org")
(org-fc-test-fixture "index/lowercase.org")))))

(ert-deftest org-fc-test-index ()
(let ((algo-sm2 (org-fc-algo-sm2))
(algo-noop (org-fc-algo-noop)))
(org-fc-test-check-structure
`((:cards
(setq
org-fc-test-index-expectations
(let ((algo-sm2 (org-fc-algo-sm2))
(algo-noop (org-fc-algo-noop)))
`((("malformed/no_review_data.org") . ())
(("malformed/no_properties.org") . ())
(("malformed/normal_swapped_drawers.org") . ())
(("malformed/unclosed_drawer1.org") . ())
(("malformed/unclosed_drawer2.org") . ())
(("escaping/spaces in filename.org")
.
((:cards ((:id "33645f3a-384d-44ed-aed2-a2d56b973800")))))
(("index/uppercase.org" "index/lowercase.org")
.
((:title "File Title Uppercase"
:cards ((:tags ("tag1" "tag2" "fc"))))
(:title "File Title Lowercase"
:cards ((:tags ("tag3" "tag4" "fc"))))))
(("index/test.org")
.
((:cards
((:id "edee8940-5c9a-4c70-b1c4-f45c194c0c97"
:tags ("fc" "tag1")
:title "Headline"
Expand All @@ -47,5 +35,24 @@
(:id "a7ed2686-73e6-4780-825d-78cf4b2e5374"
:tags ("fc" "tag3")
:title "Headline 3:not_a_tag:"
:algo ,algo-noop))))
(org-fc-awk-index (list (org-fc-test-fixture "index/test.org"))))))
:algo ,algo-noop))))))))

(ert-deftest org-fc-test-awk-index ()
(dolist (expectation org-fc-test-index-expectations)
(let ((files
(mapcar #'org-fc-test-fixture (car expectation))))
(org-fc-test-check-structure
(cdr expectation)
(org-fc-awk-index files)))))

(ert-deftest org-fc-test-cache-index ()
(dolist (expectation org-fc-test-index-expectations)
(let* ((files
(mapcar #'org-fc-test-fixture (car expectation)))
(org-fc-directories files)
(org-fc-test-cache org-fc-cache))
(setq org-fc-cache (make-hash-table :test #'equal))
(org-fc-test-check-structure
(cdr expectation)
(org-fc-cache-index files))
(setq org-fc-cache org-fc-test-cache))))

0 comments on commit c78aa99

Please sign in to comment.