Files
ww/test/lang/tuple_index_read_test.ww
Hojun-Cho 83f5956df2 test: banner purge + WHY-only comment sweep (rule 8)
Every section banner dies (103 -> 0) across test/lang, the observer
suites, the C carriers, and the five comment-heavy corpus fixtures;
banner provenance (#N cites, carrier numbers, repair-cluster labels)
folded into headers or adjacent WHY comments. Narration deleted; row
provenance, ref cites, divergence pins, and layout contracts kept
(fwd-ref decl-order guards and bootstrap-gate corpus rationale
restored where the sweep over-cut). Comment-only proven: all 3742
wwbuild workdir .s byte-identical before/after; test-commit and
test-byteid (161 lang + 1399 data, 0 pinned-divergent) green.
2026-08-08 21:40:23 +09:00

62 lines
1.8 KiB
Plaintext

// #121: const-slice tuple-element READ. Migrated from
// test/wcc/947_tuple_index_read_run.c.
//
// Three legs of indexed-tuple read off a `const [](str,*fn)` (fold-6's
// charclass_map shape), all sharing the &tbl[i] place-spine (#116):
//
// field_read — direct `tbl[i].N` field read, was LOUD both stages.
// whole_element — `let e = tbl[i]` then read e.N, was SILENT both-wrong-
// IDENTICAL (#263, word0-only truncation). The runtime read-
// back with DISTINCT-per-row values is the net: a wrong word
// is CAUGHT, not masked.
// store_roundtrip — write-face: a tuple-LITERAL store `a[i] = (3,4)`, read
// back whole; DISTINCT words per row catch the word0-only
// store.
//
// The for-range-over-module-global LOUD-STOP reject row migrated to
// test/wcc/data/tupidx_forrange_global_loud/case.ww (K_BUILDERR). Every value
// row's cs==ww .s byte-id rides T2 (test-lang-byteid).
package tuple_index_read_test;
fn fa(c: rune) bool = { return c == 'a'; };
fn fz(c: rune) bool = { return c == 'z'; };
const tbl: [](str, *fn(c: rune) bool) = [("ab", &fa), ("cdef", &fz)];
@test fn field_read() void = {
let s1 = tbl[1].0;
let s0 = tbl[0].0;
assert(len(s1) == 4);
assert(len(s0) == 2);
let f1 = tbl[1].1;
assert((*f1)('z'));
assert(!((*f1)('a')));
let f0 = tbl[0].1;
assert((*f0)('a'));
assert(!((*f0)('z')));
};
@test fn whole_element() void = {
let e = tbl[1];
assert(len(e.0) == 4);
assert((*e.1)('z'));
assert(!((*e.1)('a')));
let e0 = tbl[0];
assert(len(e0.0) == 2);
assert((*e0.1)('a'));
assert(!((*e0.1)('z')));
};
@test fn store_roundtrip() void = {
let a: [2](u64, u64);
a[1] = (3u64, 4u64);
a[0] = (7u64, 9u64);
let t = a[1];
assert(t.0 == 3);
assert(t.1 == 4);
let s = a[0];
assert(s.0 == 7);
assert(s.1 == 9);
};