Files
ww/lib/encoding/utf8/rune_test.ww
Hojun-Cho aadc6618f0 lib: banner purge + WHY-only comment sweep (rule 8)
Every // ---- section banner dies (132 -> 0): names carry the WHAT.
Narration deleted (filename restatements, run-with lines, what-the-
next-line-does); every ref/hare cite, task cite, divergence, ABI/
layout contract, and ownership qualifier kept (borrowed-view lines
restored where the sweep over-cut). Comment-only proven: all 442
walk-workdir .s and 32 import-probe .s byte-identical before/after;
libbyteid 56-roster all-ID.
2026-08-08 21:10:18 +09:00

63 lines
2.1 KiB
Plaintext

// Vectors mirror ref/hare/encoding/utf8/rune.ha. A failing row aborts
// via the assert/abort builtin (task #5 @test conversion).
package utf8_test;
import encoding.utf8;
// ref/hare/encoding/utf8/rune.ha:5. Boundaries: 0x7F → 1, 0x80 → 2,
// 0x7FF → 2, 0x800 → 3, 0xFFFF → 3, 0x10000 → 4, 0x10FFFF → 4.
@test fn runesz_ranges() void = {
assert(!(utf8.runesz(0u32: rune) != 1));
assert(!(utf8.runesz(0x7Fu32: rune) != 1));
assert(!(utf8.runesz(0x80u32: rune) != 2));
assert(!(utf8.runesz(0x7FFu32: rune) != 2));
assert(!(utf8.runesz(0x800u32: rune) != 3));
assert(!(utf8.runesz(0xFFFFu32: rune) != 3));
assert(!(utf8.runesz(0x10000u32: rune) != 4));
assert(!(utf8.runesz(0x10FFFFu32: rune) != 4));
};
// ref/hare/encoding/utf8/rune.ha:15. ASCII → 1; legal multibyte
// leads → 2/3/4; continuation and >0xF7 → invalid.
@test fn utf8sz_classify() void = {
match (utf8.utf8sz(0u8)) {
case let n: i32 => { assert(!(n != 1)); };
case let e: utf8.invalid => { abort(); };
};
match (utf8.utf8sz(0x7Fu8)) {
case let n: i32 => { assert(!(n != 1)); };
case let e: utf8.invalid => { abort(); };
};
match (utf8.utf8sz(0x80u8)) { // continuation
case let n: i32 => { abort(); };
case let e: utf8.invalid => void;
};
match (utf8.utf8sz(0xC1u8)) { // overlong 2-byte lead
case let n: i32 => { abort(); };
case let e: utf8.invalid => void;
};
match (utf8.utf8sz(0xC2u8)) {
case let n: i32 => { assert(!(n != 2)); };
case let e: utf8.invalid => { abort(); };
};
match (utf8.utf8sz(0xE0u8)) {
case let n: i32 => { assert(!(n != 3)); };
case let e: utf8.invalid => { abort(); };
};
match (utf8.utf8sz(0xF0u8)) {
case let n: i32 => { assert(!(n != 4)); };
case let e: utf8.invalid => { abort(); };
};
match (utf8.utf8sz(0xF8u8)) { // 5-byte lead — illegal in modern UTF-8
case let n: i32 => { abort(); };
case let e: utf8.invalid => void;
};
match (utf8.utf8sz(0xFFu8)) {
case let n: i32 => { abort(); };
case let e: utf8.invalid => void;
};
};