summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/NumberFormat/prototype/format/signDisplay-currency-en-US.js
blob: 72a1a0ba2ecbb7ee947155e9051fc4c6f85e5147 (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
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the signDisplay option to the NumberFormat constructor.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/


const tests = [
  [
    "auto",
    "($987.00)",
    "($0.00)",
    "($0.00)",
    "$0.00",
    "$0.00",
    "$987.00",
  ],
  [
    "always",
    "($987.00)",
    "($0.00)",
    "($0.00)",
    "+$0.00",
    "+$0.00",
    "+$987.00",
  ],
  [
    "never",
    "$987.00",
    "$0.00",
    "$0.00",
    "$0.00",
    "$0.00",
    "$987.00",
  ],
  [
    "exceptZero",
    "($987.00)",
    "$0.00",
    "$0.00",
    "$0.00",
    "$0.00",
    "+$987.00",
  ],
];

for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
  const nf = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
  assert.sameValue(nf.format(-987), negative);
  assert.sameValue(nf.format(-0.0001), negativeNearZero);
  assert.sameValue(nf.format(-0), negativeZero);
  assert.sameValue(nf.format(0), zero);
  assert.sameValue(nf.format(0.0001), positiveNearZero);
  assert.sameValue(nf.format(987), positive);
}


reportCompare(0, 0);