Pure move: utf8_test.ww dissolves along its banner seams into sibling
rune_test.ww (runesz/utf8sz), encode_test.ww (encoderune),
decode_test.ww (decoder next/prev/validate/remaining/slice/position
plus the encode->decode round-trip), and types_test.ww (strerror),
mirroring ref/hare/encoding/utf8/{rune,encode,decode,types}.ha
ownership (types.ha:12 owns strerror). Blocks are byte-identical;
only the banner lines are deleted. The streq helper moves with its
sole consumer, strerror_cases, into types_test.ww. The impl utf8.ww
is untouched (no banners).
Consumers: Makefile LIBRARY_TESTS replaces the utf8_test.ww entry
with the four new entries at the same position; the
test/byteid/libbyteid_test.ww roster row becomes four fx rows,
NENTEXPECT 52->55 (+3).
64 lines
2.1 KiB
Plaintext
64 lines
2.1 KiB
Plaintext
// runetest — exercises utf8.runesz/utf8sz. A failing row aborts via
|
|
// the assert/abort builtin (task #5 @test conversion).
|
|
// Vectors mirror ref/hare/encoding/utf8/rune.ha.
|
|
|
|
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;
|
|
};
|
|
};
|