for (let [locale, localeTests] of Object.entries(tests)) { for (let [style, styleTests] of Object.entries(localeTests)) {
let dn = new Intl.DisplayNames(locale, {type: "region", style});
let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow}; for (let [region, expected] of Object.entries({...inheritedTests, ...styleTests})) {
assertEq(dn.of(region), expected);
// Also works with objects.
assertEq(dn.of(Object(region)), expected);
}
}
}
{
let dn = new Intl.DisplayNames("en", {type: "region"});
// Performs ToString on the input and then validates the stringified result.
assertThrowsInstanceOf(() => dn.of(), RangeError);
assertThrowsInstanceOf(() => dn.of(null), RangeError);
assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
assertThrowsInstanceOf(() => dn.of(0), RangeError);
// Throws an error if |code| can't be parsed as a `unicode_region_subtag` production.
assertThrowsInstanceOf(() => dn.of("CA-"), RangeError);
assertThrowsInstanceOf(() => dn.of("en-CA"), RangeError);
}
// Test fallback behaviour.
{
let dn1 = new Intl.DisplayNames("en", {type: "region"});
let dn2 = new Intl.DisplayNames("en", {type: "region", fallback: "code"});
let dn3 = new Intl.DisplayNames("en", {type: "region", fallback: "none"});
// "AA" is not a registered region code.
assertEq(dn1.of("AA"), "AA");
assertEq(dn2.of("AA"), "AA");
assertEq(dn3.of("AA"), undefined);
// The returned fallback is in canonical case.
assertEq(dn1.of("aa"), "AA");
assertEq(dn2.of("aa"), "AA");
assertEq(dn3.of("aa"), undefined);
// "998" is canonicalised to "XZ", but "XZ" has no localised names.
assertEq(new Intl.Locale("und-998").region, "XZ");
// Ensure we return the input and not the canonicalised input.
assertEq(dn1.of("998"), "998");
assertEq(dn2.of("998"), "998");
assertEq(dn3.of("998"), undefined);
// "XZ" should be consistent with "998".
assertEq(dn1.of("XZ"), "XZ");
assertEq(dn2.of("XZ"), "XZ");
assertEq(dn3.of("XZ"), undefined);
}
// Ensure language tag canonicalisation is performed.
{
let dn = new Intl.DisplayNames("en", {type: "region", fallback: "none"});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.