| ... | ... | @@ -1,5 +1,30 @@ |
| 1 | | const casesraw = await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/urltestdata.json").then((x) => x.json()); |
| 2 | | const casesidna = await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/IdnaTestV2.json").then((x) => x.json()); |
| 1 | type 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 | }; |
| 17 | type CaseFail = { |
| 18 | input: string; |
| 19 | base: string | null; |
| 20 | failure: true; |
| 21 | }; |
| 22 | type CaseIDNA = { |
| 23 | input: string; |
| 24 | output: string | null; |
| 25 | }; |
| 26 | const casesraw = (await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/urltestdata.json").then((x) => x.json())) as (string | Case | CaseFail)[]; |
| 27 | const casesidna = (await fetch("https://github.com/web-platform-tests/wpt/raw/master/url/resources/IdnaTestV2.json").then((x) => x.json())) as (string | CaseIDNA)[]; |
| 3 | 28 | |
| 4 | 29 | const cases = casesraw.filter((v) => typeof v !== "string"); |
| 5 | 30 | const f = Bun.file(process.argv[2]!); |
| ... | ... | @@ -82,39 +107,49 @@ pub fn parseIDNAPass(comptime input: []const u8, comptime output: []const u8) !v |
| 82 | 107 | `); |
| 83 | 108 | |
| 84 | 109 | w.write(`\n`); |
| 85 | | for (const c of cases.filter((v) => v.base == null && !!v.failure)) { |
| 110 | for (const c of cases) { |
| 111 | if (c.base !== null) continue; |
| 112 | if (!c.failure) continue; |
| 86 | 113 | w.write(`test { try parseFail("${stringEscape(c.input)}", null); }\n`); |
| 87 | 114 | } |
| 88 | 115 | |
| 89 | 116 | w.write(`\n`); |
| 90 | 117 | // prettier-ignore |
| 91 | 118 | if (false) |
| 92 | | for (const c of cases.filter((v) => v.base != null && !!v.failure)) { |
| 119 | for (const c of cases) { |
| 120 | if (c.base === null) continue; |
| 121 | if (!c.failure) continue; |
| 93 | 122 | w.write(`test { try parseFail("${stringEscape(c.input)}", "${stringEscape(c.base!)}"); }\n`); |
| 94 | 123 | } |
| 95 | 124 | |
| 96 | 125 | w.write(`\n`); |
| 97 | | for (const c of cases.filter((v) => v.base == null && !v.failure)) { |
| 126 | for (const c of cases) { |
| 127 | if (c.base !== null) continue; |
| 128 | if (c.failure) continue; |
| 98 | 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 | } |
| 100 | 131 | |
| 101 | 132 | w.write(`\n`); |
| 102 | 133 | // prettier-ignore |
| 103 | 134 | if (false) |
| 104 | | for (const c of cases.filter((v) => v.base != null && !v.failure)) { |
| 135 | for (const c of cases) { |
| 136 | if (c.base === null) continue; |
| 137 | if (c.failure) continue; |
| 105 | 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 | } |
| 107 | 140 | |
| 108 | 141 | w.write(`\n`); |
| 109 | | for (const c of casesidna.filter((v) => typeof v !== "string").filter((v) => v.output === null)) { |
| 142 | for (const c of casesidna.filter((v) => typeof v !== "string")) { |
| 110 | 143 | if (c.input.length === 0) continue; |
| 144 | if (c.output !== null) continue; |
| 111 | 145 | w.write(`test { try parseIDNAFail("${stringEscape(c.input)}"); }\n`); |
| 112 | 146 | } |
| 113 | 147 | |
| 114 | 148 | w.write(`\n`); |
| 115 | | for (const c of casesidna.filter((v) => typeof v !== "string").filter((v) => v.output !== null)) { |
| 149 | for (const c of casesidna.filter((v) => typeof v !== "string")) { |
| 116 | 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 | } |
| 119 | 154 | |
| 120 | 155 | w.flush(); |