summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/NumberFormat/constructor-roundingIncrement.js
blob: 3d8522d28aa4d908aecd0e83e0b0fbfd3e27c42a (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
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: Checks handling of the roundingIncrement option to the NumberFormat constructor.
includes: [compareArray.js]
features: [Intl.NumberFormat-v3]
---*/

const values = [
  [undefined, 1],
  [1, 1],
  [2, 2],
  [5, 5],
  [10, 10],
  [20, 20],
  [25, 25],
  [50, 50],
  [100, 100],
  [200, 200],
  [250, 250],
  [500, 500],
  [1000, 1000],
  [2000, 2000],
  [2500, 2500],
  [5000, 5000],
  [true, 1],
  ["2", 2],
  [{valueOf: function() { return 5; }}, 5],
];

for (const [value, expected] of values) {
  const callOrder = [];
  const nf = new Intl.NumberFormat([], {
    get notation() {
      callOrder.push("notation");
      return "standard";
    },
    get roundingIncrement() {
      callOrder.push("roundingIncrement");
      return value;
    },
    minimumFractionDigits: 3
  });
  const resolvedOptions = nf.resolvedOptions();
  assert("roundingIncrement" in resolvedOptions, "has property for value " + value);
  assert.sameValue(resolvedOptions.roundingIncrement, expected);

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

reportCompare(0, 0);