authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-24 14:36:03 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-24 14:46:27 -08:00
loge4875fe79a7f41d0e4d92d3558bdbee2996096d4
treec09bdd0e8a9565e5e1d8861bf6ae11b10ddb3944
parent3ccf2d3baa2f477362be1e641bf33870c2da2e44

fix the generate.ts types again


1 files changed, 44 insertions(+), 9 deletions(-)

generate.ts+44-9
...@@ -1,5 +1,30 @@...@@ -1,5 +1,30 @@
1const casesraw = await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/urltestdata.json").then((x) => x.json());1type Case = {
2const casesidna = await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/IdnaTestV2.json").then((x) => x.json());2 input: string;
3 base: string | null;
4 href: string;
5 origin: string;
6 protocol: string;
7 username: string;
8 password: string;
9 host: string;
10 hostname: string;
11 port: string;
12 pathname: string;
13 search: string;
14 hash: string;
15 failure: undefined;
16};
17type CaseFail = {
18 input: string;
19 base: string | null;
20 failure: true;
21};
22type CaseIDNA = {
23 input: string;
24 output: string | null;
25};
26const casesraw = (await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/urltestdata.json").then((x) => x.json())) as (string | Case | CaseFail)[];
27const casesidna = (await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/IdnaTestV2.json").then((x) => x.json())) as (string | CaseIDNA)[];
328
4const cases = casesraw.filter((v) => typeof v !== "string");29const cases = casesraw.filter((v) => typeof v !== "string");
5const f = Bun.file(process.argv[2]!);30const f = Bun.file(process.argv[2]!);
...@@ -82,39 +107,49 @@ pub fn parseIDNAPass(comptime input: []const u8, comptime output: []const u8) !v...@@ -82,39 +107,49 @@ pub fn parseIDNAPass(comptime input: []const u8, comptime output: []const u8) !v
82`);107`);
83108
84w.write(`\n`);109w.write(`\n`);
85for (const c of cases.filter((v) => v.base == null && !!v.failure)) {110for (const c of cases) {
111 if (c.base !== null) continue;
112 if (!c.failure) continue;
86 w.write(`test { try parseFail("${stringEscape(c.input)}", null); }\n`);113 w.write(`test { try parseFail("${stringEscape(c.input)}", null); }\n`);
87}114}
88115
89w.write(`\n`);116w.write(`\n`);
90// prettier-ignore117// prettier-ignore
91if (false)118if (false)
92for (const c of cases.filter((v) => v.base != null && !!v.failure)) {119for (const c of cases) {
120 if (c.base === null) continue;
121 if (!c.failure) continue;
93 w.write(`test { try parseFail("${stringEscape(c.input)}", "${stringEscape(c.base!)}"); }\n`);122 w.write(`test { try parseFail("${stringEscape(c.input)}", "${stringEscape(c.base!)}"); }\n`);
94}123}
95124
96w.write(`\n`);125w.write(`\n`);
97for (const c of cases.filter((v) => v.base == null && !v.failure)) {126for (const c of cases) {
127 if (c.base !== null) continue;
128 if (c.failure) continue;
98 w.write(`test { try parsePass("${E(c.input)}", null, "${E(c.href)}", "${E(c.origin)}", "${E(c.protocol)}", "${E(c.username)}", "${E(c.password)}", "${E(c.host)}", "${E(c.hostname)}", "${E(c.port)}", "${E(c.pathname)}", "${E(c.search)}", "${E(c.hash)}"); }\n`);129 w.write(`test { try parsePass("${E(c.input)}", null, "${E(c.href)}", "${E(c.origin)}", "${E(c.protocol)}", "${E(c.username)}", "${E(c.password)}", "${E(c.host)}", "${E(c.hostname)}", "${E(c.port)}", "${E(c.pathname)}", "${E(c.search)}", "${E(c.hash)}"); }\n`);
99}130}
100131
101w.write(`\n`);132w.write(`\n`);
102// prettier-ignore133// prettier-ignore
103if (false)134if (false)
104for (const c of cases.filter((v) => v.base != null && !v.failure)) {135for (const c of cases) {
136 if (c.base === null) continue;
137 if (c.failure) continue;
105 w.write(`test { try parsePass("${E(c.input)}", "${E(c.base!)}", "${E(c.href)}", "${E(c.origin)}", "${E(c.protocol)}", "${E(c.username)}", "${E(c.password)}", "${E(c.host)}", "${E(c.hostname)}", "${E(c.port)}", "${E(c.pathname)}", "${E(c.search)}", "${E(c.hash)}"); }\n`);138 w.write(`test { try parsePass("${E(c.input)}", "${E(c.base!)}", "${E(c.href)}", "${E(c.origin)}", "${E(c.protocol)}", "${E(c.username)}", "${E(c.password)}", "${E(c.host)}", "${E(c.hostname)}", "${E(c.port)}", "${E(c.pathname)}", "${E(c.search)}", "${E(c.hash)}"); }\n`);
106}139}
107140
108w.write(`\n`);141w.write(`\n`);
109for (const c of casesidna.filter((v) => typeof v !== "string").filter((v) => v.output === null)) {142for (const c of casesidna.filter((v) => typeof v !== "string")) {
110 if (c.input.length === 0) continue;143 if (c.input.length === 0) continue;
144 if (c.output !== null) continue;
111 w.write(`test { try parseIDNAFail("${stringEscape(c.input)}"); }\n`);145 w.write(`test { try parseIDNAFail("${stringEscape(c.input)}"); }\n`);
112}146}
113147
114w.write(`\n`);148w.write(`\n`);
115for (const c of casesidna.filter((v) => typeof v !== "string").filter((v) => v.output !== null)) {149for (const c of casesidna.filter((v) => typeof v !== "string")) {
116 if (c.input.length === 0) continue;150 if (c.input.length === 0) continue;
117 w.write(`test { try parseIDNAPass("${stringEscape(c.input)}", "${stringEscape(c.output!)}"); }\n`);151 if (c.output === null) continue;
152 w.write(`test { try parseIDNAPass("${stringEscape(c.input)}", "${stringEscape(c.output)}"); }\n`);
118}153}
119154
120w.flush();155w.flush();