blob: 2136325c64280477cce40972d64e64202e535b1a (
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
|
;;; test-chime-day-wide-time-matching.el --- Tests for day-wide time matching -*- lexical-binding: t; -*-
;; Copyright (C) 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 day-wide time matching functions:
;; - chime-current-time-matches-time-of-day-string
;; - chime-current-time-is-day-wide-time
;;
;; These functions determine when to fire notifications for all-day events
;; by comparing the current time to configured alert times like "08:00".
;;
;; IMPORTANT: Mock times must be computed BEFORE entering with-test-time,
;; because test-time-today-at calls current-time internally.
;;; Code:
(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
;; Load test utilities
(require 'testutil-general (expand-file-name "testutil-general.el"))
(require 'testutil-time (expand-file-name "testutil-time.el"))
;;;; Tests for chime-current-time-matches-time-of-day-string
;;; Normal Cases
(ert-deftest test-chime-time-matches-string-exact-match ()
"Should return truthy when current time matches the time-of-day string."
(let ((mock-time (test-time-today-at 8 0)))
(with-test-time mock-time
(should (chime-current-time-matches-time-of-day-string "8:00")))))
(ert-deftest test-chime-time-matches-string-no-match ()
"Should return nil when current time does not match."
(let ((mock-time (test-time-today-at 9 0)))
(with-test-time mock-time
(should-not (chime-current-time-matches-time-of-day-string "8:00")))))
(ert-deftest test-chime-time-matches-string-afternoon ()
"Should match afternoon times correctly."
(let ((mock-time (test-time-today-at 17 0)))
(with-test-time mock-time
(should (chime-current-time-matches-time-of-day-string "17:00")))))
;;; Boundary Cases
(ert-deftest test-chime-time-matches-string-midnight ()
"Should match midnight (00:00)."
(let ((mock-time (test-time-today-at 0 0)))
(with-test-time mock-time
(should (chime-current-time-matches-time-of-day-string "0:00")))))
(ert-deftest test-chime-time-matches-string-end-of-day ()
"Should match 23:59."
(let ((mock-time (test-time-today-at 23 59)))
(with-test-time mock-time
(should (chime-current-time-matches-time-of-day-string "23:59")))))
(ert-deftest test-chime-time-matches-string-off-by-one-minute ()
"One minute off should not match."
(let ((mock-time (test-time-today-at 8 1)))
(with-test-time mock-time
(should-not (chime-current-time-matches-time-of-day-string "8:00")))))
(ert-deftest test-chime-time-matches-string-leading-zero ()
"Should match with leading zero in time string (08:00)."
(let ((mock-time (test-time-today-at 8 0)))
(with-test-time mock-time
(should (chime-current-time-matches-time-of-day-string "08:00")))))
;;;; Tests for chime-current-time-is-day-wide-time
;;; Normal Cases
(ert-deftest test-chime-is-day-wide-time-matches-single-entry ()
"Should return truthy when current time matches the configured alert time."
(let ((mock-time (test-time-today-at 8 0)))
(with-test-time mock-time
(let ((chime-day-wide-alert-times '("08:00")))
(should (chime-current-time-is-day-wide-time))))))
(ert-deftest test-chime-is-day-wide-time-matches-second-entry ()
"Should return truthy when current time matches any entry, not just first."
(let ((mock-time (test-time-today-at 17 0)))
(with-test-time mock-time
(let ((chime-day-wide-alert-times '("08:00" "17:00")))
(should (chime-current-time-is-day-wide-time))))))
(ert-deftest test-chime-is-day-wide-time-no-match ()
"Should return nil when current time matches no configured alert times."
(let ((mock-time (test-time-today-at 12 0)))
(with-test-time mock-time
(let ((chime-day-wide-alert-times '("08:00" "17:00")))
(should-not (chime-current-time-is-day-wide-time))))))
;;; Boundary Cases
(ert-deftest test-chime-is-day-wide-time-empty-list ()
"Should return nil when alert times list is empty."
(let ((mock-time (test-time-today-at 8 0)))
(with-test-time mock-time
(let ((chime-day-wide-alert-times '()))
(should-not (chime-current-time-is-day-wide-time))))))
(ert-deftest test-chime-is-day-wide-time-nil-list ()
"Should return nil when alert times list is nil."
(let ((mock-time (test-time-today-at 8 0)))
(with-test-time mock-time
(let ((chime-day-wide-alert-times nil))
(should-not (chime-current-time-is-day-wide-time))))))
(ert-deftest test-chime-is-day-wide-time-matches-first-of-many ()
"Should return truthy when matching the first of several alert times."
(let ((mock-time (test-time-today-at 8 0)))
(with-test-time mock-time
(let ((chime-day-wide-alert-times '("08:00" "12:00" "17:00")))
(should (chime-current-time-is-day-wide-time))))))
(provide 'test-chime-day-wide-time-matching)
;;; test-chime-day-wide-time-matching.el ends here
|