node/deps/v8/test/intl/number-format/rounding-mode-table-v3.js
Michaël Zasso fd4f80ce54
deps: update V8 to 10.1.124.6
PR-URL: https://github.com/nodejs/node/pull/42657
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2022-04-12 22:08:39 +02:00

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);
})
});