blob: c7f16834351114d93ff7335cd4b33397cd618d22 (
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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
;;; test-daily-prep-agenda.el --- ERT tests for daily-prep-agenda -*- lexical-binding: t; -*-
;; Run: emacs --batch -q -L .ai/scripts -l ert -l test-daily-prep-agenda.el \
;; -f ert-run-tests-batch-and-exit
(require 'ert)
(require 'cl-lib)
(require 'daily-prep-agenda)
;;; dp-iso-date --------------------------------------------------------------
(ert-deftest dp-iso-date-extracts-from-active-timestamp ()
(should (equal (dp-iso-date "<2026-04-25 Sat 16:00>") "2026-04-25")))
(ert-deftest dp-iso-date-extracts-from-inactive-timestamp ()
(should (equal (dp-iso-date "[2026-05-29 Fri]") "2026-05-29")))
(ert-deftest dp-iso-date-no-date-returns-nil ()
(should (null (dp-iso-date "no date in here"))))
(ert-deftest dp-iso-date-nil-input-returns-nil ()
(should (null (dp-iso-date nil))))
;;; dp-bucket --------------------------------------------------------------
;; dp-today / dp-week-end are dynamic; pin them so bucketing is deterministic.
(defmacro dp-test--with-clock (&rest body)
`(let ((dp-today "2026-05-15")
(dp-week-end "2026-05-22"))
,@body))
(ert-deftest dp-bucket-deadline-before-today-is-overdue ()
(dp-test--with-clock
(should (eq (dp-bucket '(:deadline "2026-05-10")) 'overdue))))
(ert-deftest dp-bucket-deadline-today-is-today ()
(dp-test--with-clock
(should (eq (dp-bucket '(:deadline "2026-05-15")) 'today))))
(ert-deftest dp-bucket-scheduled-today-is-today ()
(dp-test--with-clock
(should (eq (dp-bucket '(:scheduled "2026-05-15")) 'today))))
(ert-deftest dp-bucket-scheduled-before-today-is-overdue ()
(dp-test--with-clock
(should (eq (dp-bucket '(:scheduled "2026-05-12")) 'overdue))))
(ert-deftest dp-bucket-deadline-within-week-is-this-week ()
(dp-test--with-clock
(should (eq (dp-bucket '(:deadline "2026-05-20")) 'this-week))))
(ert-deftest dp-bucket-priority-a-undated-is-pri-a ()
(dp-test--with-clock
(should (eq (dp-bucket '(:priority ?A)) 'pri-a))))
(ert-deftest dp-bucket-priority-b-undated-is-pri-b ()
(dp-test--with-clock
(should (eq (dp-bucket '(:priority ?B)) 'pri-b))))
(ert-deftest dp-bucket-no-date-no-priority-is-other ()
(dp-test--with-clock
(should (eq (dp-bucket '(:heading "x")) 'other))))
;;; dp-format-entry --------------------------------------------------------
(ert-deftest dp-format-entry-renders-heading-loc-deadline-body ()
(let ((out (dp-format-entry
'(:state "TODO" :priority ?A :heading "Ship it"
:file "/x/todo.org" :line 42
:deadline-raw "<2026-05-20 Wed>" :scheduled-raw nil
:body "do the thing"))))
(should (string-match-p "\\*\\* TODO \\[#A\\] Ship it" out))
(should (string-match-p ":LOC: todo.org:42" out))
(should (string-match-p "DEADLINE: <2026-05-20 Wed>" out))
(should (string-match-p " do the thing" out))))
(ert-deftest dp-format-entry-omits-priority-cookie-when-absent ()
(let ((out (dp-format-entry
'(:state "TODO" :heading "No priority" :file "f.org" :line 1))))
(should (string-match-p "\\*\\* TODO No priority" out))
(should-not (string-match-p "\\[#" out))))
;;; dp-collect (exercises dp-active-candidate-p + dp-entry-info) ------------
(ert-deftest dp-collect-picks-active-priority-and-dated-entries ()
(let ((tmp (make-temp-file
"dp-test" nil ".org"
(concat
"* TODO [#A] urgent thing\n"
"* TODO [#C] low prio no date\n"
"* TODO scheduled thing\n"
"SCHEDULED: <2026-05-20 Wed>\n"
"* DONE [#A] finished\n"))))
(unwind-protect
(let ((headings (mapcar (lambda (e) (plist-get e :heading))
(dp-collect (list tmp)))))
;; [#A]-active and the SCHEDULED entry qualify;
;; the undated [#C] and the DONE entry do not.
(should (member "urgent thing" headings))
(should (member "scheduled thing" headings))
(should-not (member "low prio no date" headings))
(should-not (member "finished" headings)))
(delete-file tmp))))
(provide 'test-daily-prep-agenda)
;;; test-daily-prep-agenda.el ends here
|