summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Intl/supportedValuesOf/collations.js
blob: 372f84c7bf2a6c91450afa1b9006e5b5fa390165 (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
// Copyright (C) 2021 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-intl.supportedvaluesof
description: >
  The returned "collation" values are sorted, unique, and match the type production.
info: |
  Intl.supportedValuesOf ( key )

  1. Let key be ? ToString(key).
  ...
  3. Else if key is "collation", then
    a. Let list be ! AvailableCollations( ).
  ...
  9. Return ! CreateArrayFromList( list ).

  AvailableCollations ( )
    The AvailableCollations abstract operation returns a List, ordered as if an
    Array of the same values had been sorted using %Array.prototype.sort% using
    undefined as comparefn, that contains unique collation types identifying the
    collations for which the implementation provides the functionality of
    Intl.Collator objects.
includes: [compareArray.js]
features: [Intl-enumeration, Intl.Locale, Array.prototype.includes]
---*/

const collations = Intl.supportedValuesOf("collation");

assert(Array.isArray(collations), "Returns an Array object.");
assert.sameValue(Object.getPrototypeOf(collations), Array.prototype,
                 "The array prototype is Array.prototype");

const otherCollations = Intl.supportedValuesOf("collation");
assert.notSameValue(otherCollations, collations,
                    "Returns a new array object for each call.");

assert.compareArray(collations, otherCollations.sort(),
                    "The array is sorted.");

assert.sameValue(new Set(collations).size, collations.length,
                 "The array doesn't contain duplicates.");

// https://unicode.org/reports/tr35/tr35.html#Unicode_locale_identifier
const typeRE = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/;
for (let collation of collations) {
  assert(typeRE.test(collation), `${collation} matches the 'type' production`);
}

for (let collation of collations) {
  assert.sameValue(new Intl.Locale("und", {collation}).collation, collation,
                   `${collation} is canonicalised`);
}

assert(!collations.includes("standard"), "Mustn't include the 'standard' collation type.");
assert(!collations.includes("search"), "Mustn't include the 'search' collation type.");

reportCompare(0, 0);