dymokomi/luce-std
Source of release 0.7.3
0.7.3 / tests / unicode / unicode.lucb
## The `unicode` module against its archive: full Unicode casing with multi-scalar
## expansion and Greek final-sigma context, the four normalization forms, and the
## scalar properties. Tricky sequences are built from explicit UTF-8 bytes so the test
## does not depend on how this file's own encoding is read.
test "full Unicode casing: ASCII, German sharp s, and Greek final sigma":
let upper = try to_upper("straße")
defer upper.release()
assert(upper.value == "STRASSE")
let lowered_ascii = try to_lower("MixedCASE 42")
defer lowered_ascii.release()
assert(lowered_ascii.value == "mixedcase 42")
# ΟΔΟΣ lowercases to οδος: the trailing Σ becomes the final form ς, not medial σ
let greek_upper: u8[8] = [0xCE, 0x9F, 0xCE, 0x94, 0xCE, 0x9F, 0xCE, 0xA3]
let greek_lower: u8[8] = [0xCE, 0xBF, 0xCE, 0xB4, 0xCE, 0xBF, 0xCF, 0x82]
let lowered = try to_lower((str)greek_upper[0..])
defer lowered.release()
assert(lowered.value == (str)greek_lower[0..])
test "case folding compares without case and expands like uppercase":
let folded_upper = try case_fold("STRASSE")
defer folded_upper.release()
let folded_sharp = try case_fold("straße")
defer folded_sharp.release()
assert(folded_upper.value == folded_sharp.value and folded_upper.value == "strasse")
test "normalization composes, decomposes, and folds compatibility ligatures":
let decomposed: u8[3] = [0x65, 0xCC, 0x81] # "e" followed by combining acute accent
let precomposed: u8[2] = [0xC3, 0xA9] # the single scalar "é"
let composed = try normalize((str)decomposed[0..], NormalizationForm.nfc)
defer composed.release()
assert(composed.value == (str)precomposed[0..])
let expanded = try normalize((str)precomposed[0..], NormalizationForm.nfd)
defer expanded.release()
assert(expanded.value == (str)decomposed[0..])
let ligature: u8[3] = [0xEF, 0xAC, 0x81] # the ligature "fi"
let plain = try normalize((str)ligature[0..], NormalizationForm.nfkc)
defer plain.release()
assert(plain.value == "fi")
test "a byte limit stops the cased output rather than overrunning it":
# "straße" uppercases to the seven-byte "STRASSE", past the four-byte limit
var stopped = false
let limited = to_upper("straße", 4) catch failure:
assert(failure.code == strings.output_too_large)
stopped = true
recover interop.Owned[str]("")
limited.release()
assert(stopped)
test "scalar properties: whitespace, combining class, and the data version":
assert(is_whitespace(0x20) and is_whitespace(0x00A0) and is_whitespace(0x3000))
assert(not is_whitespace(0x41) and not is_whitespace(0x200B))
assert(combining_class(0x61) == 0 and combining_class(0x0301) == 230)
assert(version == "17.0.0")