diff --git a/.gitignore b/.gitignore index 378eac2..f611581 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ build +zig-cache +zig-out diff --git a/grammar/build.zig b/grammar/build.zig new file mode 100644 index 0000000..0d829e6 --- /dev/null +++ b/grammar/build.zig @@ -0,0 +1,35 @@ +const std = @import("std"); + +const test_targets = [_]std.Target.Query{ + .{}, +}; + +pub fn build(b: *std.Build) !void { + const test_step = b.step("test", "Test the tests"); + + var files = std.ArrayList([]const u8).init(b.allocator); + defer files.deinit(); + + var dir = try std.fs.cwd().openDir("tests", .{ .iterate = true }); + var it = dir.iterate(); + while (try it.next()) |file| { + if (file.kind != .file) { + continue; + } + try files.append(b.dupe(file.name)); + } + + for (test_targets) |target| { + for (files.items) |file| { + const unit_test = b.addTest(.{ + .root_source_file = .{ .path = file }, + .target = b.resolveTargetQuery(target), + }); + + const run_unit_test = b.addRunArtifact(unit_test); + test_step.dependOn(&run_unit_test.step); + } + } + + b.default_step.dependOn(test_step); +} diff --git a/grammar/tests/while.zig b/grammar/tests/while.zig index c920739..737b4ae 100644 --- a/grammar/tests/while.zig +++ b/grammar/tests/while.zig @@ -137,48 +137,42 @@ fn getNumberOrNull() ?i32 { test "while on optional with else result follow else prong" { const result = while (returnNull()) |value| { break value; - } else - @as(i32, 2); + } else @as(i32, 2); expect(result == 2); } test "while on optional with else result follow break prong" { const result = while (returnOptional(10)) |value| { break value; - } else - @as(i32, 2); + } else @as(i32, 2); expect(result == 10); } test "while on error union with else result follow else prong" { const result = while (returnError()) |value| { break value; - } else |err| - @as(i32, 2); + } else |err| @as(i32, 2); expect(result == 2); } test "while on error union with else result follow break prong" { const result = while (returnSuccess(10)) |value| { break value; - } else |err| - @as(i32, 2); + } else |err| @as(i32, 2); expect(result == 10); } test "while on bool with else result follow else prong" { const result = while (returnFalse()) { break @as(i32, 10); - } else - @as(i32, 2); + } else @as(i32, 2); expect(result == 2); } test "while on bool with else result follow break prong" { const result = while (returnTrue()) { break @as(i32, 10); - } else - @as(i32, 2); + } else @as(i32, 2); expect(result == 10); }