tests/compat/idna2008_test.mbt1///|2test "legacy IDNA repertoire option checks both conversions" {3 inspect(@unicode/idna.to_ascii("☕.example"), content="xn--53h.example")4 inspect(@unicode/idna.to_unicode("xn--53h.example"), content="☕.example")5 try @unicode/idna.to_ascii("☕.example", check_idna2008=true) catch {6 @unicode/idna.DisallowedCodePoint(cp~) => inspect(cp, content="9749")7 error => raise error8 } noraise {9 _ => fail("expected the IDNA2008 repertoire check to reject U+2615")10 }11 try @unicode/idna.to_unicode("xn--53h.example", check_idna2008=true) catch {12 @unicode/idna.DisallowedCodePoint(cp~) => inspect(cp, content="9749")13 error => raise error14 } noraise {15 _ =>16 fail("expected the decoded label to fail the IDNA2008 repertoire check")17 }18}1920///|21test "legacy IDNA ContextO option preserves its error" {22 inspect(@unicode/idna.to_unicode("a·b.example"), content="a·b.example")23 try @unicode/idna.to_ascii("a·b.example", check_contexto=true) catch {24 @unicode/idna.InvalidContextO(cp~) => inspect(cp, content="183")25 error => raise error26 } noraise {27 _ => fail("expected the ContextO check to reject the middle dot")28 }29 try @unicode/idna.to_unicode("a·b.example", check_contexto=true) catch {30 @unicode/idna.InvalidContextO(cp~) => inspect(cp, content="183")31 error => raise error32 } noraise {33 _ => fail("expected the ContextO check to reject the middle dot")34 }35 let error : @unicode/idna.IdnaError = @unicode/idna.InvalidContextO(cp=0xB7)36 inspect(error, content="InvalidContextO(cp=183)")37}38
///|
test "legacy IDNA repertoire option checks both conversions" {
inspect(@unicode/idna.to_ascii("☕.example"), content="xn--53h.example")
inspect(@unicode/idna.to_unicode("xn--53h.example"), content="☕.example")
try @unicode/idna.to_ascii("☕.example", check_idna2008=true) catch {
@unicode/idna.DisallowedCodePoint(cp~) => inspect(cp, content="9749")
error => raise error
} noraise {
_ => fail("expected the IDNA2008 repertoire check to reject U+2615")
}
try @unicode/idna.to_unicode("xn--53h.example", check_idna2008=true) catch {
@unicode/idna.DisallowedCodePoint(cp~) => inspect(cp, content="9749")
error => raise error
} noraise {
_ =>
fail("expected the decoded label to fail the IDNA2008 repertoire check")
}
}
///|
test "legacy IDNA ContextO option preserves its error" {
inspect(@unicode/idna.to_unicode("a·b.example"), content="a·b.example")
try @unicode/idna.to_ascii("a·b.example", check_contexto=true) catch {
@unicode/idna.InvalidContextO(cp~) => inspect(cp, content="183")
error => raise error
} noraise {
_ => fail("expected the ContextO check to reject the middle dot")
}
try @unicode/idna.to_unicode("a·b.example", check_contexto=true) catch {
@unicode/idna.InvalidContextO(cp~) => inspect(cp, content="183")
error => raise error
} noraise {
_ => fail("expected the ContextO check to reject the middle dot")
}
let error : @unicode/idna.IdnaError = @unicode/idna.InvalidContextO(cp=0xB7)
inspect(error, content="InvalidContextO(cp=183)")
}