aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime-has-timestamp.el
blob: 6accb68e72c76ed84e097560643b762b7bda1d49 (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
;;; test-chime-has-timestamp.el --- Tests for chime--has-timestamp -*- lexical-binding: t; -*-

;; Copyright (C) 2024-2026 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--has-timestamp 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"))
(require 'testutil-time (expand-file-name "testutil-time.el"))

;;; Setup and Teardown

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

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

;;; Normal Cases

(ert-deftest test-chime-has-timestamp-standard-timestamp-with-time-returns-non-nil ()
  "Test that standard timestamp with time returns non-nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 14 30))
             (timestamp (test-timestamp-string time))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-timestamp-without-brackets-returns-non-nil ()
  "Test that timestamp without brackets but with time returns non-nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 14 30))
             (timestamp (format-time-string "%Y-%m-%d %a %H:%M" time))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-timestamp-with-time-range-returns-non-nil ()
  "Test that timestamp with time range returns non-nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 14 0))
             (timestamp (format-time-string "<%Y-%m-%d %a %H:%M-15:30>" time))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-scheduled-with-time-returns-non-nil ()
  "Test that SCHEDULED timestamp with time returns non-nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 9 0))
             (timestamp (concat "SCHEDULED: " (test-timestamp-string time)))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-deadline-with-time-returns-non-nil ()
  "Test that DEADLINE timestamp with time returns non-nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 17 0))
             (timestamp (concat "DEADLINE: " (test-timestamp-string time)))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-repeater-with-time-returns-non-nil ()
  "Test that timestamp with repeater and time returns non-nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 14 0))
             (timestamp (format-time-string "<%Y-%m-%d %a %H:%M +1w>" time))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-midnight-timestamp-returns-non-nil ()
  "Test that midnight timestamp (00:00) returns non-nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 0 0))
             (timestamp (test-timestamp-string time))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

;;; Boundary Cases

(ert-deftest test-chime-has-timestamp-day-wide-timestamp-returns-nil ()
  "Test that day-wide timestamp without time returns nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 0 0))
             (timestamp (test-timestamp-string time t))
             (result (chime--has-timestamp timestamp)))
        (should-not result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-date-only-returns-nil ()
  "Test that date-only timestamp without day name returns nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 0 0))
             (timestamp (format-time-string "<%Y-%m-%d>" time))
             (result (chime--has-timestamp timestamp)))
        (should-not result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-single-digit-hour-returns-non-nil ()
  "Test that timestamp with single-digit hour returns non-nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 9 0))
             (timestamp (format-time-string "<%Y-%m-%d %a %-H:%M>" time))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-embedded-in-text-returns-non-nil ()
  "Test that timestamp embedded in text returns non-nil.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 14 0))
             (timestamp (concat "Meeting scheduled for " (test-timestamp-string time) " in conference room"))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-multiple-timestamps-returns-non-nil ()
  "Test that string with multiple timestamps returns non-nil for first match.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time1 (test-time-tomorrow-at 14 0))
             (time2 (test-time-days-from-now 2))
             (timestamp (concat (test-timestamp-string time1) " and "
                                (format-time-string "<%Y-%m-%d %a %H:%M>" time2)))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

;;; Error Cases

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

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

(ert-deftest test-chime-has-timestamp-no-timestamp-returns-nil ()
  "Test that string without timestamp returns nil."
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((timestamp "Just a regular string with no timestamp")
             (result (chime--has-timestamp timestamp)))
        (should-not result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-invalid-format-returns-nil ()
  "Test that invalid timestamp format returns nil.

REFACTORED: Uses dynamic timestamps (keeps invalid format for testing)"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 14 0))
             ;; Intentionally wrong format (MM-DD-YYYY instead of YYYY-MM-DD) for testing
             (timestamp (format-time-string "<%m-%d-%Y %a %H:%M>" time))
             (result (chime--has-timestamp timestamp)))
        (should-not result))
    (test-chime-has-timestamp-teardown)))

(ert-deftest test-chime-has-timestamp-partial-timestamp-returns-nil ()
  "Test that partial timestamp returns nil.

REFACTORED: Uses dynamic timestamps (keeps partial format for testing)"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 0 0))
             ;; Intentionally incomplete timestamp for testing
             (timestamp (format-time-string "<%Y-%m-%d" time))
             (result (chime--has-timestamp timestamp)))
        (should-not result))
    (test-chime-has-timestamp-teardown)))

;;; org-gcal Integration Tests

(ert-deftest test-chime-has-timestamp-org-gcal-time-range-returns-non-nil ()
  "Test that org-gcal time range format is detected.
org-gcal uses format like <2025-10-24 Fri 17:30-18:00> which should be detected.

REFACTORED: Uses dynamic timestamps"
  (test-chime-has-timestamp-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 17 30))
             (timestamp (format-time-string "<%Y-%m-%d %a %H:%M-18:00>" time))
             (result (chime--has-timestamp timestamp)))
        (should result))
    (test-chime-has-timestamp-teardown)))

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