diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-05 06:51:20 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-05 06:51:20 -0500 |
| commit | 7eb6c0692d48b8c3d01efba8abcd2bfdfaa7cd31 (patch) | |
| tree | 2af7aa512feaae39b384939160af68fa0537fc22 /tests/test-calendar-sync--format-timestamp.el | |
| parent | 47453fd03be79205c6209d31a26cb4f7724af317 (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--format-timestamp.el')
| -rw-r--r-- | tests/test-calendar-sync--format-timestamp.el | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test-calendar-sync--format-timestamp.el b/tests/test-calendar-sync--format-timestamp.el new file mode 100644 index 00000000..5b8a6d02 --- /dev/null +++ b/tests/test-calendar-sync--format-timestamp.el @@ -0,0 +1,60 @@ +;;; test-calendar-sync--format-timestamp.el --- Tests for org timestamp formatting -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for calendar-sync--format-timestamp. +;; Converts parsed start/end times to org-mode timestamp strings. + +;;; Code: + +(require 'ert) +(require 'testutil-calendar-sync) +(require 'calendar-sync) + +;;; Normal Cases + +(ert-deftest test-calendar-sync--format-timestamp-normal-with-time () + "Timed event produces '<YYYY-MM-DD Day HH:MM-HH:MM>'." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 14 0) '(2026 3 15 15 30)))) + (should (string-match-p "^<2026-03-15 .* 14:00-15:30>$" result)))) + +(ert-deftest test-calendar-sync--format-timestamp-normal-all-day () + "All-day event (nil hours) produces '<YYYY-MM-DD Day>'." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 nil nil) '(2026 3 16 nil nil)))) + (should (string-match-p "^<2026-03-15 .*>$" result)) + (should-not (string-match-p "[0-9]:[0-9]" result)))) + +(ert-deftest test-calendar-sync--format-timestamp-normal-includes-weekday () + "Timestamp includes abbreviated weekday name." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 14 0) '(2026 3 15 15 0)))) + ;; 2026-03-15 is a Sunday + (should (string-match-p "Sun" result)))) + +;;; Boundary Cases + +(ert-deftest test-calendar-sync--format-timestamp-boundary-midnight () + "Midnight start and end are formatted as 00:00." + (let ((result (calendar-sync--format-timestamp + '(2026 1 1 0 0) '(2026 1 1 1 0)))) + (should (string-match-p "00:00-01:00" result)))) + +(ert-deftest test-calendar-sync--format-timestamp-boundary-nil-end () + "Nil end with timed start still produces time range." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 14 0) nil))) + ;; No end time means no time range + (should (string-match-p "^<2026-03-15" result)))) + +;;; Error Cases + +(ert-deftest test-calendar-sync--format-timestamp-error-start-no-time-end-has-time () + "All-day start with timed end produces date-only (no time range)." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 nil nil) '(2026 3 15 15 0)))) + ;; start-hour is nil so time-str should be nil + (should-not (string-match-p "[0-9][0-9]:[0-9][0-9]-" result)))) + +(provide 'test-calendar-sync--format-timestamp) +;;; test-calendar-sync--format-timestamp.el ends here |
