| 1 |
// |reftest| skip-if(!this.hasOwnProperty("Intl")) |
| 2 |
|
| 3 |
const languageTags = { |
| 4 |
// Case 1: legacy, regular tags. |
| 5 |
"art-lojban": "jbo", |
| 6 |
"cel-gaulish": "xtg", |
| 7 |
"zh-guoyu": "zh", |
| 8 |
"zh-hakka": "hak", |
| 9 |
"zh-xiang": "hsn", |
| 10 |
|
| 11 |
// Case 2: redundant language tags. |
| 12 |
"sgn-BR": "bzs", |
| 13 |
"sgn-CO": "csn", |
| 14 |
"sgn-DE": "gsg", |
| 15 |
"sgn-DK": "dsl", |
| 16 |
"sgn-ES": "ssp", |
| 17 |
"sgn-FR": "fsl", |
| 18 |
"sgn-GB": "bfi", |
| 19 |
"sgn-GR": "gss", |
| 20 |
"sgn-IE": "isg", |
| 21 |
"sgn-IT": "ise", |
| 22 |
"sgn-JP": "jsl", |
| 23 |
"sgn-MX": "mfs", |
| 24 |
"sgn-NI": "ncs", |
| 25 |
"sgn-NL": "dse", |
| 26 |
"sgn-NO": "nsi", |
| 27 |
"sgn-PT": "psr", |
| 28 |
"sgn-SE": "swl", |
| 29 |
"sgn-US": "ase", |
| 30 |
"sgn-ZA": "sfs", |
| 31 |
|
| 32 |
// Case 3: the special case. |
| 33 |
"ja-Latn-hepburn-heploc": "ja-Latn-alalc97", |
| 34 |
}; |
| 35 |
const extensions = ["-u-attr", "-u-nu-latn"]; |
| 36 |
const intlConstructors = [Intl.Collator, Intl.DateTimeFormat, Intl.NumberFormat]; |
| 37 |
const options = [{localeMatcher: "best fit"}, {localeMatcher: "lookup"}]; |
| 38 |
|
| 39 |
for (let [tag, canonical] of Object.entries(languageTags)) { |
| 40 |
// Ensure Intl.getCanonicalLocales canonicalizes the language tag correctly. |
| 41 |
assertEq(Intl.getCanonicalLocales(tag)[0], canonical); |
| 42 |
|
| 43 |
// Unicode extensions don't change the canonicalization result. |
| 44 |
for (let ext of extensions) { |
| 45 |
assertEq(Intl.getCanonicalLocales(tag + ext)[0], canonical + ext); |
| 46 |
assertEq(Intl.getCanonicalLocales(canonical + ext)[0], canonical + ext); |
| 47 |
} |
| 48 |
|
| 49 |
for (let intlCtor of intlConstructors) { |
| 50 |
for (let opt of options) { |
| 51 |
// The non-canonical tag is supported iff the canonical tag is supported. |
| 52 |
let supported = intlCtor.supportedLocalesOf(tag, opt); |
| 53 |
let supportedCanonical = intlCtor.supportedLocalesOf(canonical, opt); |
| 54 |
assertEq(supported.length, supportedCanonical.length); |
| 55 |
|
| 56 |
let isSupported = supported.length > 0; |
| 57 |
if (isSupported) { |
| 58 |
assertEq(supported[0], canonical); |
| 59 |
assertEq(supportedCanonical[0], canonical); |
| 60 |
} |
| 61 |
|
| 62 |
// Unicode extensions don't change the result of supportedLocalesOf(). |
| 63 |
for (let ext of extensions) { |
| 64 |
let supportedExt = intlCtor.supportedLocalesOf(tag + ext, opt); |
| 65 |
let supportedCanonicalExt = intlCtor.supportedLocalesOf(canonical + ext, opt); |
| 66 |
assertEq(supportedExt.length, supportedCanonical.length); |
| 67 |
assertEq(supportedCanonicalExt.length, supportedCanonical.length); |
| 68 |
|
| 69 |
if (isSupported) { |
| 70 |
assertEq(supportedExt[0], canonical + ext); |
| 71 |
assertEq(supportedCanonicalExt[0], canonical + ext); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
if (typeof reportCompare === "function") |
| 79 |
reportCompare(0, 0); |