diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Intl/NumberFormat/trailing-zero-display.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/Intl/NumberFormat/trailing-zero-display.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/NumberFormat/trailing-zero-display.js b/js/src/tests/non262/Intl/NumberFormat/trailing-zero-display.js new file mode 100644 index 0000000000..5e3113285a --- /dev/null +++ b/js/src/tests/non262/Intl/NumberFormat/trailing-zero-display.js @@ -0,0 +1,98 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")||release_or_beta) + +// "stripIfInteger" with fractional digits. +{ + let nf1 = new Intl.NumberFormat("en", { + minimumFractionDigits: 2, + }); + + let nf2 = new Intl.NumberFormat("en", { + minimumFractionDigits: 2, + trailingZeroDisplay: "auto", + }); + + let nf3 = new Intl.NumberFormat("en", { + minimumFractionDigits: 2, + trailingZeroDisplay: "stripIfInteger", + }); + + assertEq(nf1.resolvedOptions().trailingZeroDisplay, "auto"); + assertEq(nf2.resolvedOptions().trailingZeroDisplay, "auto"); + assertEq(nf3.resolvedOptions().trailingZeroDisplay, "stripIfInteger"); + + assertEq(nf1.format(123), "123.00"); + assertEq(nf2.format(123), "123.00"); + assertEq(nf3.format(123), "123"); +} + +// "stripIfInteger" with significand digits. +{ + let nf1 = new Intl.NumberFormat("en", { + minimumSignificantDigits: 2, + }); + + let nf2 = new Intl.NumberFormat("en", { + minimumSignificantDigits: 2, + trailingZeroDisplay: "auto", + }); + + let nf3 = new Intl.NumberFormat("en", { + minimumSignificantDigits: 2, + trailingZeroDisplay: "stripIfInteger", + }); + + assertEq(nf1.resolvedOptions().trailingZeroDisplay, "auto"); + assertEq(nf2.resolvedOptions().trailingZeroDisplay, "auto"); + assertEq(nf3.resolvedOptions().trailingZeroDisplay, "stripIfInteger"); + + assertEq(nf1.format(1), "1.0"); + assertEq(nf2.format(1), "1.0"); + assertEq(nf3.format(1), "1"); +} + +// "stripIfInteger" with rounding increment. +{ + let nf1 = new Intl.NumberFormat("en", { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + roundingIncrement: 5, + }); + let nf2 = new Intl.NumberFormat("en", { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + roundingIncrement: 5, + trailingZeroDisplay: "auto", + }); + let nf3 = new Intl.NumberFormat("en", { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + roundingIncrement: 5, + trailingZeroDisplay: "stripIfInteger", + }); + + assertEq(nf1.resolvedOptions().trailingZeroDisplay, "auto"); + assertEq(nf2.resolvedOptions().trailingZeroDisplay, "auto"); + assertEq(nf3.resolvedOptions().trailingZeroDisplay, "stripIfInteger"); + + // NB: Tests 1.975 twice b/c of <https://unicode-org.atlassian.net/browse/ICU-21674>. + + assertEq(nf1.format(1.975), "2.00"); + assertEq(nf1.format(1.97), "1.95"); + assertEq(nf1.format(1.975), "2.00"); + + assertEq(nf2.format(1.975), "2.00"); + assertEq(nf2.format(1.97), "1.95"); + assertEq(nf2.format(1.975), "2.00"); + + assertEq(nf3.format(1.975), "2"); + assertEq(nf3.format(1.97), "1.95"); + assertEq(nf3.format(1.975), "2"); +} + +// Invalid values. +for (let trailingZeroDisplay of ["", "true", true, "none", "yes", "no"]){ + assertThrowsInstanceOf(() => new Intl.NumberFormat("en", {trailingZeroDisplay}), RangeError); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |