tools/idna_data/idna_data_wbtest.mbt1///|2test "parse and emit IDNA mapping data" {3 let source = emit_mapping(4 (5 #|0041; mapped; 00616 #|0053; mapped; 00737 #|0061..007A; valid;8 #|00DF; deviation; 0073 00739 #|017F; mapped; 007310 #|200C..200D; deviation;11 #|12 ),13 )14 for15 expected in [16 "let idna_trie_top : Bytes", "let idna_trie_mid : ReadOnlyArray[Int]", "let idna_trie_leaf : ReadOnlyArray[Int]",17 // Unlisted code points are disallowed, including everything above the trie.18 "let idna_high_ranges : ReadOnlyArray[Int] = [\n 0x200004,\n]",19 // The empty mapping, "a", "s" shared by U+0053 and U+017F, and "ss".20 "let idna_mapping_offsets : ReadOnlyArray[Int] = [\n 0,\n 0,\n 1,\n 2,\n 4,\n]",21 "let idna_mapping_data : ReadOnlyArray[Int] = [\n 0x0061,\n 0x0073,\n 0x0073,\n 0x0073,\n]",22 "pub extend IdnaStatus with Eq::{not_equal, equal}", "pub extend IdnaStatus with Show::{to_string, output}",23 "pub fn lookup_idna_entry(c : Char) -> IdnaEntry", "pub fn IdnaEntry::status(self : IdnaEntry) -> IdnaStatus",24 "pub fn IdnaEntry::write_mapping(self : IdnaEntry, output : StringBuilder) -> Unit",25 ] {26 guard source.contains(expected) else {27 fail("Generated source is missing: \{expected}")28 }29 }30}3132///|33test "IDNA ranges above the trie are packed and merged" {34 let source = emit_mapping(35 (36 #|3FFFE..4FFFD; disallowed37 #|4FFFE..4FFFF; disallowed38 #|E0100..E01EF; ignored39 #|E01F0..E0FFF; disallowed40 #|F0000..F0001; valid41 #|42 ),43 )44 // Disallowed from U+40000, ignored from U+E0100, disallowed from U+E01F045 // through the unlisted gap, valid from U+F0000, disallowed from U+F0002.46 let expected = "let idna_high_ranges : ReadOnlyArray[Int] = [\n 0x200004,\n 0x700801,\n 0x700F84,\n 0x780000,\n 0x780014,\n]"47 guard source.contains(expected) else {48 fail("Unexpected high ranges in generated source")49 }50}5152///|53test "IDNA mappings above the trie are rejected" {54 try emit_mapping("40000; mapped; 0061\n") catch {55 Failure::Failure(message) =>56 assert_true(57 message.contains("IDNA value at 0x40000 does not fit in 3 bits"),58 )59 error => raise error60 } noraise {61 _ => fail("expected a mapping above the trie to be rejected")62 }63}64
///|
test "parse and emit IDNA mapping data" {
let source = emit_mapping(
(
#|0041; mapped; 0061
#|0053; mapped; 0073
#|0061..007A; valid;
#|00DF; deviation; 0073 0073
#|017F; mapped; 0073
#|200C..200D; deviation;
#|
),
)
for
expected in [
"let idna_trie_top : Bytes", "let idna_trie_mid : ReadOnlyArray[Int]", "let idna_trie_leaf : ReadOnlyArray[Int]",
// Unlisted code points are disallowed, including everything above the trie.
"let idna_high_ranges : ReadOnlyArray[Int] = [\n 0x200004,\n]",
// The empty mapping, "a", "s" shared by U+0053 and U+017F, and "ss".
"let idna_mapping_offsets : ReadOnlyArray[Int] = [\n 0,\n 0,\n 1,\n 2,\n 4,\n]",
"let idna_mapping_data : ReadOnlyArray[Int] = [\n 0x0061,\n 0x0073,\n 0x0073,\n 0x0073,\n]",
"pub extend IdnaStatus with Eq::{not_equal, equal}", "pub extend IdnaStatus with Show::{to_string, output}",
"pub fn lookup_idna_entry(c : Char) -> IdnaEntry", "pub fn IdnaEntry::status(self : IdnaEntry) -> IdnaStatus",
"pub fn IdnaEntry::write_mapping(self : IdnaEntry, output : StringBuilder) -> Unit",
] {
guard source.contains(expected) else {
fail("Generated source is missing: \{expected}")
}
}
}
///|
test "IDNA ranges above the trie are packed and merged" {
let source = emit_mapping(
(
#|3FFFE..4FFFD; disallowed
#|4FFFE..4FFFF; disallowed
#|E0100..E01EF; ignored
#|E01F0..E0FFF; disallowed
#|F0000..F0001; valid
#|
),
)
// Disallowed from U+40000, ignored from U+E0100, disallowed from U+E01F0
// through the unlisted gap, valid from U+F0000, disallowed from U+F0002.
let expected = "let idna_high_ranges : ReadOnlyArray[Int] = [\n 0x200004,\n 0x700801,\n 0x700F84,\n 0x780000,\n 0x780014,\n]"
guard source.contains(expected) else {
fail("Unexpected high ranges in generated source")
}
}
///|
test "IDNA mappings above the trie are rejected" {
try emit_mapping("40000; mapped; 0061\n") catch {
Failure::Failure(message) =>
assert_true(
message.contains("IDNA value at 0x40000 does not fit in 3 bits"),
)
error => raise error
} noraise {
_ => fail("expected a mapping above the trie to be rejected")
}
}