| author | |
| committer | |
| log | 3ed9f53a9cb6b22789662b171e8a58236a1dd33a |
| tree | b0005e924662d7c2236677aba213df5a2e0cb09e |
| parent | 4f702eb6c991e8b11262b3477f1462175d509633 |
6 files changed, 64 insertions(+), 58 deletions(-)
.gitignore-1| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | .zig-cache |
| 2 | zig-out | |
| 3 | 2 | .zigmod |
| 4 | 3 | deps.zig |
| 5 | 4 | files.zig |
build.zig+8| ... | ... | @@ -5,6 +5,14 @@ pub fn build(b: *std.Build) void { |
| 5 | 5 | const target = b.standardTargetOptions(.{}); |
| 6 | 6 | const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; |
| 7 | 7 | |
| 8 | const gen_step = b.step("generate", ""); | |
| 9 | const gen_cmd = b.addSystemCommand(&.{ "bun", "./generate.ts" }); | |
| 10 | const gen_out = gen_cmd.addOutputFileArg("test.zig"); | |
| 11 | const gen_install = b.addInstallFile(gen_out, "test.zig"); | |
| 12 | gen_cmd.setCwd(b.path(".")); | |
| 13 | gen_cmd.addFileInput(b.path("generate.ts")); | |
| 14 | gen_step.dependOn(&gen_install.step); | |
| 15 | ||
| 8 | 16 | const tests = b.addTest(.{ |
| 9 | 17 | .root_source_file = b.path("test.zig"), |
| 10 | 18 | .target = target, |
generate.ts+1-2| ... | ... | @@ -3,8 +3,7 @@ import casesraw from "./urltestdata.json"; |
| 3 | 3 | import casesidna from "./IdnaTestV2.json"; |
| 4 | 4 | |
| 5 | 5 | const cases = casesraw.filter((v) => typeof v !== "string"); |
| 6 | closeSync(openSync("./test.generated.zig", "w", 0o777)); | |
| 7 | const f = Bun.file("./test.generated.zig"); | |
| 6 | const f = Bun.file(process.argv[2]!); | |
| 8 | 7 | const w = f.writer(); |
| 9 | 8 | |
| 10 | 9 | w.write(`const std = @import("std");\n`); |
test.generated.zig deleted-54| ... | ... | @@ -1,54 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const url = @import("url"); | |
| 3 | const expect = @import("expect").expect; | |
| 4 | ||
| 5 | // zig fmt: off | |
| 6 | ||
| 7 | pub fn parseFail(input: []const u8, base: ?[]const u8) !void { | |
| 8 | const allocator = std.testing.allocator; | |
| 9 | _ = url.URL.parse(allocator, input, base) catch |err| switch (err) { | |
| 10 | error.SkipZigTest => |e| return e, | |
| 11 | else => return, | |
| 12 | }; | |
| 13 | return error.FailZigTest; | |
| 14 | } | |
| 15 | ||
| 16 | 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 { | |
| 17 | _ = input; | |
| 18 | _ = base; | |
| 19 | _ = href; | |
| 20 | _ = origin; | |
| 21 | _ = protocol; | |
| 22 | _ = username; | |
| 23 | _ = password; | |
| 24 | _ = host; | |
| 25 | _ = hostname; | |
| 26 | _ = port; | |
| 27 | _ = pathname; | |
| 28 | _ = search; | |
| 29 | _ = hash; | |
| 30 | return error.SkipZigTest; | |
| 31 | } | |
| 32 | ||
| 33 | pub fn parseIDNAFail(input: []const u8) !void { | |
| 34 | _ = input; | |
| 35 | // new URL('https://{idnaTest.input}/x') | |
| 36 | return error.SkipZigTest; | |
| 37 | } | |
| 38 | ||
| 39 | pub fn parseIDNAPass(input: []const u8, output: []const u8) !void { | |
| 40 | _ = input; | |
| 41 | _ = output; | |
| 42 | // new URL('https://{idnaTest.input}/x'); | |
| 43 | // assert_equals(url.host, idnaTest.output); | |
| 44 | // assert_equals(url.hostname, idnaTest.output); | |
| 45 | // assert_equals(url.pathname, "/x"); | |
| 46 | // assert_equals(url.href, 'https://{idnaTest.output}/x'); | |
| 47 | return error.SkipZigTest; | |
| 48 | } | |
| 49 | ||
| 50 | ||
| 51 | ||
| 52 | ||
| 53 | ||
| 54 |
test.zig+1-1| ... | ... | @@ -2,5 +2,5 @@ const std = @import("std"); |
| 2 | 2 | const url = @import("url"); |
| 3 | 3 | |
| 4 | 4 | test { |
| 5 | _ = @import("./test.generated.zig"); | |
| 5 | _ = @import("./zig-out/test.zig"); | |
| 6 | 6 | } |
zig-out/test.zig created+54| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | const std = @import("std"); | |
| 2 | const url = @import("url"); | |
| 3 | const expect = @import("expect").expect; | |
| 4 | ||
| 5 | // zig fmt: off | |
| 6 | ||
| 7 | pub fn parseFail(input: []const u8, base: ?[]const u8) !void { | |
| 8 | const allocator = std.testing.allocator; | |
| 9 | _ = url.URL.parse(allocator, input, base) catch |err| switch (err) { | |
| 10 | error.SkipZigTest => |e| return e, | |
| 11 | else => return, | |
| 12 | }; | |
| 13 | return error.FailZigTest; | |
| 14 | } | |
| 15 | ||
| 16 | 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 { | |
| 17 | _ = input; | |
| 18 | _ = base; | |
| 19 | _ = href; | |
| 20 | _ = origin; | |
| 21 | _ = protocol; | |
| 22 | _ = username; | |
| 23 | _ = password; | |
| 24 | _ = host; | |
| 25 | _ = hostname; | |
| 26 | _ = port; | |
| 27 | _ = pathname; | |
| 28 | _ = search; | |
| 29 | _ = hash; | |
| 30 | return error.SkipZigTest; | |
| 31 | } | |
| 32 | ||
| 33 | pub fn parseIDNAFail(input: []const u8) !void { | |
| 34 | _ = input; | |
| 35 | // new URL('https://{idnaTest.input}/x') | |
| 36 | return error.SkipZigTest; | |
| 37 | } | |
| 38 | ||
| 39 | pub fn parseIDNAPass(input: []const u8, output: []const u8) !void { | |
| 40 | _ = input; | |
| 41 | _ = output; | |
| 42 | // new URL('https://{idnaTest.input}/x'); | |
| 43 | // assert_equals(url.host, idnaTest.output); | |
| 44 | // assert_equals(url.hostname, idnaTest.output); | |
| 45 | // assert_equals(url.pathname, "/x"); | |
| 46 | // assert_equals(url.href, 'https://{idnaTest.output}/x'); | |
| 47 | return error.SkipZigTest; | |
| 48 | } | |
| 49 | ||
| 50 | ||
| 51 | ||
| 52 | ||
| 53 | ||
| 54 |