From 28fe483bedb408f0d7600b8c096ad1afbe15b43e Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 24 Oct 2021 21:50:38 -0700 Subject: [PATCH] reformat rest of tests --- main.zig | 129 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 51 deletions(-) diff --git a/main.zig b/main.zig index 3668bb4365fad8db48a191e962a07f332c9b0faa..3e7dbc0eb8560004b0b07a6faa8b3f6ca8bf3ebe 100644 --- a/main.zig +++ b/main.zig @@ -31,59 +31,86 @@ comptime { harness(1634858430000, &.{.{ "YYYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30" }}); harness(1634858430023, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023" }}); harness(1144509852789, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2006-04-08 15:24:12.789" }}); -} -fn assertOk(unix_ms: u64, comptime format: []const u8, expected: string) !void { - const alloc = std.testing.allocator; + harness(1635033600000, &.{ + .{ "H", "0" }, .{ "HH", "00" }, + .{ "h", "12" }, .{ "hh", "12" }, + .{ "k", "24" }, .{ "kk", "24" }, + }); + + harness(1635037200000, &.{ + .{ "H", "1" }, .{ "HH", "01" }, + .{ "h", "1" }, .{ "hh", "01" }, + .{ "k", "1" }, .{ "kk", "01" }, + }); + + harness(1635076800000, &.{ + .{ "H", "12" }, .{ "HH", "12" }, + .{ "h", "12" }, .{ "hh", "12" }, + .{ "k", "12" }, .{ "kk", "12" }, + }); + harness(1635080400000, &.{ + .{ "H", "13" }, .{ "HH", "13" }, + .{ "h", "1" }, .{ "hh", "01" }, + .{ "k", "13" }, .{ "kk", "13" }, + }); + + harness(1144509852789, &.{ + .{ "M", "4" }, + .{ "Mo", "4th" }, + .{ "MM", "04" }, + .{ "MMM", "Apr" }, + .{ "MMMM", "April" }, + + .{ "Q", "2" }, + .{ "Qo", "2nd" }, + + .{ "D", "8" }, + .{ "Do", "8th" }, + .{ "DD", "08" }, + + .{ "DDD", "98" }, + .{ "DDDo", "98th" }, + .{ "DDDD", "098" }, + + .{ "d", "6" }, + .{ "do", "6th" }, + .{ "dd", "Sa" }, + .{ "ddd", "Sat" }, + .{ "dddd", "Saturday" }, + .{ "E", "7" }, + + .{ "w", "14" }, + .{ "wo", "14th" }, + .{ "ww", "14" }, + + .{ "Y", "12006" }, + .{ "YY", "06" }, + .{ "YYY", "2006" }, + .{ "YYYY", "2006" }, + + .{ "N", "AD" }, + .{ "NN", "Anno Domini" }, + + .{ "A", "PM" }, + .{ "a", "pm" }, + + .{ "H", "15" }, + .{ "HH", "15" }, + .{ "h", "3" }, + .{ "hh", "03" }, + .{ "k", "15" }, + .{ "kk", "15" }, + + .{ "m", "24" }, + .{ "mm", "24" }, - const actual = try time.DateTime.initUnixMs(unix_ms).formatAlloc(alloc, format); - defer alloc.free(actual); + .{ "s", "12" }, + .{ "ss", "12" }, - std.testing.expectEqualStrings(expected, actual) catch return error.SkipZigTest; + .{ "S", "7" }, + .{ "SS", "78" }, + .{ "SSS", "789" }, + }); } -// zig fmt: off -// test every field -test { try assertOk(1144509852789, "M", "4"); } -test { try assertOk(1144509852789, "Mo", "4th"); } -test { try assertOk(1144509852789, "MM", "04"); } -test { try assertOk(1144509852789, "MMM", "Apr"); } -test { try assertOk(1144509852789, "MMMM", "April"); } -test { try assertOk(1144509852789, "Q", "2"); } -test { try assertOk(1144509852789, "Qo", "2nd"); } -test { try assertOk(1144509852789, "D", "8"); } -test { try assertOk(1144509852789, "Do", "8th"); } -test { try assertOk(1144509852789, "DD", "08"); } -test { try assertOk(1144509852789, "DDD", "98"); } -test { try assertOk(1144509852789, "DDDo", "98th"); } -test { try assertOk(1144509852789, "DDDD", "098"); } -test { try assertOk(1144509852789, "d", "6"); } -test { try assertOk(1144509852789, "do", "6th"); } -test { try assertOk(1144509852789, "dd", "Sa"); } -test { try assertOk(1144509852789, "ddd", "Sat"); } -test { try assertOk(1144509852789, "dddd", "Saturday"); } -test { try assertOk(1144509852789, "E", "7"); } -test { try assertOk(1144509852789, "w", "14"); } -test { try assertOk(1144509852789, "wo", "14th"); } -test { try assertOk(1144509852789, "ww", "14"); } -test { try assertOk(1144509852789, "Y", "12006"); } -test { try assertOk(1144509852789, "YY", "06"); } -test { try assertOk(1144509852789, "YYY", "2006"); } -test { try assertOk(1144509852789, "YYYY", "2006"); } -test { try assertOk(1144509852789, "N", "AD"); } -test { try assertOk(1144509852789, "NN", "Anno Domini"); } -test { try assertOk(1144509852789, "A", "PM"); } -test { try assertOk(1144509852789, "a", "pm"); } -test { try assertOk(1144509852789, "H", "15"); } -test { try assertOk(1144509852789, "HH", "15"); } -test { try assertOk(1144509852789, "h", "3"); } -test { try assertOk(1144509852789, "hh", "03"); } -test { try assertOk(1144509852789, "k", "15"); } -test { try assertOk(1144509852789, "kk", "15"); } -test { try assertOk(1144509852789, "m", "24"); } -test { try assertOk(1144509852789, "mm", "24"); } -test { try assertOk(1144509852789, "s", "12"); } -test { try assertOk(1144509852789, "ss", "12"); } -test { try assertOk(1144509852789, "S", "7"); } -test { try assertOk(1144509852789, "SS", "78"); } -test { try assertOk(1144509852789, "SSS", "789"); } -- 2.54.0