From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../Intl/NumberFormat/trailing-zero-display.js | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 js/src/tests/non262/Intl/NumberFormat/trailing-zero-display.js (limited to 'js/src/tests/non262/Intl/NumberFormat/trailing-zero-display.js') 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 . + + 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); -- cgit v1.2.3