summaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync--parse-timestamp.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-05 06:51:20 -0500
committerCraig Jennings <c@cjennings.net>2026-04-05 06:51:20 -0500
commit7eb6c0692d48b8c3d01efba8abcd2bfdfaa7cd31 (patch)
tree2af7aa512feaae39b384939160af68fa0537fc22 /tests/test-calendar-sync--parse-timestamp.el
parent47453fd03be79205c6209d31a26cb4f7724af317 (diff)
test(calendar-sync): add 68 tests across 13 files for untested pure functions
Covers core parsing (parse-ics-datetime, parse-timestamp, format-timestamp, split-events, parse-event), date utilities (add-months, add-days, weekday-to-number, date-weekday, event-start-time), and timezone (format-timezone-offset, convert-utc-to-local, localize-parsed-datetime).
Diffstat (limited to 'tests/test-calendar-sync--parse-timestamp.el')
-rw-r--r--tests/test-calendar-sync--parse-timestamp.el59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test-calendar-sync--parse-timestamp.el b/tests/test-calendar-sync--parse-timestamp.el
new file mode 100644
index 00000000..d05540f7
--- /dev/null
+++ b/tests/test-calendar-sync--parse-timestamp.el
@@ -0,0 +1,59 @@
+;;; test-calendar-sync--parse-timestamp.el --- Tests for timestamp parser -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for calendar-sync--parse-timestamp.
+;; Handles UTC conversion, TZID conversion, local passthrough, and date-only.
+
+;;; Code:
+
+(require 'ert)
+(require 'testutil-calendar-sync)
+(require 'calendar-sync)
+
+;;; Normal Cases
+
+(ert-deftest test-calendar-sync--parse-timestamp-normal-local-no-tz ()
+ "Local datetime without timezone returns raw values."
+ (let ((result (calendar-sync--parse-timestamp "20260315T143000")))
+ (should (equal '(2026 3 15 14 30) result))))
+
+(ert-deftest test-calendar-sync--parse-timestamp-normal-utc-converts ()
+ "UTC datetime (Z suffix) is converted to local time."
+ (let ((result (calendar-sync--parse-timestamp "20260315T180000Z")))
+ ;; Result should be local time — verify it's a valid 5-element list
+ (should (= 5 (length result)))
+ ;; The hour should differ from 18 unless we're in UTC
+ (should (numberp (nth 3 result)))))
+
+(ert-deftest test-calendar-sync--parse-timestamp-normal-date-only ()
+ "Date-only returns 3-element list (year month day)."
+ (let ((result (calendar-sync--parse-timestamp "20260315")))
+ (should (equal '(2026 3 15) result))))
+
+;;; Boundary Cases
+
+(ert-deftest test-calendar-sync--parse-timestamp-boundary-with-tzid ()
+ "TZID parameter triggers timezone conversion."
+ (let ((result (calendar-sync--parse-timestamp "20260315T140000" "America/New_York")))
+ ;; Should return a 5-element list (converted from Eastern)
+ (should (= 5 (length result)))
+ (should (numberp (nth 0 result)))))
+
+(ert-deftest test-calendar-sync--parse-timestamp-boundary-midnight-utc ()
+ "Midnight UTC converts correctly (may change date for western timezones)."
+ (let ((result (calendar-sync--parse-timestamp "20260315T000000Z")))
+ (should (= 5 (length result)))
+ (should (numberp (nth 3 result)))))
+
+;;; Error Cases
+
+(ert-deftest test-calendar-sync--parse-timestamp-error-garbage ()
+ "Non-datetime string returns nil."
+ (should (null (calendar-sync--parse-timestamp "not-a-date"))))
+
+(ert-deftest test-calendar-sync--parse-timestamp-error-partial ()
+ "Truncated datetime returns nil."
+ (should (null (calendar-sync--parse-timestamp "2026031"))))
+
+(provide 'test-calendar-sync--parse-timestamp)
+;;; test-calendar-sync--parse-timestamp.el ends here