Files
ww/test/lang/idx_compound_test.ww
Hojun-Cho af3c49a4c7 test: migrate 948_idx_compound to @test + runww rejects, retire C twin (fold-3)
#133 indexed-scalar compound-assign. The 21 rows split by observability:
18 value rows -> test/lang/idx_compound_test.ww (one @test fn each,
primitive-only asserts, slot-poison + neighbor-unchanged read-back);
3 reject rows -> test/wcc/data/idx_compound_{float_indexed,str_indexed,
chained_ptr_float}/case.ww as //ww:error, asserting BOTH stages reject on
the shared diagnostic body (cstage's leading prefix excluded). The C twin
is retired; its coverage is a strict superset of the original rows.

First reject-bearing fold-3 migration -- validates the runww dual-stage
home end to end. LANGBYTEID_EXPECTED_MIN 49 -> 50.
2026-06-22 16:02:01 +09:00

142 lines
3.3 KiB
Plaintext

// idx_compound_test — indexed-scalar compound-assign (#133), migrated from
// test/wcc/948_idx_compound_run.c. A compound assign on an indexed lvalue
// (`arr[i] OP= v`) must do a real LOAD-OP-STORE, not silently demote `OP=` to
// `=` (cstage's prior bug) nor emit NOTHING (wwstage's prior bug). Every row
// init-poisons the target slot with a value != the expected result (so a
// dropped/demoted op is caught by value), runs the op, and reads back the FULL
// element. Narrow-width rows also assert an UNTOUCHED neighbor to catch an
// over-wide store. PRIMITIVE-only asserts (no fmt/strconv) so a co-miscompile
// in the assert path cannot mask the bug. The matrix covers + - * & | ^ / % <<
// >> across u8/i32/i64/u32 elements and a slice base; the plain-assign control
// pins the ASSIGN path the fix must leave unchanged. T2 keeps the cs==ww net.
package idx_compound_test;
@test fn u8_pluseq() void = {
let a: [4]u8 = [10u8, 20u8, 30u8, 40u8];
a[0] += 1u8;
assert(a[0] == 11u8);
assert(a[1] == 20u8);
};
@test fn u8_minuseq() void = {
let a: [4]u8 = [10u8, 20u8, 30u8, 40u8];
a[2] -= 5u8;
assert(a[2] == 25u8);
assert(a[3] == 40u8);
};
@test fn u8_stareq() void = {
let a: [4]u8 = [7u8, 0u8, 0u8, 0u8];
a[0] *= 3u8;
assert(a[0] == 21u8);
assert(a[1] == 0u8);
};
@test fn u8_ampeq() void = {
let a: [4]u8 = [0xF3u8, 0u8, 0u8, 0u8];
a[0] &= 0x0Fu8;
assert(a[0] == 3u8);
assert(a[1] == 0u8);
};
@test fn u8_pipeeq() void = {
let a: [4]u8 = [0x10u8, 0u8, 0u8, 0u8];
a[0] |= 0x07u8;
assert(a[0] == 23u8);
assert(a[1] == 0u8);
};
@test fn u8_careteq() void = {
let a: [4]u8 = [0xAAu8, 0u8, 0u8, 0u8];
a[0] ^= 0xFFu8;
assert(a[0] == 85u8);
assert(a[1] == 0u8);
};
@test fn i32_pluseq() void = {
let a: [4]i32 = [100, 200, 300, 400];
a[1] += 50;
assert(a[1] == 250);
assert(a[2] == 300);
};
@test fn i64_pluseq() void = {
let a: [4]i64 = [100i64, 200i64, 300i64, 400i64];
a[0] += 34i64;
assert(a[0] == 134i64);
assert(a[1] == 200i64);
};
@test fn u32_idx3_pluseq() void = {
let a: [4]u32 = [10u32, 20u32, 50u32, 100u32];
a[3] += 7u32;
assert(a[3] == 107u32);
assert(a[2] == 50u32);
};
@test fn slice_pluseq() void = {
let buf: [4]u8 = [11u8, 22u8, 33u8, 44u8];
let s: []u8 = buf[0:4];
s[1] += 8u8;
assert(s[1] == 30u8);
assert(s[0] == 11u8);
assert(buf[1] == 30u8);
};
@test fn plain_assign_ctrl() void = {
let a: [4]u8 = [10u8, 20u8, 30u8, 40u8];
a[1] = 99u8;
assert(a[1] == 99u8);
assert(a[0] == 10u8);
};
@test fn i32_slasheq() void = {
let a: [4]i32 = [100, 200, 300, 400];
a[0] /= 4;
assert(a[0] == 25);
assert(a[1] == 200);
};
@test fn u32_slasheq() void = {
let a: [4]u32 = [100u32, 200u32, 300u32, 400u32];
a[0] /= 4u32;
assert(a[0] == 25u32);
assert(a[1] == 200u32);
};
@test fn i32_percenteq() void = {
let a: [4]i32 = [17, 0, 0, 0];
a[0] %= 5;
assert(a[0] == 2);
assert(a[1] == 0);
};
@test fn u32_percenteq() void = {
let a: [4]u32 = [100u32, 0u32, 0u32, 0u32];
a[0] %= 7u32;
assert(a[0] == 2u32);
assert(a[1] == 0u32);
};
@test fn i32_lshifteq() void = {
let a: [4]i32 = [3, 0, 0, 0];
a[0] <<= 4;
assert(a[0] == 48);
assert(a[1] == 0);
};
@test fn u32_rshifteq() void = {
let a: [4]u32 = [200u32, 0u32, 0u32, 0u32];
a[0] >>= 2u32;
assert(a[0] == 50u32);
assert(a[1] == 0u32);
};
@test fn i32_rshifteq_pos() void = {
let a: [4]i32 = [200, 0, 0, 0];
a[0] >>= 2;
assert(a[0] == 50);
assert(a[1] == 0);
};