blob: eb868952d15285cb536ab7d7224296145a972399 (
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
|
;;; test-calendar-sync--helpers.el --- Tests for calendar-sync helper functions -*- lexical-binding: t; -*-
;;; Commentary:
;; Unit tests for refactored helper functions.
;; Tests the helper functions that simplify RRULE expansion logic.
;;; Code:
(require 'ert)
(require 'calendar-sync)
;;; Setup and Teardown
(defun test-calendar-sync--helpers-setup ()
"Setup for helper function tests."
nil)
(defun test-calendar-sync--helpers-teardown ()
"Teardown for helper function tests."
nil)
;;; calendar-sync--date-to-time Tests
(ert-deftest test-calendar-sync--date-to-time-converts-date-to-time ()
"Test converting date to time value."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let* ((date '(2025 11 18)) ; Nov 18, 2025
(time-val (calendar-sync--date-to-time date)))
;; Should return a valid time value
(should (numberp (time-convert time-val 'integer))))
(test-calendar-sync--helpers-teardown)))
(ert-deftest test-calendar-sync--date-to-time-handles-different-dates ()
"Test date-to-time with various dates."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let ((date1 '(2025 1 1))
(date2 '(2025 12 31)))
;; Different dates should produce different time values
(should (not (equal (calendar-sync--date-to-time date1)
(calendar-sync--date-to-time date2)))))
(test-calendar-sync--helpers-teardown)))
;;; calendar-sync--before-date-p Tests
(ert-deftest test-calendar-sync--before-date-p-returns-true-for-earlier-date ()
"Test that earlier dates return true."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let ((earlier '(2025 11 17))
(later '(2025 11 18)))
(should (calendar-sync--before-date-p earlier later)))
(test-calendar-sync--helpers-teardown)))
(ert-deftest test-calendar-sync--before-date-p-returns-false-for-later-date ()
"Test that later dates return false."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let ((earlier '(2025 11 17))
(later '(2025 11 18)))
(should-not (calendar-sync--before-date-p later earlier)))
(test-calendar-sync--helpers-teardown)))
(ert-deftest test-calendar-sync--before-date-p-returns-false-for-same-date ()
"Test that same dates return false."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let ((date '(2025 11 18)))
(should-not (calendar-sync--before-date-p date date)))
(test-calendar-sync--helpers-teardown)))
(ert-deftest test-calendar-sync--before-date-p-handles-month-boundaries ()
"Test date comparison across month boundaries."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let ((november '(2025 11 30))
(december '(2025 12 1)))
(should (calendar-sync--before-date-p november december))
(should-not (calendar-sync--before-date-p december november)))
(test-calendar-sync--helpers-teardown)))
(ert-deftest test-calendar-sync--before-date-p-handles-year-boundaries ()
"Test date comparison across year boundaries."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let ((dec-2025 '(2025 12 31))
(jan-2026 '(2026 1 1)))
(should (calendar-sync--before-date-p dec-2025 jan-2026))
(should-not (calendar-sync--before-date-p jan-2026 dec-2025)))
(test-calendar-sync--helpers-teardown)))
;;; calendar-sync--create-occurrence Tests
(ert-deftest test-calendar-sync--create-occurrence-creates-new-event ()
"Test creating occurrence from base event."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let* ((base-event '(:summary "Test Event"
:start (2025 11 1 10 0 0)
:end (2025 11 1 11 0 0)))
(new-date '(2025 11 15 10 0 0))
(occurrence (calendar-sync--create-occurrence base-event new-date)))
;; Should have same summary
(should (equal (plist-get occurrence :summary) "Test Event"))
;; Should have new start date
(should (equal (plist-get occurrence :start) new-date))
;; Should have end date with same day as start
(let ((end (plist-get occurrence :end)))
(should (= (nth 0 end) 2025))
(should (= (nth 1 end) 11))
(should (= (nth 2 end) 15))))
(test-calendar-sync--helpers-teardown)))
(ert-deftest test-calendar-sync--create-occurrence-preserves-time ()
"Test that occurrence preserves time from base event."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let* ((base-event '(:summary "Morning Meeting"
:start (2025 11 1 9 30 0)
:end (2025 11 1 10 30 0)))
(new-date '(2025 11 15 9 30 0))
(occurrence (calendar-sync--create-occurrence base-event new-date)))
;; End time should preserve hours/minutes from base event
(let ((end (plist-get occurrence :end)))
(should (= (nth 3 end) 10)) ; hour
(should (= (nth 4 end) 30)))) ; minute
(test-calendar-sync--helpers-teardown)))
(ert-deftest test-calendar-sync--create-occurrence-handles-no-end-time ()
"Test creating occurrence when base event has no end time."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let* ((base-event '(:summary "All Day Event"
:start (2025 11 1 0 0 0)))
(new-date '(2025 11 15 0 0 0))
(occurrence (calendar-sync--create-occurrence base-event new-date)))
;; Should have start but no end
(should (equal (plist-get occurrence :start) new-date))
(should (null (plist-get occurrence :end))))
(test-calendar-sync--helpers-teardown)))
(ert-deftest test-calendar-sync--create-occurrence-does-not-modify-original ()
"Test that creating occurrence doesn't modify base event."
(test-calendar-sync--helpers-setup)
(unwind-protect
(let* ((original-start '(2025 11 1 10 0 0))
(base-event (list :summary "Test"
:start original-start))
(new-date '(2025 11 15 10 0 0)))
(calendar-sync--create-occurrence base-event new-date)
;; Original should be unchanged
(should (equal (plist-get base-event :start) original-start)))
(test-calendar-sync--helpers-teardown)))
(provide 'test-calendar-sync--helpers)
;;; test-calendar-sync--helpers.el ends here
|