blob: c94801ad571e34c284a6f98e912398cad2748797 (
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
|
;;; test-chime-time-left.el --- Tests for chime--time-left -*- 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--time-left 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-time-left-setup ()
"Setup function run before each test."
(chime-create-test-base-dir))
(defun test-chime-time-left-teardown ()
"Teardown function run after each test."
(chime-delete-test-base-dir))
;;; Normal Cases
(ert-deftest test-chime-time-left-one-minute-formats-correctly ()
"Test that 1 minute formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 60)))
(should (stringp result))
(should (string-match-p "in 1 minute" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-five-minutes-formats-correctly ()
"Test that 5 minutes formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 300)))
(should (stringp result))
(should (string-match-p "in 5 minutes" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-ten-minutes-formats-correctly ()
"Test that 10 minutes formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 600)))
(should (stringp result))
(should (string-match-p "in 10 minutes" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-thirty-minutes-formats-correctly ()
"Test that 30 minutes formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 1800)))
(should (stringp result))
(should (string-match-p "in 30 minutes" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-one-hour-formats-correctly ()
"Test that 1 hour formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 3600)))
(should (stringp result))
;; At exactly 1 hour (3600s), still shows minutes format
(should (string-match-p "in 60 minutes" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-two-hours-formats-correctly ()
"Test that 2 hours formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 7200)))
(should (stringp result))
(should (string-match-p "in 2 hours" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-one-hour-thirty-minutes-formats-correctly ()
"Test that 1 hour 30 minutes formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 5400)))
(should (stringp result))
;; Should show both hours and minutes
(should (string-match-p "in 1 hour 30 minutes" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-three-hours-fifteen-minutes-formats-correctly ()
"Test that 3 hours 15 minutes formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 11700)))
(should (stringp result))
(should (string-match-p "in 3 hours 15 minutes" result)))
(test-chime-time-left-teardown)))
;;; Boundary Cases
(ert-deftest test-chime-time-left-zero-seconds-returns-right-now ()
"Test that 0 seconds returns 'right now'."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 0)))
(should (stringp result))
(should (string-equal "right now" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-one-second-shows-right-now ()
"Test that 1 second shows 'right now'."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 1)))
(should (stringp result))
;; Less than a minute, but format-seconds might show "in 0 minutes"
;; or the implementation might handle this specially
(should result))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-fifty-nine-seconds-shows-minutes ()
"Test that 59 seconds shows in minutes format."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 59)))
(should (stringp result))
;; Should use minutes format (< 1 hour)
(should (string-match-p "in" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-exactly-one-hour-shows-minutes-format ()
"Test that exactly 1 hour shows minutes format."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 3600)))
(should (stringp result))
;; At exactly 3600s, still uses minutes format (boundary case)
(should (string-match-p "in 60 minutes" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-fifty-nine-minutes-shows-minutes-only ()
"Test that 59 minutes shows minutes format only."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 3540))) ; 59 minutes
(should (stringp result))
(should (string-match-p "in 59 minutes" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-twenty-four-hours-formats-correctly ()
"Test that 24 hours formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 86400)))
(should (stringp result))
(should (string-match-p "in 24 hours" result)))
(test-chime-time-left-teardown)))
;;; Error Cases
(ert-deftest test-chime-time-left-negative-value-returns-right-now ()
"Test that negative value returns 'right now'."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left -60)))
(should (stringp result))
(should (string-equal "right now" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-large-negative-returns-right-now ()
"Test that large negative value returns 'right now'."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left -3600)))
(should (stringp result))
(should (string-equal "right now" result)))
(test-chime-time-left-teardown)))
(ert-deftest test-chime-time-left-very-large-value-formats-correctly ()
"Test that very large value (1 week) formats correctly."
(test-chime-time-left-setup)
(unwind-protect
(let ((result (chime--time-left 604800))) ; 1 week
(should (stringp result))
;; Should format with days/hours
(should (string-match-p "in" result)))
(test-chime-time-left-teardown)))
(provide 'test-chime-time-left)
;;; test-chime-time-left.el ends here
|