summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/NumberFormat/constructor-unitDisplay.js
blob: 54b1594aa53628ef01d631c59ad906698d7f3383 (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
// 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 )

    23. Let signDisplay be ? GetOption(options, "signDisplay", "string", « "auto", "never", "always", "exceptZero" », "auto").
    24. Set numberFormat.[[SignDisplay]] to signDisplay.

features: [Intl.NumberFormat-unified]
---*/

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

for (const [value, expected = value] of values) {
  const nf = new Intl.NumberFormat([], {
    style: "unit",
    unitDisplay: value,
    unit: "hour",
  });
  const resolvedOptions = nf.resolvedOptions();
  assert.sameValue("unitDisplay" in resolvedOptions, true);
  assert.sameValue(resolvedOptions.unitDisplay, expected);
}

for (const [value, expected = value] of values) {
  const nf = new Intl.NumberFormat([], {
    style: "unit",
    unitDisplay: value,
    unit: "percent",
  });
  const resolvedOptions = nf.resolvedOptions();
  assert.sameValue("unitDisplay" in resolvedOptions, true);
  assert.sameValue(resolvedOptions.unitDisplay, expected);
}

for (const [value] of values) {
  const nf = new Intl.NumberFormat([], {
    style: "percent",
    unitDisplay: value,
  });
  const resolvedOptions = nf.resolvedOptions();
  assert.sameValue("unitDisplay" in resolvedOptions, false);
  assert.sameValue(resolvedOptions.unitDisplay, undefined);
}

const invalidValues = [
  "",
  "Short",
  "s",
  "\u017Fhort",
];

for (const unitDisplay of invalidValues) {
  assert.throws(RangeError, () => {
    new Intl.NumberFormat([], { unitDisplay });
  });
}

reportCompare(0, 0);