From d08b3d3b82145faefe315d68350878c61b218b94 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 21 Sep 2024 00:48:39 -0400 Subject: [PATCH] add tests for time.time_to_rfc3339 --- tests/core/time/test_core_time.odin | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/core/time/test_core_time.odin b/tests/core/time/test_core_time.odin index 51955b1c4..2ad3690d9 100644 --- a/tests/core/time/test_core_time.odin +++ b/tests/core/time/test_core_time.odin @@ -196,6 +196,35 @@ test_parse_rfc3339_string :: proc(t: ^testing.T) { } } +@test +test_print_rfc3339 :: proc(t: ^testing.T) { + TestCase :: struct { + printed: string, + time: i64, + utc_offset: int + }; + + tests :: [?]TestCase { + {"1985-04-12T23:20:50.52Z", 482196050520000000, 0}, + {"1985-04-12T23:20:50.52001905Z", 482196050520019050, 0}, + {"1996-12-19T16:39:57-08:00", 851013597000000000, -480}, + {"1996-12-20T00:39:57Z", 851042397000000000, 0}, + {"1937-01-01T12:00:27.87+00:20", -1041335972130000000, +20}, + }; + + for test in tests { + timestamp := time.Time { _nsec = test.time } + printed_timestamp, ok := time.time_to_rfc3339(time=timestamp, utc_offset=test.utc_offset) + defer delete_string(printed_timestamp) + + testing.expect(t, ok, "expected printing to work fine") + + testing.expectf( + t, printed_timestamp == test.printed, + "expected is %w, printed is %w", test.printed, printed_timestamp) + } +} + @test test_parse_iso8601_string :: proc(t: ^testing.T) { for test in iso8601_tests { @@ -318,4 +347,4 @@ date_component_roundtrip_test :: proc(t: ^testing.T, moment: dt.DateTime) { "Expected %4d-%2d-%2d %2d:%2d:%2d, got %4d-%2d-%2d %2d:%2d:%2d", moment.year, moment.month, moment.day, moment.hour, moment.minute, moment.second, YYYY, MM, DD, hh, mm, ss, ) -} \ No newline at end of file +}