diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/index/lowercase.org | 4 | ||||
-rw-r--r-- | tests/index/uppercase.org | 2 | ||||
-rw-r--r-- | tests/org-fc-indexer-test.el | 98 | ||||
-rw-r--r-- | tests/org-fc-test-helper.el | 26 |
4 files changed, 63 insertions, 67 deletions
diff --git a/tests/index/lowercase.org b/tests/index/lowercase.org index 991455f..a52ebb1 100644 --- a/tests/index/lowercase.org +++ b/tests/index/lowercase.org @@ -1,5 +1,5 @@ -#+title: File Title -#+filetags: :tag1:tag2: +#+title: File Title Lowercase +#+filetags: :tag3:tag4: * Card :fc: :PROPERTIES: diff --git a/tests/index/uppercase.org b/tests/index/uppercase.org index 693e1f0..043e3df 100644 --- a/tests/index/uppercase.org +++ b/tests/index/uppercase.org @@ -1,4 +1,4 @@ -#+TITLE: File Title +#+TITLE: File Title Uppercase #+FILETAGS: :tag1:tag2: * Card :fc: diff --git a/tests/org-fc-indexer-test.el b/tests/org-fc-indexer-test.el index ae75735..760372e 100644 --- a/tests/org-fc-indexer-test.el +++ b/tests/org-fc-indexer-test.el @@ -3,73 +3,43 @@ (require 'ert) (ert-deftest org-fc-test-index-malformed () - (should (null (org-fc-awk-index-paths - (list (org-fc-test-fixture "malformed/no_review_data.org"))))) - (should (null (org-fc-awk-index-paths - (list (org-fc-test-fixture "malformed/no_properties.org"))))) - (should (null (org-fc-awk-index-paths - (list (org-fc-test-fixture "malformed/normal_swapped_drawers.org"))))) - (should (null (org-fc-awk-index-paths - (list (org-fc-test-fixture "malformed/unclosed_drawer1.org"))))) - (should (null (org-fc-awk-index-paths - (list (org-fc-test-fixture "malformed/unclosed_drawer2.org")))))) + (let ((files + '("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 + '((:cards ())) + (org-fc-awk-index-paths (list (org-fc-test-fixture file))))))) (ert-deftest org-fc-test-escaping () - (let ((index (org-fc-awk-index-paths - (list (org-fc-test-fixture "escaping/spaces in filename.org"))))) - (should (eq (length index) 1)) - (should - (equal (plist-get (car index) :id) - "33645f3a-384d-44ed-aed2-a2d56b973800")))) + (org-fc-test-check-structure + '((:cards ((:id "33645f3a-384d-44ed-aed2-a2d56b973800")))) + (org-fc-awk-index-paths + (list (org-fc-test-fixture "escaping/spaces in filename.org"))))) (ert-deftest org-fc-test-index-keywords () - (let ((index (org-fc-awk-index-paths - (list (org-fc-test-fixture "index/uppercase.org"))))) - (should (eq (length index) 1)) - (let ((card (car index))) - (should (equal (plist-get card :inherited-tags) ":tag1:tag2:")) - (should (equal (plist-get card :filetitle) "File Title")))) - (let ((index (org-fc-awk-index-paths - (list (org-fc-test-fixture "index/lowercase.org"))))) - (should (eq (length index) 1)) - (let ((card (car index))) - (should (equal (plist-get card :inherited-tags) ":tag1:tag2:")) - (should (equal (plist-get card :filetitle) "File Title"))))) + (org-fc-test-check-structure + '((:title "File Title Uppercase" + :cards ((:inherited-tags ":tag1:tag2:"))) + (:title "File Title Lowercase" + :cards ((:inherited-tags ":tag3:tag4:")))) + (org-fc-awk-index-paths + (list (org-fc-test-fixture "index/uppercase.org") + (org-fc-test-fixture "index/lowercase.org"))))) (ert-deftest org-fc-test-index () - (let ((index (org-fc-awk-index-paths - (list - (org-fc-test-fixture "index/test.org"))))) - (should (eq (length index) 3)) - (let ((card1 (car index)) - (card2 (cadr index)) - (card3 (caddr index))) - (should - (equal (plist-get card1 :id) - "edee8940-5c9a-4c70-b1c4-f45c194c0c97")) - (should - (equal (plist-get card1 :local-tags) - ":fc:tag1:")) - (should - (equal (plist-get card1 :title) - "Headline")) - - (should - (equal (plist-get card2 :id) - "59b3b102-aebd-44ba-a1fd-6dc912c34fcf")) - (should - (equal (plist-get card2 :local-tags) - ":fc:tag2:")) - (should - (equal (plist-get card2 :title) - "Headline 2")) - - (should - (equal (plist-get card3 :id) - "a7ed2686-73e6-4780-825d-78cf4b2e5374")) - (should - (equal (plist-get card3 :local-tags) - ":fc:tag3:")) - (should - (equal (plist-get card3 :title) - "Headline 3:not_a_tag:"))))) + (org-fc-test-check-structure + '((:cards + ((:id "edee8940-5c9a-4c70-b1c4-f45c194c0c97" + :local-tags ":fc:tag1:" + :title "Headline") + (:id "59b3b102-aebd-44ba-a1fd-6dc912c34fcf" + :local-tags ":fc:tag2:" + :title "Headline 2") + (:id "a7ed2686-73e6-4780-825d-78cf4b2e5374" + :local-tags ":fc:tag3:" + :title "Headline 3:not_a_tag:")))) + (org-fc-awk-index (list (org-fc-test-fixture "index/test.org"))))) diff --git a/tests/org-fc-test-helper.el b/tests/org-fc-test-helper.el index ea94198..789f847 100644 --- a/tests/org-fc-test-helper.el +++ b/tests/org-fc-test-helper.el @@ -1,3 +1,5 @@ +(require 'cl) + (defun org-fc-test-fixture (name) "Return the full path of fixture file NAME." (expand-file-name @@ -10,4 +12,28 @@ (lambda (card) (plist-get card :id)) index)) +(defun org-fc-test-check-structure (expected got) + "Check structural equality of parts of larger objects. +For plists, values of all keys in EXPECTED are compared, +lists are compared element-by-element, +everything else is checked for equality." + (cond + ;; plist + ((and (listp expected) + expected + (symbolp (car expected))) + (let ((keys + (cl-loop for key in expected by #'cddr collecting key))) + (dolist (key keys) + (org-fc-test-check-structure + (plist-get expected key) + (plist-get got key))))) + ;; Normal list + ((listp expected) + (should (eq (length expected) (length got))) + (cl-loop for e in expected for g in got do + (org-fc-test-check-structure e g))) + ;; Anything else + (t (should (equal expected got))))) + (provide 'org-fc-test-helper) |