| 1 |
// |reftest| skip-if(!this.hasOwnProperty("Intl")) |
| 2 |
|
| 3 |
const invalid = [ |
| 4 |
// empty |
| 5 |
"en-t", |
| 6 |
"en-t-a", |
| 7 |
"en-t-x", |
| 8 |
"en-t-0", |
| 9 |
|
| 10 |
// incomplete |
| 11 |
"en-t-", |
| 12 |
"en-t-en-", |
| 13 |
"en-t-0x-", |
| 14 |
|
| 15 |
// tlang: unicode_language_subtag must be 2-3 or 5-8 characters and mustn't |
| 16 |
// contain extlang subtags. |
| 17 |
"en-t-root", |
| 18 |
"en-t-abcdefghi", |
| 19 |
"en-t-ar-aao", |
| 20 |
|
| 21 |
// tlang: unicode_script_subtag must be 4 alphabetical characters, can't |
| 22 |
// be repeated. |
| 23 |
"en-t-en-lat0", |
| 24 |
"en-t-en-latn-latn", |
| 25 |
|
| 26 |
// tlang: unicode_region_subtag must either be 2 alpha characters or a three |
| 27 |
// digit code. |
| 28 |
"en-t-en-0", |
| 29 |
"en-t-en-00", |
| 30 |
"en-t-en-0x", |
| 31 |
"en-t-en-x0", |
| 32 |
"en-t-en-latn-0", |
| 33 |
"en-t-en-latn-00", |
| 34 |
"en-t-en-latn-xyz", |
| 35 |
|
| 36 |
// tlang: unicode_variant_subtag is either 5-8 alphanum characters or 4 |
| 37 |
// characters starting with a digit. |
| 38 |
"en-t-en-abcdefghi", |
| 39 |
"en-t-en-latn-gb-ab", |
| 40 |
"en-t-en-latn-gb-abc", |
| 41 |
"en-t-en-latn-gb-abcd", |
| 42 |
"en-t-en-latn-gb-abcdefghi", |
| 43 |
]; |
| 44 |
|
| 45 |
// Canonicalisation also applies for the transformation extension. But also |
| 46 |
// see <https://github.com/tc39/ecma402/issues/330>. |
| 47 |
const valid = [ |
| 48 |
{locale: "en-t-en", canonical: "en-t-en"}, |
| 49 |
{locale: "en-t-en-latn", canonical: "en-t-en-latn"}, |
| 50 |
{locale: "en-t-en-ca", canonical: "en-t-en-ca"}, |
| 51 |
{locale: "en-t-en-latn-ca", canonical: "en-t-en-latn-ca"}, |
| 52 |
{locale: "en-t-en-emodeng", canonical: "en-t-en-emodeng"}, |
| 53 |
{locale: "en-t-en-latn-emodeng", canonical: "en-t-en-latn-emodeng"}, |
| 54 |
{locale: "en-t-en-latn-ca-emodeng", canonical: "en-t-en-latn-ca-emodeng"}, |
| 55 |
{locale: "sl-t-sl-rozaj-biske-1994", canonical: "sl-t-sl-1994-biske-rozaj"}, |
| 56 |
{locale: "DE-T-M0-DIN-K0-QWERTZ", canonical: "de-t-k0-qwertz-m0-din"}, |
| 57 |
{locale: "en-t-m0-true", canonical: "en-t-m0-true"}, |
| 58 |
{locale: "en-t-iw", canonical: "en-t-he"}, |
| 59 |
{locale: "und-Latn-t-und-hani-m0-names", canonical: "und-Latn-t-und-hani-m0-prprname"}, |
| 60 |
]; |
| 61 |
|
| 62 |
for (let locale of invalid) { |
| 63 |
assertThrowsInstanceOf(() => Intl.getCanonicalLocales(locale), RangeError); |
| 64 |
} |
| 65 |
|
| 66 |
for (let {locale, canonical} of valid) { |
| 67 |
assertEq(Intl.getCanonicalLocales(locale)[0], canonical); |
| 68 |
} |
| 69 |
|
| 70 |
if (typeof reportCompare === "function") |
| 71 |
reportCompare(true, true); |