authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 20:36:56 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 20:36:56 -07:00
log64bc6c77e8189c60a5223877827b4753eb2b483d
tree808d9c90230f643ac87beb27872a228f29b95e7b
parent729990060aa9fc694ee8d030813eb1e553ffa735

add tests


2 files changed, 24 insertions(+), 1 deletions(-)

build.zig+7
...@@ -23,4 +23,11 @@ pub fn build(b: *std.build.Builder) void {...@@ -23,4 +23,11 @@ pub fn build(b: *std.build.Builder) void {
23 run_step.dependOn(&run_cmd.step);23 run_step.dependOn(&run_cmd.step);
24 }24 }
2525
26 {
27 const t = b.addTest("main.zig");
28 deps.addAllTo(t);
29
30 const t_step = b.step("test", "");
31 t_step.dependOn(&t.step);
32 }
26}33}
main.zig+17-1
...@@ -1,5 +1,21 @@...@@ -1,5 +1,21 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
3const time = @import("time");
24
3pub fn main() anyerror!void {5pub fn main() !void {
4 std.log.info("All your codebase are belong to us.", .{});6 std.log.info("All your codebase are belong to us.", .{});
5}7}
8
9fn assertOk(input: u64, expected: string) !void {
10 const alloc = std.testing.allocator;
11
12 const actual = try time.DateTime.initUnix(input).formatAlloc(alloc, "YYYY-MM-DD HH:mm:ss");
13 defer alloc.free(actual);
14
15 try std.testing.expectEqualStrings(expected, actual);
16}
17
18// zig fmt: off
19test { try assertOk(0, "1970-01-01 00:00:00"); }
20test { try assertOk(1257894000, "2009-11-10 23:00:00"); }
21test { try assertOk(1634858430, "2021-10-21 23:20:30"); }