Debian Codegraph @

js/src/tests/test262/intl402/NumberFormat/constructor-compactDisplay-compact.js

raw
1 // Copyright 2019 Igalia, S.L. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-initializenumberformat
6 description: Checks handling of the compactDisplay option to the NumberFormat constructor.
7 info: |
8 InitializeNumberFormat ( numberFormat, locales, options )
9
10 19. Let compactDisplay be ? GetOption(options, "compactDisplay", "string", « "short", "long" », "short").
11 20. If notation is "compact", then
12 a. Set numberFormat.[[CompactDisplay]] to compactDisplay.
13
14 includes: [compareArray.js]
15 features: [Intl.NumberFormat-unified]
16 ---*/
17
18 const values = [
19 [undefined, "short"],
20 ["short"],
21 ["long"],
22 ];
23
24 for (const [value, expected = value] of values) {
25 const callOrder = [];
26 const nf = new Intl.NumberFormat([], {
27 get notation() {
28 callOrder.push("notation");
29 return "compact";
30 },
31 get compactDisplay() {
32 callOrder.push("compactDisplay");
33 return value;
34 }
35 });
36 const resolvedOptions = nf.resolvedOptions();
37 assert.sameValue("compactDisplay" in resolvedOptions, true);
38 assert.sameValue(resolvedOptions.compactDisplay, expected);
39
40 assert.compareArray(callOrder, [
41 "notation",
42 "compactDisplay",
43 ]);
44 }
45
46 reportCompare(0, 0);