authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-24 21:50:38 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-24 21:50:38 -07:00
log28fe483bedb408f0d7600b8c096ad1afbe15b43e
tree4160b74546ca7d7d163c831aeaf10d2adc0ad311
parentae73e1d8a27d9be8741dbb986842e605bc711e5d

reformat rest of tests


1 files changed, 78 insertions(+), 51 deletions(-)

main.zig+78-51
...@@ -31,59 +31,86 @@ comptime {...@@ -31,59 +31,86 @@ comptime {
31 harness(1634858430000, &.{.{ "YYYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30" }});31 harness(1634858430000, &.{.{ "YYYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30" }});
32 harness(1634858430023, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023" }});32 harness(1634858430023, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023" }});
33 harness(1144509852789, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2006-04-08 15:24:12.789" }});33 harness(1144509852789, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2006-04-08 15:24:12.789" }});
34}
3534
36fn assertOk(unix_ms: u64, comptime format: []const u8, expected: string) !void {35 harness(1635033600000, &.{
37 const alloc = std.testing.allocator;36 .{ "H", "0" }, .{ "HH", "00" },
37 .{ "h", "12" }, .{ "hh", "12" },
38 .{ "k", "24" }, .{ "kk", "24" },
39 });
40
41 harness(1635037200000, &.{
42 .{ "H", "1" }, .{ "HH", "01" },
43 .{ "h", "1" }, .{ "hh", "01" },
44 .{ "k", "1" }, .{ "kk", "01" },
45 });
46
47 harness(1635076800000, &.{
48 .{ "H", "12" }, .{ "HH", "12" },
49 .{ "h", "12" }, .{ "hh", "12" },
50 .{ "k", "12" }, .{ "kk", "12" },
51 });
52 harness(1635080400000, &.{
53 .{ "H", "13" }, .{ "HH", "13" },
54 .{ "h", "1" }, .{ "hh", "01" },
55 .{ "k", "13" }, .{ "kk", "13" },
56 });
57
58 harness(1144509852789, &.{
59 .{ "M", "4" },
60 .{ "Mo", "4th" },
61 .{ "MM", "04" },
62 .{ "MMM", "Apr" },
63 .{ "MMMM", "April" },
64
65 .{ "Q", "2" },
66 .{ "Qo", "2nd" },
67
68 .{ "D", "8" },
69 .{ "Do", "8th" },
70 .{ "DD", "08" },
71
72 .{ "DDD", "98" },
73 .{ "DDDo", "98th" },
74 .{ "DDDD", "098" },
75
76 .{ "d", "6" },
77 .{ "do", "6th" },
78 .{ "dd", "Sa" },
79 .{ "ddd", "Sat" },
80 .{ "dddd", "Saturday" },
81 .{ "E", "7" },
82
83 .{ "w", "14" },
84 .{ "wo", "14th" },
85 .{ "ww", "14" },
86
87 .{ "Y", "12006" },
88 .{ "YY", "06" },
89 .{ "YYY", "2006" },
90 .{ "YYYY", "2006" },
91
92 .{ "N", "AD" },
93 .{ "NN", "Anno Domini" },
94
95 .{ "A", "PM" },
96 .{ "a", "pm" },
97
98 .{ "H", "15" },
99 .{ "HH", "15" },
100 .{ "h", "3" },
101 .{ "hh", "03" },
102 .{ "k", "15" },
103 .{ "kk", "15" },
104
105 .{ "m", "24" },
106 .{ "mm", "24" },
38107
39 const actual = try time.DateTime.initUnixMs(unix_ms).formatAlloc(alloc, format);108 .{ "s", "12" },
40 defer alloc.free(actual);109 .{ "ss", "12" },
41110
42 std.testing.expectEqualStrings(expected, actual) catch return error.SkipZigTest;111 .{ "S", "7" },
112 .{ "SS", "78" },
113 .{ "SSS", "789" },
114 });
43}115}
44116
45// zig fmt: off
46// test every field
47test { try assertOk(1144509852789, "M", "4"); }
48test { try assertOk(1144509852789, "Mo", "4th"); }
49test { try assertOk(1144509852789, "MM", "04"); }
50test { try assertOk(1144509852789, "MMM", "Apr"); }
51test { try assertOk(1144509852789, "MMMM", "April"); }
52test { try assertOk(1144509852789, "Q", "2"); }
53test { try assertOk(1144509852789, "Qo", "2nd"); }
54test { try assertOk(1144509852789, "D", "8"); }
55test { try assertOk(1144509852789, "Do", "8th"); }
56test { try assertOk(1144509852789, "DD", "08"); }
57test { try assertOk(1144509852789, "DDD", "98"); }
58test { try assertOk(1144509852789, "DDDo", "98th"); }
59test { try assertOk(1144509852789, "DDDD", "098"); }
60test { try assertOk(1144509852789, "d", "6"); }
61test { try assertOk(1144509852789, "do", "6th"); }
62test { try assertOk(1144509852789, "dd", "Sa"); }
63test { try assertOk(1144509852789, "ddd", "Sat"); }
64test { try assertOk(1144509852789, "dddd", "Saturday"); }
65test { try assertOk(1144509852789, "E", "7"); }
66test { try assertOk(1144509852789, "w", "14"); }
67test { try assertOk(1144509852789, "wo", "14th"); }
68test { try assertOk(1144509852789, "ww", "14"); }
69test { try assertOk(1144509852789, "Y", "12006"); }
70test { try assertOk(1144509852789, "YY", "06"); }
71test { try assertOk(1144509852789, "YYY", "2006"); }
72test { try assertOk(1144509852789, "YYYY", "2006"); }
73test { try assertOk(1144509852789, "N", "AD"); }
74test { try assertOk(1144509852789, "NN", "Anno Domini"); }
75test { try assertOk(1144509852789, "A", "PM"); }
76test { try assertOk(1144509852789, "a", "pm"); }
77test { try assertOk(1144509852789, "H", "15"); }
78test { try assertOk(1144509852789, "HH", "15"); }
79test { try assertOk(1144509852789, "h", "3"); }
80test { try assertOk(1144509852789, "hh", "03"); }
81test { try assertOk(1144509852789, "k", "15"); }
82test { try assertOk(1144509852789, "kk", "15"); }
83test { try assertOk(1144509852789, "m", "24"); }
84test { try assertOk(1144509852789, "mm", "24"); }
85test { try assertOk(1144509852789, "s", "12"); }
86test { try assertOk(1144509852789, "ss", "12"); }
87test { try assertOk(1144509852789, "S", "7"); }
88test { try assertOk(1144509852789, "SS", "78"); }
89test { try assertOk(1144509852789, "SSS", "789"); }