mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
test(wasm): consolidate WABT output and glue scanner checks (#12822)
test(wasm): consolidate WABT and glue parser checks
This commit is contained in:
1 parent
0f9ec0e44b
commit
c11e73bd64
1 file changed
+36
-38
+36
-38
@@ -49,10 +49,12 @@ it("corroborates a blank custom name with bounded invalid UTF-8 bytes", () => {
|
||||
});
|
||||
it("retains real WABT section ranges, custom section identity and original header output", async () => {
|
||||
const text = await golden();
|
||||
const headers = text.slice(0, text.indexOf("Section Details:\n"));
|
||||
expect(parseWabtOutput(text, 76, ["test"]).sections).toHaveLength(7);
|
||||
expect(parseWabtOutput(text, 76, ["test"]).headers).toBe(headers);
|
||||
expect(parseWabtOutput(text, 76, ["test"]).sections.at(-1)).toEqual({
|
||||
const parsed = parseWabtOutput(text, 76, ["test"]);
|
||||
expect(parsed.sections).toHaveLength(7);
|
||||
expect(parsed.headers).toBe(
|
||||
text.slice(0, text.indexOf("Section Details:\n")),
|
||||
);
|
||||
expect(parsed.sections.at(-1)).toEqual({
|
||||
kind: "Custom",
|
||||
start: 64,
|
||||
end: 76,
|
||||
@@ -428,41 +430,37 @@ it("retains directive literals and matches their cooked escaped path", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it.each(["\n", "\r", "\r\n", "\u2028", "\u2029"])(
|
||||
"retains complete .wasm query and fragment literals containing %j",
|
||||
(separator) => {
|
||||
it.each([
|
||||
["\n", 2],
|
||||
["\r", 2],
|
||||
["\r\n", 2],
|
||||
// JSON.stringify leaves LS and PS literal, so they advance the source line.
|
||||
["\u2028", 3],
|
||||
["\u2029", 3],
|
||||
] as const)(
|
||||
"keeps query and fragment line breaks outside the .wasm path check: %j",
|
||||
(separator, fragmentLine) => {
|
||||
const path = "https://example.invalid/module.wasm";
|
||||
const candidates = ["/artifacts/module.wasm", "/other/module.wasm"];
|
||||
for (const qualifier of ["?query=", "#fragment="]) {
|
||||
const value = `https://example.invalid/module.wasm${qualifier}a${separator}b`;
|
||||
const result = associateWasmGlue(
|
||||
`fetch(${JSON.stringify(value)});`,
|
||||
"/artifacts/glue.js",
|
||||
candidates,
|
||||
);
|
||||
expect(result).toEqual({
|
||||
parse_status: "complete",
|
||||
references: [
|
||||
{
|
||||
value,
|
||||
line: 1,
|
||||
column: 6,
|
||||
candidate_paths: candidates,
|
||||
association: "basename-candidates",
|
||||
evidence_kind: "static-literal",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["\n", "\r", "\r\n", "\u2028", "\u2029"])(
|
||||
"does not accept a path-ending separator without a query or fragment: %j",
|
||||
(separator) => {
|
||||
const value = `https://example.invalid/module.wasm${separator}`;
|
||||
expect(
|
||||
associateWasmGlue(`fetch(${JSON.stringify(value)});`, "/glue.js", []),
|
||||
).toEqual({ parse_status: "complete", references: [] });
|
||||
const query = `${path}?query=a${separator}b`;
|
||||
const fragment = `${path}#fragment=a${separator}b`;
|
||||
const source = [query, fragment, path + separator]
|
||||
.map((value) => `fetch(${JSON.stringify(value)});`)
|
||||
.join("\n");
|
||||
const result = associateWasmGlue(source, "/artifacts/glue.js", candidates);
|
||||
expect(result).toEqual({
|
||||
parse_status: "complete",
|
||||
references: [
|
||||
{ value: query, line: 1 },
|
||||
{ value: fragment, line: fragmentLine },
|
||||
].map((reference) => ({
|
||||
...reference,
|
||||
column: 6,
|
||||
candidate_paths: candidates,
|
||||
association: "basename-candidates",
|
||||
evidence_kind: "static-literal",
|
||||
})),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user