summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/NumberFormat/constructor-compactDisplay-compact.js
blob: ef5061b87d56b26b625348ff2045134c8fa1bfa9 (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
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializenumberformat
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
info: |
    InitializeNumberFormat ( numberFormat, locales, options )

    19. Let compactDisplay be ? GetOption(options, "compactDisplay", "string", « "short", "long" », "short").
    20. If notation is "compact", then
        a. Set numberFormat.[[CompactDisplay]] to compactDisplay.

includes: [compareArray.js]
features: [Intl.NumberFormat-unified]
---*/

const values = [
  [undefined, "short"],
  ["short"],
  ["long"],
];

for (const [value, expected = value] of values) {
  const callOrder = [];
  const nf = new Intl.NumberFormat([], {
    get notation() {
      callOrder.push("notation");
      return "compact";
    },
    get compactDisplay() {
      callOrder.push("compactDisplay");
      return value;
    }
  });
  const resolvedOptions = nf.resolvedOptions();
  assert.sameValue("compactDisplay" in resolvedOptions, true);
  assert.sameValue(resolvedOptions.compactDisplay, expected);

  assert.compareArray(callOrder, [
    "notation",
    "compactDisplay",
  ]);
}

reportCompare(0, 0);