aboutsummaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync--expand-monthly.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-calendar-sync--expand-monthly.el')
-rw-r--r--tests/test-calendar-sync--expand-monthly.el47
1 files changed, 37 insertions, 10 deletions
diff --git a/tests/test-calendar-sync--expand-monthly.el b/tests/test-calendar-sync--expand-monthly.el
index d2d25a70..e9fae901 100644
--- a/tests/test-calendar-sync--expand-monthly.el
+++ b/tests/test-calendar-sync--expand-monthly.el
@@ -14,9 +14,12 @@
;;; Normal Cases
(ert-deftest test-calendar-sync--expand-monthly-normal-generates-occurrences ()
- "Test expanding monthly event generates occurrences within range."
- (let* ((start-date (test-calendar-sync-time-days-from-now 1 10 0))
- (end-date (test-calendar-sync-time-days-from-now 1 11 0))
+ "Test expanding monthly event generates occurrences within range.
+Anchored on a day every month has: a series on the 29th, 30th, or 31st
+correctly skips the months lacking that day, which is fewer than one per month
+and not what this assertion is about."
+ (let* ((start-date (test-calendar-sync-time-monthly-anchor 10 0))
+ (end-date (test-calendar-sync-time-monthly-anchor 11 0))
(base-event (list :summary "Monthly Review"
:start start-date
:end end-date))
@@ -28,9 +31,13 @@
(should (< (length occurrences) 20))))
(ert-deftest test-calendar-sync--expand-monthly-normal-preserves-day-of-month ()
- "Test that each occurrence falls on the same day of month."
- (let* ((start-date (test-calendar-sync-time-days-from-now 5 10 0))
- (end-date (test-calendar-sync-time-days-from-now 5 11 0))
+ "Test that each occurrence falls on the same day of month.
+Anchored on a day every month has, so the assertion below can be an equality.
+It used to be `<=' against an anchor whose day varied with the run date, which a
+skipped month satisfies without ever landing on the right day -- the assertion
+held even when the series was wrong."
+ (let* ((start-date (test-calendar-sync-time-monthly-anchor 10 0))
+ (end-date (test-calendar-sync-time-monthly-anchor 11 0))
(expected-day (nth 2 start-date))
(base-event (list :summary "Monthly"
:start start-date
@@ -39,15 +46,15 @@
(range (test-calendar-sync-wide-range))
(occurrences (calendar-sync--expand-monthly base-event rrule range)))
(should (> (length occurrences) 0))
- ;; Day of month should be consistent (may clamp for short months)
+ ;; Every occurrence lands on the anchor day, exactly.
(dolist (occ occurrences)
(let ((day (nth 2 (plist-get occ :start))))
- (should (<= day expected-day))))))
+ (should (= day expected-day))))))
(ert-deftest test-calendar-sync--expand-monthly-normal-interval-two ()
"Test expanding bi-monthly event."
- (let* ((start-date (test-calendar-sync-time-days-from-now 1 9 0))
- (end-date (test-calendar-sync-time-days-from-now 1 10 0))
+ (let* ((start-date (test-calendar-sync-time-monthly-anchor 9 0))
+ (end-date (test-calendar-sync-time-monthly-anchor 10 0))
(base-event (list :summary "Bi-Monthly"
:start start-date
:end end-date))
@@ -269,5 +276,25 @@ Upper bound alone can't catch a dropped final occurrence -- assert both."
;; 2026 months (Apr on) with a 5th Wednesday: Apr 29, Jul 29, Sep 30, Dec 30.
(should (equal days '((4 29) (7 29) (9 30) (12 30))))))
+(ert-deftest test-calendar-sync--expand-monthly-on-31st-skips-short-months ()
+ "Boundary: a plain monthly rule on the 31st skips months without a 31st.
+The stepper kept day-of-month verbatim, so Jan 31 stepped to Feb 31,
+which encode-time normalizes to Mar 3 -- phantom mis-dated occurrences
+instead of the RFC 5545 skip."
+ (let* ((base-event (list :summary "Monthly on the 31st"
+ :start '(2030 1 31 10 0)
+ :end '(2030 1 31 11 0)))
+ (rrule (list :freq 'monthly :interval 1))
+ ;; End the range past Dec 31: the range end is midnight, so ending
+ ;; ON the 31st would exclude that day's 10:00 occurrence.
+ (range (list (calendar-sync--date-to-time '(2030 1 1))
+ (calendar-sync--date-to-time '(2031 1 1))))
+ (occurrences (calendar-sync--expand-monthly base-event rrule range))
+ (months (mapcar (lambda (o) (nth 1 (plist-get o :start))) occurrences))
+ (days (mapcar (lambda (o) (nth 2 (plist-get o :start))) occurrences)))
+ ;; Only the seven 31-day months of 2030, each on the 31st.
+ (should (equal months '(1 3 5 7 8 10 12)))
+ (should (equal days '(31 31 31 31 31 31 31)))))
+
(provide 'test-calendar-sync--expand-monthly)
;;; test-calendar-sync--expand-monthly.el ends here