v8/test/intl/number-format/options-digits-v3.js
Frank Tang d43080a7f7 [intl] Fix ResolvedOptions to output.
In v3 we allow both significant digits and fraction digits to be set in some conditions.
Also fix the case in v2 we didn't handle "precision-integer" with currency format.

Related spec text:
https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/diff.html#sec-intl.numberformat.prototype.resolvedoptions
https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/diff.html#sec-setnfdigitoptions

Bug: v8:11544
Change-Id: I89c147dcc7803eae7aad2a380e85d1d877e30370
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3615217
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80322}
2022-05-03 03:23:46 +00:00

64 lines
2.6 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.
// Test v3 condiction
// Flags: --harmony-intl-number-format-v3
function assertPresentOfDigits(
options, expectSignificant, expectFractional, user_message) {
if (expectSignificant) {
assertNotUndefined(options.minimumSignificantDigits, user_message);
assertNotUndefined(options.maximumSignificantDigits, user_message);
} else {
assertEquals(undefined, options.minimumSignificantDigits, user_message);
assertEquals(undefined, options.maximumSignificantDigits, user_message);
}
if (expectFractional) {
assertNotUndefined(options.minimumFractionDigits, user_message);
assertNotUndefined(options.maximumFractionDigits, user_message);
} else {
assertEquals(undefined, options.minimumFractionDigits, user_message);
assertEquals(undefined, options.maximumFractionDigits, user_message);
}
}
// Should contain ONLY significant digits (both v2 and v3)
let options = new Intl.NumberFormat("und",
{ maximumSignificantDigits: 3 }).resolvedOptions();
assertPresentOfDigits(options, true, false,
"maximumSignificantDigits: 3");
// Should contain ONLY fraction digits (both v2 and v3)
options = new Intl.NumberFormat("und",
{ maximumFractionDigits: 3 }).resolvedOptions();
assertPresentOfDigits(options, false, true,
"maximumFractionDigits: 3");
// in v2, this should NOT have EITHER significant nor fraction digits
// in v3, should contain BOTH significant and fraction digits, plus
// roundingPriority
options = new Intl.NumberFormat("und",
{ notation: "compact" }).resolvedOptions();
assertPresentOfDigits(options, true, true, "notation: 'compact'");
// in v2, should contain ONLY significant digits
// in v3, should contain BOTH significant and fraction digits, plus
// roundingPriority
options = new Intl.NumberFormat("und",
{ maximumSignificantDigits: 3, maximumFractionDigits: 3,
roundingPriority: "morePrecision" }).resolvedOptions();
assertPresentOfDigits(options, true, true, "roundingPriority: 'morePrecision'");
// Should contain ONLY fraction digits (both v2 and v3)
options = new Intl.NumberFormat('en',
{ style: 'currency', currency: 'USD' }).resolvedOptions();
assertPresentOfDigits(options, false, true,
"style: 'currency', currency: 'USD'");
// Should contain ONLY fraction digits (both v2 and v3)
options = new Intl.NumberFormat('en',
{ style: 'currency', currency: 'JPY' }).resolvedOptions();
assertPresentOfDigits(options, false, true,
"style: 'currency', currency: 'JPY'");