Debian Codegraph @

js/src/tests/non262/Intl/supportedValuesOf-collation.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2
3 const collations = Intl.supportedValuesOf("collation");
4
5 assertEq(new Set(collations).size, collations.length, "No duplicates are present");
6 assertEqArray(collations, [...collations].sort(), "The list is sorted");
7
8 const typeRE = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/;
9 for (let collation of collations) {
10 assertEq(typeRE.test(collation), true, `${collation} matches the 'type' production`);
11 }
12
13 for (let collation of collations) {
14 assertEq(new Intl.Locale("und", {collation}).collation, collation, `${collation} is canonicalised`);
15 }
16
17 // Not all locales support all possible collations, so test the minimal set to
18 // cover all supported collations.
19 const locales = [
20 "en", // "emoji", "eor"
21 "ar", // compat
22 "de", // phonebk
23 "es", // trad
24 "ko", // searchjl
25 "ln", // phonetic
26 "si", // dict
27 "sv", // reformed
28 "zh", // big5han, gb2312, pinyin, stroke, unihan, zhuyin
29 ];
30
31 for (let collation of collations) {
32 let supported = false;
33 for (let locale of locales) {
34 let obj = new Intl.Collator(locale, {collation});
35 if (obj.resolvedOptions().collation === collation) {
36 supported = true;
37 }
38 }
39
40 assertEq(supported, true, `${collation} is supported by Collator`);
41 }
42
43 if (typeof reportCompare === "function")
44 reportCompare(true, true);