forked from atheriel/org-clock-csv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
org-clock-csv-tests.el
88 lines (73 loc) · 3.33 KB
/
org-clock-csv-tests.el
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
;; -*- lexical-binding: t -*-
(require 'org-clock-csv)
;;; Helper Code:
(defun org-clock-csv-should-match (input output)
"Test that clock entries in INPUT match the .csv OUTPUT file."
(let* ((in (with-current-buffer (org-clock-csv input 'no-switch)
(buffer-string)))
(out (with-temp-buffer
(insert-file-contents output)
(buffer-string))))
(should (equal in out))))
(defvar org-clock-csv-header-all-props
"task,headline,parents,category,start,end,duration,effort,ishabit,tags,title")
(defun org-clock-csv-all-props-row-fmt (plist)
"Formatting function including all properties."
(mapconcat #'identity
(list (org-clock-csv--escape (plist-get plist ':task))
(org-clock-csv--escape
(org-element-property :raw-value (plist-get plist ':headline)))
(org-clock-csv--escape
(s-join org-clock-csv-headline-separator
(plist-get plist ':parents)))
(org-clock-csv--escape (plist-get plist ':category))
(plist-get plist ':start)
(plist-get plist ':end)
(plist-get plist ':duration)
(plist-get plist ':effort)
(plist-get plist ':ishabit)
(plist-get plist ':tags)
(plist-get plist ':title))
","))
;;; Tests:
(ert-deftest test-sample ()
"Docs."
(org-clock-csv-should-match "tests/sample.org" "tests/sample.csv"))
(ert-deftest test-all-props ()
"Test all available properties."
(let ((org-clock-csv-header org-clock-csv-header-all-props)
(org-clock-csv-row-fmt #'org-clock-csv-all-props-row-fmt))
(org-clock-csv-should-match "tests/sample.org" "tests/all-props.csv")))
(ert-deftest test-issue-2 ()
"Test tasks with commas in them, as in issue #2."
(org-clock-csv-should-match "tests/issue-2.org" "tests/issue-2.csv"))
(ert-deftest test-issue-3 ()
"Test tasks with headline ancestors, as in issue #3."
(org-clock-csv-should-match "tests/issue-3.org" "tests/issue-3.csv"))
(ert-deftest test-issue-5 ()
"Test file level category."
(org-clock-csv-should-match "tests/issue-5.org" "tests/issue-5.csv"))
(ert-deftest test-issue-26 ()
"Test file without title."
(let ((org-clock-csv-header org-clock-csv-header-all-props)
(org-clock-csv-row-fmt #'org-clock-csv-all-props-row-fmt))
(org-clock-csv-should-match "tests/issue-26.org" "tests/issue-26.csv")))
(ert-deftest test-issue-23 ()
"Test custom properties."
(let ((org-clock-csv-header "task,CUSTOM_1,CUSTOM_2,start,end")
(org-clock-csv-row-fmt
(lambda (plist)
(mapconcat #'identity
(list (org-clock-csv--escape (plist-get plist ':task))
(org-clock-csv--escape
(org-clock-csv--read-property plist "CUSTOM_1" "defaultvalue"))
(org-clock-csv--escape
(org-clock-csv--read-property plist "CUSTOM_2"))
(plist-get plist ':start)
(plist-get plist ':end))
","))))
(org-clock-csv-should-match "tests/issue-23.org" "tests/issue-23.csv")))
;; Local Variables:
;; coding: utf-8
;; End:
;;; org-clock-csv-tests.el ends here