Debian Codegraph @

js/src/tests/test262/intl402/Intl/supportedValuesOf/collations.js

raw
1 // Copyright (C) 2021 André Bargull. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-intl.supportedvaluesof
6 description: >
7 The returned "collation" values are sorted, unique, and match the type production.
8 info: |
9 Intl.supportedValuesOf ( key )
10
11 1. Let key be ? ToString(key).
12 ...
13 3. Else if key is "collation", then
14 a. Let list be ! AvailableCollations( ).
15 ...
16 9. Return ! CreateArrayFromList( list ).
17
18 AvailableCollations ( )
19 The AvailableCollations abstract operation returns a List, ordered as if an
20 Array of the same values had been sorted using %Array.prototype.sort% using
21 undefined as comparefn, that contains unique collation types identifying the
22 collations for which the implementation provides the functionality of
23 Intl.Collator objects.
24 includes: [compareArray.js]
25 features: [Intl-enumeration, Intl.Locale, Array.prototype.includes]
26 ---*/
27
28 const collations = Intl.supportedValuesOf("collation");
29
30 assert(Array.isArray(collations), "Returns an Array object.");
31 assert.sameValue(Object.getPrototypeOf(collations), Array.prototype,
32 "The array prototype is Array.prototype");
33
34 const otherCollations = Intl.supportedValuesOf("collation");
35 assert.notSameValue(otherCollations, collations,
36 "Returns a new array object for each call.");
37
38 assert.compareArray(collations, otherCollations.sort(),
39 "The array is sorted.");
40
41 assert.sameValue(new Set(collations).size, collations.length,
42 "The array doesn't contain duplicates.");
43
44 // https://unicode.org/reports/tr35/tr35.html#Unicode_locale_identifier
45 const typeRE = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/;
46 for (let collation of collations) {
47 assert(typeRE.test(collation), `${collation} matches the 'type' production`);
48 }
49
50 for (let collation of collations) {
51 assert.sameValue(new Intl.Locale("und", {collation}).collation, collation,
52 `${collation} is canonicalised`);
53 }
54
55 assert(!collations.includes("standard"), "Mustn't include the 'standard' collation type.");
56 assert(!collations.includes("search"), "Mustn't include the 'search' collation type.");
57
58 reportCompare(0, 0);