summaryrefslogtreecommitdiff
path: root/tests/test-chime-timestamp-parse.el
blob: c97806b24f4a12cf87218ab4d38cdf05c9a8bd50 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
;;; test-chime-timestamp-parse.el --- Tests for chime--timestamp-parse -*- lexical-binding: t; -*-

;; Copyright (C) 2024 Craig Jennings

;; Author: Craig Jennings <c@cjennings.net>

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Unit tests for chime--timestamp-parse function.
;; Tests cover normal cases, boundary cases, and error cases.

;;; Code:

;; Initialize package system for batch mode
(when noninteractive
  (package-initialize))

(require 'ert)

;; Load dependencies required by chime
(require 'dash)
(require 'alert)
(require 'async)
(require 'org-agenda)

;; Load chime from parent directory
(load (expand-file-name "../chime.el") nil t)

;; Load test utilities
(require 'testutil-general (expand-file-name "testutil-general.el"))

;;; Setup and Teardown

(defun test-chime-timestamp-parse-setup ()
  "Setup function run before each test."
  (chime-create-test-base-dir))

(defun test-chime-timestamp-parse-teardown ()
  "Teardown function run after each test."
  (chime-delete-test-base-dir))

;;; Normal Cases

(ert-deftest test-chime-timestamp-parse-standard-timestamp-returns-time-list ()
  "Test that a standard timestamp with time component returns a time list."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 14:30>")
             (result (chime--timestamp-parse timestamp)))
        ;; Should return a time list (list of integers)
        (should (listp result))
        (should (= (length result) 2))
        (should (integerp (car result)))
        (should (integerp (cadr result)))
        ;; Result should not be nil
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-scheduled-timestamp-returns-time-list ()
  "Test that a SCHEDULED timestamp parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 09:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-deadline-timestamp-returns-time-list ()
  "Test that a DEADLINE timestamp parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 17:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-timestamp-with-weekly-repeater-returns-time-list ()
  "Test that a timestamp with +1w repeater parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 14:00 +1w>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-timestamp-with-completion-repeater-returns-time-list ()
  "Test that a timestamp with .+1d repeater parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 08:00 .+1d>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-timestamp-with-catchup-repeater-returns-time-list ()
  "Test that a timestamp with ++1w repeater parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 10:30 ++1w>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-timestamp-with-time-range-returns-start-time ()
  "Test that a timestamp with time range returns the start time."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 14:00-15:30>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-timestamp-with-date-range-returns-start-date ()
  "Test that a timestamp with date range returns start date time."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 10:00>--<2025-10-25 Sat 10:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

;;; Boundary Cases

(ert-deftest test-chime-timestamp-parse-midnight-timestamp-returns-time-list ()
  "Test that midnight (00:00) timestamp parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 00:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-last-minute-of-day-returns-time-list ()
  "Test that last minute of day (23:59) timestamp parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 23:59>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-year-boundary-new-years-eve-returns-time-list ()
  "Test that New Year's Eve timestamp parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-12-31 Wed 23:30>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-year-boundary-new-years-day-returns-time-list ()
  "Test that New Year's Day timestamp parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2026-01-01 Thu 00:30>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-single-digit-time-returns-time-list ()
  "Test that single-digit hours and minutes parse correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 01:05>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-leap-year-feb-29-returns-time-list ()
  "Test that Feb 29 in leap year parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2024-02-29 Thu 14:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-month-boundary-end-of-month-returns-time-list ()
  "Test that end of month timestamp parses correctly."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-31 Fri 14:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (listp result))
        (should (= (length result) 2))
        (should result))
    (test-chime-timestamp-parse-teardown)))

;;; Error Cases

(ert-deftest test-chime-timestamp-parse-empty-string-returns-nil ()
  "Test that empty string returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "")
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-nil-input-returns-nil ()
  "Test that nil input returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp nil)
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-missing-opening-bracket-returns-nil ()
  "Test that timestamp missing opening bracket returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "2025-10-24 Fri 14:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-missing-closing-bracket-returns-nil ()
  "Test that timestamp missing closing bracket returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 14:00")
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-invalid-date-format-returns-nil ()
  "Test that invalid date format returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<10-24-2025 Fri 14:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-invalid-month-returns-nil ()
  "Test that invalid month value returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-13-24 Fri 14:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-invalid-day-returns-nil ()
  "Test that invalid day value returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-32 Fri 14:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-invalid-time-hour-returns-nil ()
  "Test that invalid hour value returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 25:00>")
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-invalid-time-minute-returns-nil ()
  "Test that invalid minute value returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri 14:60>")
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(ert-deftest test-chime-timestamp-parse-date-only-no-time-returns-nil ()
  "Test that day-wide timestamp without time returns nil."
  (test-chime-timestamp-parse-setup)
  (unwind-protect
      (let* ((timestamp "<2025-10-24 Fri>")
             (result (chime--timestamp-parse timestamp)))
        (should (null result)))
    (test-chime-timestamp-parse-teardown)))

(provide 'test-chime-timestamp-parse)
;;; test-chime-timestamp-parse.el ends here