Continue fold-2 (after 374e97b): migrate the remaining Family-1 str/slice
global + literal + index + call-arg group 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 9 (434->425). All asserts are primitive int/u8/bool comparisons (no
fmt/strconv in the assert path); the slice-store/index rows reset the global
each fn and sum ADJACENT elements so a dropped/mis-strided/over-wide word FAILS.
989_globslicefield_run.c -> glob_slice_field_test.ww (slice field of a global struct: g.f=<slice> stores full 24B header; len/cap/non-zero-offset + str/scalar controls)
989_globstrslice_run.c -> glob_str_slice_arg_test.ww (global str sliced with default hi passed as call arg loads its len word; explicit-hi control)
989_trystr_run.c -> try_str_unwrap_test.ww (`!` unwrap of str-success tagged union shuffles the str header for ident-source/error-first/success-first)
797_len_strglobal_run.c -> len_str_global_test.ww (len(str-global) loads .len via name(SB); local-str control)
801_litstr_pseudo_run.c -> lit_str_pseudo_test.ww (string-literal .len/.ptr pseudo-field; empty/multibyte + arg-passthrough)
803_globalidx_run.c -> global_index_test.ww (global str/slice index read/addr-of/store/compound, esz 1/4; local regression pins)
903_tuple_elem_slice_len.c -> tuple_elem_slice_len_test.ww (len(t.N) of a slice/str tuple element loads .len at +8; 2/3-slice, str-slice both orders)
927_composite_call_arg_run.c-> composite_call_arg_test.ww (slice-returning CALL passed inline as a composite arg; canonical/letslice/two-call/middle/nested/scalar/tagged)
952_slicecopy_assign_run.c -> slice_copy_assign_test.ww (bulk slice-copy-assign `arr[lo:hi]=bs`, esz 1/4, field/via-ptr/local bases; reslice-read companion)
rd_reslice asserts the TRUE value 360 (the .c twin's want=104 was 360 & 0xFF,
an exit-code truncation). 723_composite_call_arg.c's comment repointed to the
new test/lang location. 802_lenidx_run.c is DEFERRED (it carries //ww:error
reject rows — needs a value-rows-only split + a slim reject carrier, a fold-3
pass). Bump LANGBYTEID_EXPECTED_MIN 22->31 to ratchet the new corpus floor.
65 lines
1.9 KiB
Plaintext
65 lines
1.9 KiB
Plaintext
// tuple_elem_slice_len_test — `len(t.N)` where t is a tuple and t.N is a
|
|
// slice/str-typed element, migrated from test/wcc/903_tuple_elem_slice_len_run.c
|
|
// (#235). The len() builtin special-cased only a PLAIN N_IDENT slice operand
|
|
// and an array operand; every other shape fell back to a bare `cgexpr(operand)`,
|
|
// which for a slice leaves AX=.ptr. A tuple-element read (`t.N`) loads only
|
|
// AX=.ptr, so `len(t.N)` returned the slice's .ptr word AS the length — a SILENT
|
|
// miscompile, gate-blind because the bootstrap never does len() on a
|
|
// slice-typed tuple element. The fix (both stages, byte-id) loads the element's
|
|
// .len word directly at BP + tuple_off + element_off + 8. Every element has a
|
|
// DISTINCT length so a dropped/wrong field is caught. Tuples are slice/str-ONLY
|
|
// here — a leading scalar element exercises a separate mixed-tuple sret
|
|
// divergence (filed apart, out of scope).
|
|
|
|
package tuple_elem_slice_len_test;
|
|
|
|
fn mk2() ([]u8, []u8) = {
|
|
let a: []u8; a.len = 3; a.cap = 7;
|
|
let b: []u8; b.len = 5; b.cap = 9;
|
|
return (a, b);
|
|
};
|
|
|
|
fn mk3() ([]u8, []u8, []u8) = {
|
|
let a: []u8; a.len = 3; a.cap = 7;
|
|
let b: []u8; b.len = 5; b.cap = 9;
|
|
let c: []u8; c.len = 11; c.cap = 13;
|
|
return (a, b, c);
|
|
};
|
|
|
|
fn mksb() (str, []u8) = {
|
|
let s: str = "abcd";
|
|
let b: []u8; b.len = 6; b.cap = 8;
|
|
return (s, b);
|
|
};
|
|
|
|
fn mkbs() ([]u8, str) = {
|
|
let b: []u8; b.len = 7; b.cap = 9;
|
|
let s: str = "hi";
|
|
return (b, s);
|
|
};
|
|
|
|
@test fn two_slice() void = {
|
|
let t: ([]u8, []u8) = mk2();
|
|
assert(len(t.0): i32 == 3);
|
|
assert(len(t.1): i32 == 5);
|
|
};
|
|
|
|
@test fn three_slice() void = {
|
|
let t: ([]u8, []u8, []u8) = mk3();
|
|
assert(len(t.0): i32 == 3);
|
|
assert(len(t.1): i32 == 5);
|
|
assert(len(t.2): i32 == 11);
|
|
};
|
|
|
|
@test fn str_slice() void = {
|
|
let t: (str, []u8) = mksb();
|
|
assert(len(t.0): i32 == 4);
|
|
assert(len(t.1): i32 == 6);
|
|
};
|
|
|
|
@test fn slice_str() void = {
|
|
let t: ([]u8, str) = mkbs();
|
|
assert(len(t.0): i32 == 7);
|
|
assert(len(t.1): i32 == 2);
|
|
};
|