summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLeon Rische <leon.rische@me.com>2020-05-04 13:56:00 +0200
committerLeon Rische <leon.rische@me.com>2020-05-04 13:56:00 +0200
commitb2afbb0356880b37f0bb0c80351c6a7b91dd2248 (patch)
treecd6e2dba2e0f57dfc3311247b2b989415a9e2300 /tests
parente8303241918970b680701bc645b9b37af3634249 (diff)
Add indexer & filter tests
Diffstat (limited to 'tests')
-rw-r--r--tests/filter/a.org23
-rw-r--r--tests/filter/b.org25
-rw-r--r--tests/filter/c.org29
-rw-r--r--tests/org-fc-filter-test.el74
-rw-r--r--tests/org-fc-indexer-test.el15
-rw-r--r--tests/org-fc-test-helper.el13
6 files changed, 179 insertions, 0 deletions
diff --git a/tests/filter/a.org b/tests/filter/a.org
new file mode 100644
index 0000000..5bf724d
--- /dev/null
+++ b/tests/filter/a.org
@@ -0,0 +1,23 @@
+* Normal :fc:tag1:
+:PROPERTIES:
+:FC_CREATED: 2020-05-03T15:56:55Z
+:FC_TYPE: normal
+:ID: 9c5e1c79-e0a0-4cf9-9ddd-a2556da0d755
+:END:
+:REVIEW_DATA:
+| position | ease | box | interval | due |
+|----------+------+-----+----------+----------------------|
+| front | 2.5 | 0 | 0 | 2020-05-03T15:56:55Z |
+:END:
+* Double :fc:tag1:tag2:
+:PROPERTIES:
+:FC_CREATED: 2020-05-03T15:57:00Z
+:FC_TYPE: double
+:ID: dc8340e2-8725-40b7-8e88-4c7fec938fc0
+:END:
+:REVIEW_DATA:
+| position | ease | box | interval | due |
+|----------+------+-----+----------+----------------------|
+| front | 2.5 | 0 | 0 | 2020-05-03T15:57:00Z |
+| back | 2.5 | 0 | 0 | 2020-05-03T15:57:00Z |
+:END:
diff --git a/tests/filter/b.org b/tests/filter/b.org
new file mode 100644
index 0000000..8103177
--- /dev/null
+++ b/tests/filter/b.org
@@ -0,0 +1,25 @@
+* Heading 1 :tag2:
+** Heading 2
+*** Normal1 :fc:
+:PROPERTIES:
+:FC_CREATED: 2020-05-03T16:07:38Z
+:FC_TYPE: normal
+:ID: b5686029-f41a-4ff8-a8ed-2629d2f47b81
+:END:
+:REVIEW_DATA:
+| position | ease | box | interval | due |
+|----------+------+-----+----------+----------------------|
+| front | 2.5 | 0 | 0 | 2020-05-03T16:07:38Z |
+:END:
+* Heading 3
+** Normal2 :fc:
+:PROPERTIES:
+:FC_CREATED: 2020-05-03T16:08:00Z
+:FC_TYPE: normal
+:ID: 3abe7213-33fd-4b90-8a8b-e323682e19ee
+:END:
+:REVIEW_DATA:
+| position | ease | box | interval | due |
+|----------+------+-----+----------+----------------------|
+| front | 2.5 | 0 | 0 | 2020-05-03T16:08:00Z |
+:END:
diff --git a/tests/filter/c.org b/tests/filter/c.org
new file mode 100644
index 0000000..472b52e
--- /dev/null
+++ b/tests/filter/c.org
@@ -0,0 +1,29 @@
+#+FILETAGS: :file1:file2:
+#+FILETAGS: :file3:
+
+* Double :fc:
+:PROPERTIES:
+:FC_CREATED: 2020-05-03T16:14:52Z
+:FC_TYPE: double
+:ID: d96b7d6a-c719-4696-aafc-da88b23e1dcb
+:END:
+:REVIEW_DATA:
+| position | ease | box | interval | due |
+|----------+------+-----+----------+----------------------|
+| front | 2.5 | 0 | 0 | 2020-05-03T16:14:52Z |
+| back | 2.5 | 0 | 0 | 2020-05-03T16:14:52Z |
+:END:
+* Cloze :fc:
+:PROPERTIES:
+:FC_CREATED: 2020-05-03T16:15:05Z
+:FC_TYPE: cloze
+:ID: 54625832-2d72-46f6-8f26-862eba4e4651
+:FC_CLOZE_MAX: 0
+:FC_CLOZE_TYPE: deletion
+:END:
+:REVIEW_DATA:
+| position | ease | box | interval | due |
+|----------+------+-----+----------+----------------------|
+| 0 | 2.5 | 0 | 0 | 2020-05-03T16:15:05Z |
+:END:
+{{hole}@0}
diff --git a/tests/org-fc-filter-test.el b/tests/org-fc-filter-test.el
new file mode 100644
index 0000000..a62639b
--- /dev/null
+++ b/tests/org-fc-filter-test.el
@@ -0,0 +1,74 @@
+(require 'org-fc)
+(require 'org-fc-test-helper)
+(require 'ert)
+
+(defvar
+ org-fc-filter-test-ids
+ '((a-normal . "9c5e1c79-e0a0-4cf9-9ddd-a2556da0d755")
+ (a-double . "dc8340e2-8725-40b7-8e88-4c7fec938fc0")
+ (b-normal1 . "b5686029-f41a-4ff8-a8ed-2629d2f47b81")
+ (b-normal2 . "3abe7213-33fd-4b90-8a8b-e323682e19ee")
+ (c-double . "d96b7d6a-c719-4696-aafc-da88b23e1dcb")
+ (c-cloze . "54625832-2d72-46f6-8f26-862eba4e4651")))
+
+(defun org-fc-test-compare-ids (index expected)
+ (let ((ids1 (mapcar (lambda (card) (plist-get card :id)) index))
+ (ids2
+ (mapcar
+ (lambda (ex) (alist-get ex org-fc-filter-test-ids))
+ expected)))
+ (equal (sort ids1 #'string-lessp)
+ (sort ids2 #'string-lessp))))
+
+(ert-deftest org-fc-filter-test ()
+ (let* ((index (org-fc-awk-index-paths (list (org-fc-test-fixture "filter/")))))
+ (org-fc-test-index-ids index)
+ ;; Index of all cards
+ (should (org-fc-test-compare-ids
+ index
+ '(a-normal a-double b-normal1 b-normal2 c-double c-cloze)))
+
+ ;; Filter by type
+ (should
+ (org-fc-test-compare-ids
+ (org-fc-filter-index index '(type double))
+ '(a-double c-double)))
+
+ ;; Filter by type, or
+ (should
+ (org-fc-test-compare-ids
+ (org-fc-filter-index index '(or (type cloze) (type double)))
+ '(a-double c-double c-cloze)))
+
+ ;; Filter by tag, direct
+ (should
+ (org-fc-test-compare-ids
+ (org-fc-filter-index index '(tag "tag1"))
+ '(a-normal a-double)))
+
+ ;; Filter by tag, inherited
+ (should
+ (org-fc-test-compare-ids
+ (org-fc-filter-index index '(tag "tag2"))
+ '(a-double b-normal1)))
+
+ ;; Filter by tag, filetag
+ (should
+ (org-fc-test-compare-ids
+ (org-fc-filter-index index '(and (tag "file1")
+ (tag "file2")
+ (tag "file3")))
+ '(c-double c-cloze)))
+
+ ;; Negation
+ (should
+ (org-fc-test-compare-ids
+ (org-fc-filter-index index '(not (type normal)))
+ '(a-double c-double c-cloze)))
+
+ ;; Combined
+ (should
+ (org-fc-test-compare-ids
+ (org-fc-filter-index index '(and (not (type normal))
+ (tag "file1")))
+ '(c-double c-cloze)))))
diff --git a/tests/org-fc-indexer-test.el b/tests/org-fc-indexer-test.el
new file mode 100644
index 0000000..2200fa0
--- /dev/null
+++ b/tests/org-fc-indexer-test.el
@@ -0,0 +1,15 @@
+(require 'org-fc)
+(require 'org-fc-test-helper)
+(require 'ert)
+
+(ert-deftest org-fc-test-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"))))))
diff --git a/tests/org-fc-test-helper.el b/tests/org-fc-test-helper.el
new file mode 100644
index 0000000..ea94198
--- /dev/null
+++ b/tests/org-fc-test-helper.el
@@ -0,0 +1,13 @@
+(defun org-fc-test-fixture (name)
+ "Return the full path of fixture file NAME."
+ (expand-file-name
+ name
+ (expand-file-name "tests/" org-fc-source-path)))
+
+(defun org-fc-test-index-ids (index)
+ "Return a list of IDs in INDEX."
+ (mapcar
+ (lambda (card) (plist-get card :id))
+ index))
+
+(provide 'org-fc-test-helper)