dfab3f44e8
Change NumberFormat.prototpe.resolvedOptions to return new options in v3. Also fix a heap allocation assertion bug in GetStringOrBooleanOption while the useGrouping option is an invalid argument. https://github.com/tc39/proposal-intl-numberformat-v3 https://chromestatus.com/guide/edit/5707621009981440 Design Doc: https://docs.google.com/document/d/19jAogPBb6W4Samt8NWGZKu47iv0_KoQhBvLgQH3xvr8/edit Bug: v8:10776 Change-Id: Iaeeb0398b77394db3c941a2706d44b734a1f9d8c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3427298 Reviewed-by: Shu-yu Guo <syg@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#79161}
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
// Copyright 2022 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --harmony-intl-number-format-v3
|
|
|
|
// Check the rounding behavior.
|
|
// Based on https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/diff.html#table-intl-rounding-modes
|
|
let inputs = [-1.5, 0.4, 0.5, 0.6, 1.5];
|
|
let expectations = {
|
|
"ceil": ["-1", "1", "1", "1", "2"],
|
|
"floor": ["-2", "0", "0", "0", "1"],
|
|
"expand": ["-2", "1", "1", "1", "2"],
|
|
"trunc": ["-1", "0", "0", "0", "1"],
|
|
"halfCeil": ["-1", "0", "1", "1", "2"],
|
|
"halfFloor": ["-2", "0", "0", "1", "1"],
|
|
"halfExpand": ["-2", "0", "1", "1", "2"],
|
|
"halfTrunc": ["-1", "0", "0", "1", "1"],
|
|
"halfEven": ["-2", "0", "0", "1", "2"],
|
|
};
|
|
Object.keys(expectations).forEach(function(roundingMode) {
|
|
let exp = expectations[roundingMode];
|
|
let idx = 0;
|
|
let nf = new Intl.NumberFormat("en", {roundingMode, maximumFractionDigits: 0});
|
|
assertEquals(roundingMode, nf.resolvedOptions().roundingMode);
|
|
inputs.forEach(function(input) {
|
|
let msg = "input: " + input + " with roundingMode: " + roundingMode;
|
|
assertEquals(exp[idx++], nf.format(input), msg);
|
|
})
|
|
});
|