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 @@
1const casesraw = await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/urltestdata.json").then((x) => x.json());
2const casesidna = await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/IdnaTestV2.json").then((x) => x.json());
1type Case = {
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
429const cases = casesraw.filter((v) => typeof v !== "string");
530const f = Bun.file(process.argv[2]!);
......@@ -82,39 +107,49 @@ pub fn parseIDNAPass(comptime input: []const u8, comptime output: []const u8) !v
82107`);
83108
84109w.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;
86113 w.write(`test { try parseFail("${stringEscape(c.input)}", null); }\n`);
87114}
88115
89116w.write(`\n`);
90117// prettier-ignore
91118if (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;
93122 w.write(`test { try parseFail("${stringEscape(c.input)}", "${stringEscape(c.base!)}"); }\n`);
94123}
95124
96125w.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;
98129 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`);
99130}
100131
101132w.write(`\n`);
102133// prettier-ignore
103134if (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;
105138 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`);
106139}
107140
108141w.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")) {
110143 if (c.input.length === 0) continue;
144 if (c.output !== null) continue;
111145 w.write(`test { try parseIDNAFail("${stringEscape(c.input)}"); }\n`);
112146}
113147
114148w.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")) {
116150 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`);
118153}
119154
120155w.flush();