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