test: prove ordinary import binding modes

This commit is contained in:
2026-08-14 10:56:54 +09:00
parent 792b6ecbe5
commit 10e02a00ee
20 changed files with 1284 additions and 672 deletions

View File

@@ -75,6 +75,31 @@ fn astrow(label: str, src: str, needles: []str) void = {
testenv.clean(td);
};
fn rejectrow(label: str, src: str, needle: str) void = {
let td: str = testenv.fresh();
testenv.writefile(strings.concat(td, "/a.ww"), src);
let tools: []str = ["wwdump", "wwdump_ww"];
let stages: []str = ["cstage", "wwstage"];
let errors: []str = ["", ""];
let i: i32 = 0;
for (i < tools.len) {
let av: []str = [testenv.driver(tools[i]), "-a",
strings.concat(td, "/a.ww")];
let co: testenv.commandout;
testenv.runcommand(td, td, stages[i], av, tmo(), &co);
if (co.termination != exec.termination.EXIT || co.code == 0
|| !testenv.has(co.stderr, needle)) {
fail(label, strings.concat(stages[i], " accepted rejected import"));
};
errors[i] = strings.dup(co.stderr);
i += 1;
};
if (!testenv.same(errors[0], errors[1])) {
fail(label, "cs/ww parse diagnostics DIFFER");
};
testenv.clean(td);
};
@test fn astproof() void = {
let trailing: []str = ["(dot \"x\"", "(structlit",
"(tname \"pkg.point\""];
@@ -92,4 +117,19 @@ fn astrow(label: str, src: str, needles: []str) void = {
"\tlet v: i64 = a.b.C { x = 1i64 }.x;\n",
"\treturn v;\n",
"};\n"), multilevel);
let ordinary: []str = ["(use \"codec\""];
astrow("ordinary-import", strings.concat(
"package main;\n",
"import acme.codec;\n",
"fn main() i32 = { return 0; };\n"), ordinary);
let aliased: []str = ["(use \"stable\""];
astrow("aliased-import", strings.concat(
"package main;\n",
"import stable acme.codec;\n",
"fn main() i32 = { return 0; };\n"), aliased);
rejectrow("blank-alias", strings.concat(
"package main;\n",
"import _ acme.codec;\n",
"fn main() i32 = { return 0; };\n"),
"blank import alias _ is not implemented");
};