diff --git a/.gitignore b/.gitignore index fca76950e1542a6e4e13830388ac57078e055e03..6f46837e78b35a0feab3de7506e072f467c39344 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .zig-cache -zig-out .zigmod deps.zig files.zig diff --git a/build.zig b/build.zig index f9ffeeac66f66074b0a7bbaee04d2452b06067c5..fd89fa3dfb5c4c076483ea203b95805508384c33 100644 --- a/build.zig +++ b/build.zig @@ -5,6 +5,14 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; + const gen_step = b.step("generate", ""); + const gen_cmd = b.addSystemCommand(&.{ "bun", "./generate.ts" }); + const gen_out = gen_cmd.addOutputFileArg("test.zig"); + const gen_install = b.addInstallFile(gen_out, "test.zig"); + gen_cmd.setCwd(b.path(".")); + gen_cmd.addFileInput(b.path("generate.ts")); + gen_step.dependOn(&gen_install.step); + const tests = b.addTest(.{ .root_source_file = b.path("test.zig"), .target = target, diff --git a/generate.ts b/generate.ts index 99e53107f5bb85c58534a974e94fe7e887770a0f..27538d460e41da8c9fdb6661dbd24579882c4a72 100644 --- a/generate.ts +++ b/generate.ts @@ -3,8 +3,7 @@ import casesraw from "./urltestdata.json"; import casesidna from "./IdnaTestV2.json"; const cases = casesraw.filter((v) => typeof v !== "string"); -closeSync(openSync("./test.generated.zig", "w", 0o777)); -const f = Bun.file("./test.generated.zig"); +const f = Bun.file(process.argv[2]!); const w = f.writer(); w.write(`const std = @import("std");\n`); diff --git a/test.generated.zig b/test.generated.zig deleted file mode 100644 index 5bae839a731ecc496fa90485369356657187c836..0000000000000000000000000000000000000000 --- a/test.generated.zig +++ /dev/null @@ -1,54 +0,0 @@ -const std = @import("std"); -const url = @import("url"); -const expect = @import("expect").expect; - -// zig fmt: off - -pub fn parseFail(input: []const u8, base: ?[]const u8) !void { - const allocator = std.testing.allocator; - _ = url.URL.parse(allocator, input, base) catch |err| switch (err) { - error.SkipZigTest => |e| return e, - else => return, - }; - return error.FailZigTest; -} - -pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin: []const u8, protocol: []const u8, username: []const u8, password: []const u8, host: []const u8, hostname: []const u8, port: []const u8, pathname: []const u8, search: []const u8, hash: []const u8) !void { - _ = input; - _ = base; - _ = href; - _ = origin; - _ = protocol; - _ = username; - _ = password; - _ = host; - _ = hostname; - _ = port; - _ = pathname; - _ = search; - _ = hash; - return error.SkipZigTest; -} - -pub fn parseIDNAFail(input: []const u8) !void { - _ = input; - // new URL('https://{idnaTest.input}/x') - return error.SkipZigTest; -} - -pub fn parseIDNAPass(input: []const u8, output: []const u8) !void { - _ = input; - _ = output; - // new URL('https://{idnaTest.input}/x'); - // assert_equals(url.host, idnaTest.output); - // assert_equals(url.hostname, idnaTest.output); - // assert_equals(url.pathname, "/x"); - // assert_equals(url.href, 'https://{idnaTest.output}/x'); - return error.SkipZigTest; -} - - - - - - diff --git a/test.zig b/test.zig index e1ce9ccfae058291a6f29c4ae9a465bd7fb7b6d9..c6c99f551c716ef2b57b34bb7293cefd298b4683 100644 --- a/test.zig +++ b/test.zig @@ -2,5 +2,5 @@ const std = @import("std"); const url = @import("url"); test { - _ = @import("./test.generated.zig"); + _ = @import("./zig-out/test.zig"); } diff --git a/zig-out/test.zig b/zig-out/test.zig new file mode 100644 index 0000000000000000000000000000000000000000..5bae839a731ecc496fa90485369356657187c836 --- /dev/null +++ b/zig-out/test.zig @@ -0,0 +1,54 @@ +const std = @import("std"); +const url = @import("url"); +const expect = @import("expect").expect; + +// zig fmt: off + +pub fn parseFail(input: []const u8, base: ?[]const u8) !void { + const allocator = std.testing.allocator; + _ = url.URL.parse(allocator, input, base) catch |err| switch (err) { + error.SkipZigTest => |e| return e, + else => return, + }; + return error.FailZigTest; +} + +pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin: []const u8, protocol: []const u8, username: []const u8, password: []const u8, host: []const u8, hostname: []const u8, port: []const u8, pathname: []const u8, search: []const u8, hash: []const u8) !void { + _ = input; + _ = base; + _ = href; + _ = origin; + _ = protocol; + _ = username; + _ = password; + _ = host; + _ = hostname; + _ = port; + _ = pathname; + _ = search; + _ = hash; + return error.SkipZigTest; +} + +pub fn parseIDNAFail(input: []const u8) !void { + _ = input; + // new URL('https://{idnaTest.input}/x') + return error.SkipZigTest; +} + +pub fn parseIDNAPass(input: []const u8, output: []const u8) !void { + _ = input; + _ = output; + // new URL('https://{idnaTest.input}/x'); + // assert_equals(url.host, idnaTest.output); + // assert_equals(url.hostname, idnaTest.output); + // assert_equals(url.pathname, "/x"); + // assert_equals(url.href, 'https://{idnaTest.output}/x'); + return error.SkipZigTest; +} + + + + + +