lib: split utf8 tests into rune/encode/decode/types per ref/hare/encoding/utf8
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).
This commit is contained in:
44
lib/encoding/utf8/encode_test.ww
Normal file
44
lib/encoding/utf8/encode_test.ww
Normal file
@@ -0,0 +1,44 @@
|
||||
// encodetest — exercises utf8.encoderune. A failing row aborts via
|
||||
// the assert/abort builtin (task #5 @test conversion).
|
||||
// Vectors mirror ref/hare/encoding/utf8/encode.ha.
|
||||
|
||||
package utf8_test;
|
||||
|
||||
import encoding.utf8;
|
||||
|
||||
// ref/hare/encoding/utf8/encode.ha:7. Byte vectors come from the
|
||||
// Unicode specification (UAX standard examples).
|
||||
|
||||
@test fn encode_ascii() void = {
|
||||
let out: [4]u8;
|
||||
let n: i32 = utf8.encoderune(out[0:4], 0x41u32: rune); // 'A'
|
||||
assert(!(n != 1));
|
||||
assert(!(out[0] != 0x41u8));
|
||||
};
|
||||
|
||||
@test fn encode_two_byte() void = {
|
||||
let out: [4]u8;
|
||||
let n: i32 = utf8.encoderune(out[0:4], 0xE9u32: rune); // 'é' U+00E9
|
||||
assert(!(n != 2));
|
||||
assert(!(out[0] != 0xC3u8));
|
||||
assert(!(out[1] != 0xA9u8));
|
||||
};
|
||||
|
||||
@test fn encode_three_byte() void = {
|
||||
let out: [4]u8;
|
||||
let n: i32 = utf8.encoderune(out[0:4], 0x20ACu32: rune); // '€' U+20AC
|
||||
assert(!(n != 3));
|
||||
assert(!(out[0] != 0xE2u8));
|
||||
assert(!(out[1] != 0x82u8));
|
||||
assert(!(out[2] != 0xACu8));
|
||||
};
|
||||
|
||||
@test fn encode_four_byte() void = {
|
||||
let out: [4]u8;
|
||||
let n: i32 = utf8.encoderune(out[0:4], 0x1F980u32: rune); // '🦀' U+1F980
|
||||
assert(!(n != 4));
|
||||
assert(!(out[0] != 0xF0u8));
|
||||
assert(!(out[1] != 0x9Fu8));
|
||||
assert(!(out[2] != 0xA6u8));
|
||||
assert(!(out[3] != 0x80u8));
|
||||
};
|
||||
Reference in New Issue
Block a user