test262/test/intl402/NumberFormat/constructor-roundingIncrement.js
Frank Yung-Fong Tang 0fe508c5f0 change notation to "standard"
I do not believe this setup is correct if we use notation: "compact". 

in https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/diff.html#sec-setnfdigitoptions
notation is "compact"
mnsd is undefined
mxsd is undefined
mnfd is undefined
mxfd is undefined
hasSd is false
hasFd is false
needSd is false
needFd is false
so step 23 else block will be run
Set intlObj.[[RoundingType]] to morePrecision.
then in step 23 of https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/diff.html#sec-initializenumberformat
```
If roundingIncrement is not 1 and numberFormat.[[RoundingType]] is not fractionDigits, throw a RangeError exception.
```
2022-01-07 13:17:50 -05:00

50 lines
1.2 KiB
JavaScript

// 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;
}
});
const resolvedOptions = nf.resolvedOptions();
assert("roundingIncrement" in resolvedOptions, "has property for value " + value);
assert.sameValue(resolvedOptions.roundingIncrement, expected);
assert.compareArray(callOrder, ["notation", "roundingIncrement"]);
}