dymokomi/luce-std
Source of release 0.7.1
0.7.1 / tests / utf8 / utf8.lucb
## The `utf8` module against its archive: scalars encode, decode and are validated.
test "scalars encode, decode and are validated":
var room: u8[4]
assert(encode(0x41, room[0..]) == 1 and room[0] == 0x41)
assert(encode(0x20AC, room[0..]) == 3 and room[0] == 0xE2 and room[1] == 0x82 and room[2] == 0xAC)
var wide: u8[4]
assert(encode(0x1F600, wide[0..]) == 4 and encode(0xD800, wide[0..]) == none)
assert(encoded_length(0x7F) == 1 and encoded_length(0x7FF) == 2 and encoded_length(0x110000) == none)
let euro = decode(room[..<3]) else trap("no scalar")
assert((u32)euro.scalar == 0x20AC and euro.width == 3)
assert(valid("plain ascii".bytes) and valid(room[..<3]))
let bad: u8[2] = [0xC0, 0x80]
assert(not valid(bad[0..]) and invalid_offset(bad[0..]) == 0)