summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Intl/supportedValuesOf/currencies-accepted-by-DisplayNames.js
blob: cccc756b9f8ae9dd3f91216babc0dcbd1d0d02c3 (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
// 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 "currency" values can be used with DisplayNames.
info: |
  Intl.supportedValuesOf ( key )

  1. Let key be ? ToString(key).
  ...
  4. Else if key is "currency", then
    a. Let list be ! AvailableCurrencies( ).
  ...
  9. Return ! CreateArrayFromList( list ).

  AvailableCurrencies ( )
    The AvailableCurrencies 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, well-formed, and upper case
    canonicalized 3-letter ISO 4217 currency codes, identifying the currencies
    for which the implementation provides the functionality of Intl.DisplayNames
    and Intl.NumberFormat objects.
locale: [en]
features: [Intl-enumeration, Intl.DisplayNames, Array.prototype.includes]
---*/

const currencies = Intl.supportedValuesOf("currency");

const obj = new Intl.DisplayNames("en", {type: "currency", fallback: "none"});

for (let currency of currencies) {
  assert.sameValue(typeof obj.of(currency), "string",
                   `${currency} is supported by DisplayNames`);
}

for (let i = 0x41; i <= 0x5A; ++i) {
  for (let j = 0x41; j <= 0x5A; ++j) {
    for (let k = 0x41; k <= 0x5A; ++k) {
      let currency = String.fromCharCode(i, j, k);
      if (typeof obj.of(currency) === "string") {
        assert(currencies.includes(currency),
               `${currency} supported but not returned by supportedValuesOf`);
      } else {
        assert(!currencies.includes(currency),
               `${currency} not supported but returned by supportedValuesOf`);
      }
    }
  }
}

reportCompare(0, 0);