summaryrefslogtreecommitdiff
path: root/tests/org-fc-test-helper.el
blob: 789f8471a265cd02409711fcb81b4f4907c1c608 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(require 'cl)

(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))

(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)