test: migrate defdim len/cap family to test/lang @test, retire C twins (fold-2)
Continue fold-2: migrate drew's Family 2 (def-dimensioned array len/cap/slice resolution) from bespoke build+run C twins to test/lang @test, retiring each twin in the same commit. Runtime coverage MOVES from $(TESTS) to test-lang (T1 runs+asserts via `ww test`) + test-lang-byteid (T2 keeps cs==ww .s byte-id); coverage is preserved, the $(TESTS) headline drops 3 (425->422). All asserts are primitive int comparisons (no fmt/strconv in the assert path); the defcap rows poison cap != len and assert both words so a dropped cap word FAILS. 989_defdim_field_run.c -> defdim_field_test.ww (`.len` field-read on a def-dim [MAX]T resolves from the type table: local/let-global/def cgdot arms + sum) 989_defdim_slice_run.c -> defdim_slice_test.ww (slicing a def-dim [MAX]T resolves len AND cap from the type table: default-hi + cgbasecap, local+global) 989_defdim_argslice_run.c -> defdim_argslice_test.ww (def-dim slice passed as a call arg resolves default-hi len in the N_SLICE arg-push arms; litctrl pins the N_INTLIT path) Bump LANGBYTEID_EXPECTED_MIN 31->34 to ratchet the new corpus floor.
This commit is contained in:
35
test/lang/defdim_argslice_test.ww
Normal file
35
test/lang/defdim_argslice_test.ww
Normal file
@@ -0,0 +1,35 @@
|
||||
// defdim_argslice_test — passing a slice of a `def`-dimensioned array
|
||||
// (`take(buf[1:])` on `[MAX]T`) as a call argument must resolve the default-hi
|
||||
// length from the type table, the N_SLICE arg-push member of the def-dim
|
||||
// family, migrated from test/wcc/989_defdim_argslice_run.c (#56 c4). pushargsrev's
|
||||
// N_SLICE default-hi arms (local / global) only handled an N_INTLIT dim, so a
|
||||
// plain `[MAX]u8` base emitted nothing and the pushed slice header's len word
|
||||
// was left stale -- the callee read garbage (ww 135 local / 255 global). The
|
||||
// fix reads alen from the stamped array tinfo (rule-13) in both arg-push arms.
|
||||
// `take` returns s.len, so the asserted 4 IS the pushed-header length contract;
|
||||
// the litctrl row pins the N_INTLIT path so the new else-arm can't perturb it.
|
||||
// T2 (test-lang-byteid) keeps the cs==ww net the .c twin's run-compare gave.
|
||||
|
||||
package defdim_argslice_test;
|
||||
|
||||
def MAX: i32 = 5;
|
||||
let g: [MAX]u8 = [1, 2, 3, 4, 5];
|
||||
|
||||
fn take(s: []u8) i32 = { return s.len: i32; };
|
||||
|
||||
@test fn local_argslice() void = {
|
||||
// local def-dim base: take(buf[1:]) sees len 5-1 = 4.
|
||||
let buf: [MAX]u8 = [1, 2, 3, 4, 5];
|
||||
assert(take(buf[1:]) == 4);
|
||||
};
|
||||
|
||||
@test fn global_argslice() void = {
|
||||
// global def-dim base: take(g[1:]) sees len 4.
|
||||
assert(take(g[1:]) == 4);
|
||||
};
|
||||
|
||||
@test fn litctrl_argslice() void = {
|
||||
// literal-dim control: the N_INTLIT arm stays correct (no regress).
|
||||
let buf: [5]u8 = [1, 2, 3, 4, 5];
|
||||
assert(take(buf[1:]) == 4);
|
||||
};
|
||||
Reference in New Issue
Block a user