// match_slice_variant_test — a `(scalar | []T)` match must select the right arm // and preserve the slice payload (len + first byte) across u8/i8/i32/u64/rune, // in both variant orders, and compose with a trailing str arm. Migrated from // test/wcc/926_match_slice_variant_run.c (value rows, cs==ww byte-id). package match_slice_variant_test; fn pick_u8(n: (u8 | []u8)) i32 = { match (n) { case let c: u8 => return c: i32; case let s: []u8 => return 100i32 + (s.len: i32) + (s[0]: i32); }; return -1; }; fn pick_slice_first(n: ([]u8 | u8)) i32 = { match (n) { case let s: []u8 => return 100i32 + (s.len: i32) + (s[0]: i32); case let c: u8 => return c: i32; }; return -1; }; fn pick_i8(n: (i8 | []i8)) i32 = { match (n) { case let c: i8 => return c: i32; case let s: []i8 => return 100i32 + (s.len: i32) + (s[0]: i32); }; return -1; }; fn pick_i32(n: (i32 | []i32)) i32 = { match (n) { case let c: i32 => return c; case let s: []i32 => return 1000i32 + (s.len: i32) + s[0]; }; return -1; }; fn pick_u64(n: (u64 | []u64)) i32 = { match (n) { case let c: u64 => return c: i32; case let s: []u64 => return 1000i32 + (s.len: i32) + (s[0]: i32); }; return -1; }; fn pick_rune(n: (rune | []rune)) i32 = { match (n) { case let r: rune => return r: i32; case let s: []rune => return 1000i32 + (s.len: i32) + (s[0]: i32); }; return -1; }; fn pick3(n: (u8 | []u8 | str)) i32 = { match (n) { case let c: u8 => return c: i32; case let s: []u8 => return 200i32 + (s.len: i32) + (s[0]: i32); case let t: str => return 300i32 + (t.len: i32); }; return -1; }; @test fn u8_slice_u8() void = { let buf: [3]u8; buf[0] = 7u8; buf[1] = 8u8; buf[2] = 9u8; assert(pick_u8(42u8) == 42); assert(pick_u8(buf[0:3]) == 110); }; @test fn slice_u8_then_u8() void = { let buf: [3]u8; buf[0] = 7u8; buf[1] = 8u8; buf[2] = 9u8; assert(pick_slice_first(buf[0:3]) == 110); assert(pick_slice_first(42u8) == 42); }; @test fn i8_slice_i8() void = { let buf: [2]i8; buf[0] = 5i8; buf[1] = 6i8; assert(pick_i8(11i8) == 11); assert(pick_i8(buf[0:2]) == 107); }; @test fn i32_slice_i32() void = { let buf: [2]i32; buf[0] = 33i32; buf[1] = 44i32; assert(pick_i32(77i32) == 77); assert(pick_i32(buf[0:2]) == 1035); }; @test fn u64_slice_u64() void = { let buf: [2]u64; buf[0] = 41u64; buf[1] = 42u64; assert(pick_u64(99u64) == 99); assert(pick_u64(buf[0:2]) == 1043); }; @test fn rune_slice_rune() void = { let buf: [2]rune; buf[0] = 'a'; buf[1] = 'b'; assert(pick_rune('Z') == 90); assert(pick_rune(buf[0:2]) == 1099); }; @test fn u8_slice_u8_str() void = { let buf: [3]u8; buf[0] = 1u8; buf[1] = 2u8; buf[2] = 3u8; let a: i32 = pick3(5u8); let b: i32 = pick3(buf[0:3]); let c: i32 = pick3("hi"); assert(a == 5); assert(b == 204); assert(c == 302); };