summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/unicode-bcp47-locale-ids-transformed-ext.js
blob: 50ac20e58bd8a4178db98ba883cabcfbf5f50f8d (plain)
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
// |reftest| skip-if(!this.hasOwnProperty("Intl"))

const invalid = [
    // empty
    "en-t",
    "en-t-a",
    "en-t-x",
    "en-t-0",

    // incomplete
    "en-t-",
    "en-t-en-",
    "en-t-0x-",

    // tlang: unicode_language_subtag must be 2-3 or 5-8 characters and mustn't
    // contain extlang subtags.
    "en-t-root",
    "en-t-abcdefghi",
    "en-t-ar-aao",

    // tlang: unicode_script_subtag must be 4 alphabetical characters, can't
    // be repeated.
    "en-t-en-lat0",
    "en-t-en-latn-latn",

    // tlang: unicode_region_subtag must either be 2 alpha characters or a three
    // digit code.
    "en-t-en-0",
    "en-t-en-00",
    "en-t-en-0x",
    "en-t-en-x0",
    "en-t-en-latn-0",
    "en-t-en-latn-00",
    "en-t-en-latn-xyz",

    // tlang: unicode_variant_subtag is either 5-8 alphanum characters or 4
    // characters starting with a digit.
    "en-t-en-abcdefghi",
    "en-t-en-latn-gb-ab",
    "en-t-en-latn-gb-abc",
    "en-t-en-latn-gb-abcd",
    "en-t-en-latn-gb-abcdefghi",
];

// Canonicalisation also applies for the transformation extension. But also
// see <https://github.com/tc39/ecma402/issues/330>.
const valid = [
    {locale: "en-t-en", canonical: "en-t-en"},
    {locale: "en-t-en-latn", canonical: "en-t-en-latn"},
    {locale: "en-t-en-ca", canonical: "en-t-en-ca"},
    {locale: "en-t-en-latn-ca", canonical: "en-t-en-latn-ca"},
    {locale: "en-t-en-emodeng", canonical: "en-t-en-emodeng"},
    {locale: "en-t-en-latn-emodeng", canonical: "en-t-en-latn-emodeng"},
    {locale: "en-t-en-latn-ca-emodeng", canonical: "en-t-en-latn-ca-emodeng"},
    {locale: "sl-t-sl-rozaj-biske-1994", canonical: "sl-t-sl-1994-biske-rozaj"},
    {locale: "DE-T-M0-DIN-K0-QWERTZ", canonical: "de-t-k0-qwertz-m0-din"},
    {locale: "en-t-m0-true", canonical: "en-t-m0-true"},
    {locale: "en-t-iw", canonical: "en-t-he"},
    {locale: "und-Latn-t-und-hani-m0-names", canonical: "und-Latn-t-und-hani-m0-prprname"},
];

for (let locale of invalid) {
    assertThrowsInstanceOf(() => Intl.getCanonicalLocales(locale), RangeError);
}

for (let {locale, canonical} of valid) {
    assertEq(Intl.getCanonicalLocales(locale)[0], canonical);
}

if (typeof reportCompare === "function")
    reportCompare(true, true);