diff options
Diffstat (limited to 'tests/testutil-calendar-sync.el')
| -rw-r--r-- | tests/testutil-calendar-sync.el | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/tests/testutil-calendar-sync.el b/tests/testutil-calendar-sync.el index c83006b5..d1a94b01 100644 --- a/tests/testutil-calendar-sync.el +++ b/tests/testutil-calendar-sync.el @@ -8,6 +8,15 @@ (require 'calendar) +;;; Test Environment Setup + +;; Provide stub for cj/log-silently if not already defined +;; This function is defined in system-lib.el but tests should run standalone +(unless (fboundp 'cj/log-silently) + (defun cj/log-silently (format-string &rest args) + "Stub for testing: silently ignore log messages." + nil)) + ;;; Dynamic Timestamp Generation (defun test-calendar-sync-time-today-at (hour minute) @@ -48,7 +57,7 @@ Returns (year month day hour minute) list suitable for tests." (defun test-calendar-sync-time-date-only (offset-days) "Generate date-only timestamp for OFFSET-DAYS from now. -Returns (year month day) list for all-day events." +Returns (year month day) list for all-day events and UNTIL dates." (let* ((future (time-add (current-time) (* offset-days 24 3600))) (decoded (decode-time future)) (year (nth 5 decoded)) @@ -56,6 +65,22 @@ Returns (year month day) list for all-day events." (day (nth 3 decoded))) (list year month day))) +(defun test-calendar-sync-time-date-only-ago (offset-days) + "Generate date-only timestamp for OFFSET-DAYS ago. +Returns (year month day) list for UNTIL dates in the past." + (let* ((past (time-subtract (current-time) (* offset-days 24 3600))) + (decoded (decode-time past)) + (year (nth 5 decoded)) + (month (nth 4 decoded)) + (day (nth 3 decoded))) + (list year month day))) + +(defun test-calendar-sync-date-only-from-datetime (datetime) + "Extract date-only (year month day) from DATETIME list. +DATETIME is (year month day hour minute). +Returns (year month day) suitable for UNTIL dates." + (list (nth 0 datetime) (nth 1 datetime) (nth 2 datetime))) + ;;; .ics Test Data Generation (defun test-calendar-sync-ics-datetime (time-list) @@ -106,5 +131,68 @@ Each event should be a VEVENT string from `test-calendar-sync-make-vevent'." (string-join events "\n") "\nEND:VCALENDAR")) +;;; Property Test Helpers + +(defun test-calendar-sync-random-future-date () + "Generate random date 1-180 days in future with random time. +Returns (year month day hour minute) list." + (test-calendar-sync-time-days-from-now + (1+ (random 180)) + (random 24) + (random 60))) + +(defun test-calendar-sync-random-past-date () + "Generate random date 1-90 days in past with random time. +Returns (year month day hour minute) list." + (test-calendar-sync-time-days-ago + (1+ (random 90)) + (random 24) + (random 60))) + +(defun test-calendar-sync-random-weekday-subset () + "Generate random non-empty subset of weekdays. +Returns list of weekday strings like (\"MO\" \"WE\" \"FR\")." + (let ((days '("MO" "TU" "WE" "TH" "FR" "SA" "SU")) + (result '())) + (dolist (day days) + (when (zerop (random 2)) + (push day result))) + ;; Ensure non-empty + (or result (list (nth (random 7) days))))) + +(defun test-calendar-sync-random-freq () + "Return random RRULE frequency symbol." + (nth (random 4) '(daily weekly monthly yearly))) + +(defun test-calendar-sync-days-between (date1 date2) + "Calculate days between DATE1 and DATE2. +Both dates are (year month day ...) lists. +Returns float number of days (positive if date2 > date1)." + (let ((t1 (calendar-sync--date-to-time (list (nth 0 date1) (nth 1 date1) (nth 2 date1)))) + (t2 (calendar-sync--date-to-time (list (nth 0 date2) (nth 1 date2) (nth 2 date2))))) + (/ (float-time (time-subtract t2 t1)) 86400.0))) + +(defun test-calendar-sync-wide-range () + "Generate wide date range: 90 days past to 365 days future. +Returns (start-time end-time) suitable for expansion functions." + (list (time-subtract (current-time) (* 90 86400)) + (time-add (current-time) (* 365 86400)))) + +(defun test-calendar-sync-narrow-range () + "Generate narrow date range: today to 30 days future. +Returns (start-time end-time) suitable for expansion functions." + (list (current-time) + (time-add (current-time) (* 30 86400)))) + +(defun test-calendar-sync-date-to-time-value (date) + "Convert DATE list to Emacs time value. +DATE is (year month day) or (year month day hour minute)." + (let ((year (nth 0 date)) + (month (nth 1 date)) + (day (nth 2 date)) + (hour (or (nth 3 date) 0)) + (minute (or (nth 4 date) 0))) + (encode-time 0 minute hour day month year))) + (provide 'testutil-calendar-sync) ;;; testutil-calendar-sync.el ends here |
