diff --git a/build.zig b/build.zig index 2a47b70136549550f9f536c7a9a872e046d5c5cc..8a3036d41ff085d7245ec00ed051b22ba68b95c2 100644 --- a/build.zig +++ b/build.zig @@ -23,4 +23,11 @@ pub fn build(b: *std.build.Builder) void { run_step.dependOn(&run_cmd.step); } + { + const t = b.addTest("main.zig"); + deps.addAllTo(t); + + const t_step = b.step("test", ""); + t_step.dependOn(&t.step); + } } diff --git a/main.zig b/main.zig index d29869ff88feb94cd5a5fd28d760824920f269ac..220dc52c97a25ba151111466c5edec6350ee746a 100644 --- a/main.zig +++ b/main.zig @@ -1,5 +1,21 @@ const std = @import("std"); +const string = []const u8; +const time = @import("time"); -pub fn main() anyerror!void { +pub fn main() !void { std.log.info("All your codebase are belong to us.", .{}); } + +fn assertOk(input: u64, expected: string) !void { + const alloc = std.testing.allocator; + + const actual = try time.DateTime.initUnix(input).formatAlloc(alloc, "YYYY-MM-DD HH:mm:ss"); + defer alloc.free(actual); + + try std.testing.expectEqualStrings(expected, actual); +} + +// zig fmt: off +test { try assertOk(0, "1970-01-01 00:00:00"); } +test { try assertOk(1257894000, "2009-11-10 23:00:00"); } +test { try assertOk(1634858430, "2021-10-21 23:20:30"); }