Debian Codegraph @

js/src/tests/non262/Intl/duplicate-variants.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2
3 // RFC 5646 section 2.1
4 // variant = 5*8alphanum ; registered variants
5 // / (DIGIT 3alphanum)
6
7 // Duplicate variants are forbidden.
8 assertEqArray(Intl.getCanonicalLocales("de-1996"), ["de-1996"]);
9 assertThrowsInstanceOf(() => Intl.getCanonicalLocales("de-1996-1996"), RangeError);
10
11 // Multiple different variants are allowed.
12 assertEqArray(Intl.getCanonicalLocales("sl-rozaj-solba"), ["sl-rozaj-solba"]);
13
14 // Variants can have the same prefix.
15 assertEqArray(Intl.getCanonicalLocales("zh-Latn-pinyin-pinyin2"), ["zh-Latn-pinyin-pinyin2"]);
16
17 // Values in extension sequences are not counted as variants.
18 assertEqArray(Intl.getCanonicalLocales("en-u-kf-false-kn-false"), ["en-u-kf-false-kn-false"]);
19
20 // Also test duplicates in Unicode extension keywords and attributes.
21 // From https://tools.ietf.org/html/rfc6067#section-2.1
22 //
23 // An 'attribute' is a subtag with a length of three to eight
24 // characters following the singleton and preceding any 'keyword'
25 // sequences. No attributes were defined at the time of this
26 // document's publication.
27 //
28 // A 'keyword' is a sequence of subtags consisting of a 'key' subtag,
29 // followed by zero or more 'type' subtags (so a 'key' might appear
30 // alone and not be accompanied by a 'type' subtag). A 'key' MUST
31 // NOT appear more than once in a language tag's extension string.
32 //
33 // ...
34 //
35 // Only the first occurrence of an attribute or key conveys meaning in a
36 // language tag. When interpreting tags containing the Unicode locale
37 // extension, duplicate attributes or keywords are ignored in the
38 // following way: ignore any attribute that has already appeared in the
39 // tag and ignore any keyword whose key has already occurred in the tag.
40 //
41 // The duplicates itself are removed in CanonicalizeUnicodeLocaleId, step 2-3.
42 assertEqArray(Intl.getCanonicalLocales("en-u-kn-false-kn-false"), ["en-u-kn-false"]);
43 assertEqArray(Intl.getCanonicalLocales("en-u-attr1-attr2-attr2"), ["en-u-attr1-attr2"]);
44
45 if (typeof reportCompare === "function")
46 reportCompare(0, 0);