diff --git a/build.zig b/build.zig index 074d572fa94c34950d182e4716e236abe1f9256c..6fdd9f4dc6a359727cd87e03b96c45c77ea02cb9 100644 --- a/build.zig +++ b/build.zig @@ -20,4 +20,16 @@ pub fn build(b: *std.Build) void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); + + const tests = b.addTest(.{ + .root_source_file = b.path("src/test.zig"), + .target = target, + .optimize = mode, + }); + + const run_test = b.addRunArtifact(tests); + run_test.step.dependOn(&tests.step); + + const test_step = b.step("test", "Run the test suite"); + test_step.dependOn(&run_test.step); } diff --git a/src/test.zig b/src/test.zig new file mode 100644 index 0000000000000000000000000000000000000000..a35b087b4e0b78cde1605cedfc5883b8add85d1e --- /dev/null +++ b/src/test.zig @@ -0,0 +1,19 @@ +const std = @import("std"); +const ansi = @import("./lib.zig"); + +fn expectFmt(comptime actual: []const u8, expected: []const u8) !void { + return std.testing.expectEqualSlices(u8, expected, actual); +} + +test { + try expectFmt( + ansi.color.Fg(.Blue, "All your codebase"), + &(.{ 27, '[', '3', '4', 'm' } ++ "All your codebase".* ++ .{ 27, '[', '3', '9', 'm' }), + ); +} +test { + try expectFmt( + ansi.color.Bg(.Cyan, "All your codebase"), + &(.{ 27, '[', '4', '6', 'm' } ++ "All your codebase".* ++ .{ 27, '[', '4', '9', 'm' }), + ); +}