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

@@ -21,12 +21,10 @@
// the regex/capture struct shapes, and finish(). A failing row aborts
// via the assert/abort builtin (task #5 @test conversion).
//
// Struct literals below name the type UNQUALIFIED (`inst_charset { … }`,
// not `regex.inst_charset { … }`): the parser rejects a module-qualified
// name in struct-literal position (#29), and the imported EXPORTED type
// is in scope unqualified. These reach only exported types — the #29
// axis, distinct from the white-box privacy boundary handled by the
// whitebox_test.ww split above.
// The parser rejects a qualified name in struct-literal position (#29), so
// the few struct payload rows below initialize a qualified typed local before
// injecting it into the exported union. This stays distinct from the
// white-box privacy boundary handled by the whitebox_test.ww split above.
package regex_test;
import regex;
@@ -107,7 +105,10 @@ import strings;
// inst_charset carries a struct payload; its fields survive the union
// round-trip.
@test fn charset_payload() void = {
let c: regex.inst = (inst_charset { idx = 3, is_positive = true });
let value: regex.inst_charset;
value.idx = 3;
value.is_positive = true;
let c: regex.inst = value;
match (c) {
case let cs: regex.inst_charset => {
assert(!(cs.idx != (3: size)));
@@ -123,9 +124,12 @@ import strings;
// diverges cs≠ww (#26 — the wwstage frames it wider), so
// asserting the bounds here would seed a rule-10-divergent fixture.
@test fn repeat_payload() void = {
let r: regex.inst = (inst_repeat {
id = 1, origin = 4, min = (2: size), max = void,
});
let value: regex.inst_repeat;
value.id = 1;
value.origin = 4;
value.min = (2: size);
value.max = void;
let r: regex.inst = value;
match (r) {
case let rp: regex.inst_repeat => {
assert(!(rp.id != (1: size)));
@@ -138,13 +142,12 @@ import strings;
// The regex/capture structs hold their fields; finish() is a no-op
// (no-free runtime) and must accept a built regex.
@test fn struct_shapes_and_finish() void = {
let cap: regex.capture = capture {
content = "abc",
start = 0,
start_bytesize = 0,
end = 3,
end_bytesize = 3,
};
let cap: regex.capture;
cap.content = "abc";
cap.start = 0;
cap.start_bytesize = 0;
cap.end = 3;
cap.end_bytesize = 3;
assert(!(cap.content.len != 3));
assert(!(cap.end != (3: size)));
@@ -256,15 +259,18 @@ import strings;
// the documented no-op (no-free runtime), so the header must stay
// readable after — a future real free changes this row consciously.
// The local is spelled []regex.capture, not the regex.result alias:
// wwstage falsely loud-bails appending a struct literal onto an
// alias-typed dst (#20); the alias + signature stay exercised by the
// result_free call itself. Reverts to `regex.result` when #20 lands.
// wwstage falsely loud-bails appending a capture value onto an alias-typed
// dst (#20); the alias + signature stay exercised by result_free itself.
// Reverts to `regex.result` when #20 lands.
@test fn result_free_noop() void = {
let res: []regex.capture;
append(res, capture {
content = "x", start = 0, start_bytesize = 0,
end = 1, end_bytesize = 1,
});
let value: regex.capture;
value.content = "x";
value.start = 0;
value.start_bytesize = 0;
value.end = 1;
value.end_bytesize = 1;
append(res, value);
regex.result_free(res);
assert(!(len(res) != 1));
assert(!(res[0].end != (1: size)));
@@ -872,16 +878,16 @@ type cerow = struct {
// class items as -2 (presence sentinel — fn-ptr address not stable).
// The element binds structurally, not via the `charset` alias — an
// alias-typed slice local's index read mis-scales in wwstage (#68).
fn cssig(cs: [](charset_lit_item | charset_range_item |
charset_class_item), k: size) i64 = {
let cur: (charset_lit_item | charset_range_item |
charset_class_item) = cs[k];
fn cssig(cs: [](regex.charset_lit_item | regex.charset_range_item |
regex.charset_class_item), k: size) i64 = {
let cur: (regex.charset_lit_item | regex.charset_range_item |
regex.charset_class_item) = cs[k];
match (cur) {
case let l: charset_lit_item =>
case let l: regex.charset_lit_item =>
return 1000000 + ((l: rune): i64);
case let range: charset_range_item =>
case let range: regex.charset_range_item =>
return (range.0: i64) * 10000 + (range.1: i64);
case charset_class_item => return -2; // fn-ptr address not stable
case regex.charset_class_item => return -2; // fn-ptr address not stable
case => return -1;
};
};
@@ -928,8 +934,8 @@ type cscase = struct {
match (c) {
case let re: regex.regex => {
assert(!(re.charsets.len != 1));
let cs0: [](charset_lit_item | charset_range_item |
charset_class_item) = re.charsets[0];
let cs0: [](regex.charset_lit_item | regex.charset_range_item |
regex.charset_class_item) = re.charsets[0];
assert(!((len(cs0): i32) != rows[i].ecnt));
let k: i32 = 0;
for (k < rows[i].ecnt) {
@@ -1715,8 +1721,8 @@ type smcase = struct {
match (c) {
case let re: regex.regex => {
assert(!(re.charsets.len != 1));
let cs0: [](charset_lit_item | charset_range_item |
charset_class_item) = re.charsets[0];
let cs0: [](regex.charset_lit_item | regex.charset_range_item |
regex.charset_class_item) = re.charsets[0];
assert(!((len(cs0): i32) != 1));
assert(!(cssig(cs0, 0) != -2));
regex.finish(&re);