summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Intl/supportedValuesOf/collations-accepted-by-Collator.js
blob: ee4413581b806a0889aef0a68df6e093e3f2044b (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
72
73
74
75
76
77
78
79
80
81
82
83
// 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 can be used with Collator.
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: [testIntl.js]
locale: [en, ar, de, es, ko, ln, si, sv, zh]
features: [Intl-enumeration, Array.prototype.includes]
---*/

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

// Not all locales support all possible collations, so test the minimal set to
// cover all supported collations.
//
// The list of all collations can be derived from
// <https://github.com/unicode-org/cldr/blob/master/common/bcp47/collation.xml>.
//
// Note: "standard" and "search" are explicitly disallowed by Intl.Collator.
const locales = [
  "en", // ducet, emoji, eor
  "ar", // compat
  "de", // phonebk
  "es", // trad
  "hi", // direct
  "ko", // searchjl
  "ln", // phonetic
  "si", // dict
  "sv", // reformed
  "zh", // big5han, gb2312, pinyin, stroke, unihan, zhuyin
];

for (let collation of collations) {
  let supported = false;
  for (let locale of locales) {
    let obj = new Intl.Collator(locale, {collation});
    if (obj.resolvedOptions().collation === collation) {
      supported = true;
      break;
    }
  }

  assert(supported, `${collation} is supported by Collator`);
}

for (let collation of allCollations()) {
  let supported = false;
  for (let locale of locales) {
    let obj = new Intl.Collator(locale, {collation});
    if (obj.resolvedOptions().collation === collation) {
      supported = true;
      break;
    }
  }

  if (supported) {
    assert(collations.includes(collation),
           `${collation} supported but not returned by supportedValuesOf`);
  } else {
    assert(!collations.includes(collation),
           `${collation} not supported but returned by supportedValuesOf`);
  }
}

reportCompare(0, 0);