From 7cf698a82a18b8d37e0d816c6b0720fc0579e687 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Mon, 21 Oct 2024 14:42:59 -0700 Subject: [PATCH] Intl.NumberFormat Add tests for `Intl.NumberFormat` when using "currency" style and "compact", "engineering", and "scientific" notations. Related PR: https://github.com/tc39/ecma402/pull/925 --- .../currency-digits-nonstandard-notation.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/intl402/NumberFormat/currency-digits-nonstandard-notation.js diff --git a/test/intl402/NumberFormat/currency-digits-nonstandard-notation.js b/test/intl402/NumberFormat/currency-digits-nonstandard-notation.js new file mode 100644 index 00000000000..2071ef7780e --- /dev/null +++ b/test/intl402/NumberFormat/currency-digits-nonstandard-notation.js @@ -0,0 +1,34 @@ +// Copyright 2024 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.numberformat +description: > + Checks that the special handling for number of fractional digits when formatting currency values in "standard" notation is ignored when using "compact", "engineering", or "scientific" notation. +info: | + Intl.DateTimeFormat ( [ locales [ , options ] ] ) + + ... + 19. If style is "currency" and "notation" is "standard", then + ... + 20. Else, + a. mnfdDefault be 0. + b. If style is "percent", then + i. Let mxfdDefault be 0. + c. Else, + i. Let mxfdDefault be 3. +---*/ + +for (const notation of ["compact", "engineering", "scientific"]) { + for (const currency of ["JPY", "KWD", "USD"]) { + let nf = new Intl.NumberFormat('en-US', {style: "currency", currency, notation}); + const resolvedOptions = nf.resolvedOptions(); + const minimumFractionDigits = resolvedOptions.minimumFractionDigits; + const maximumFractionDigits = resolvedOptions.maximumFractionDigits; + + assert.sameValue(minimumFractionDigits, 0, "Didn't get correct minimumFractionDigits for currency " + currency + "."); + assert.sameValue(maximumFractionDigits, 3, "Didn't get correct maximumFractionDigits for currency " + currency + "."); + } +} + +