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 --- .../non262/Intl/NumberFormat/rounding-priority.js | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 js/src/tests/non262/Intl/NumberFormat/rounding-priority.js (limited to 'js/src/tests/non262/Intl/NumberFormat/rounding-priority.js') diff --git a/js/src/tests/non262/Intl/NumberFormat/rounding-priority.js b/js/src/tests/non262/Intl/NumberFormat/rounding-priority.js new file mode 100644 index 0000000000..49c9e1b274 --- /dev/null +++ b/js/src/tests/non262/Intl/NumberFormat/rounding-priority.js @@ -0,0 +1,132 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")||release_or_beta) + +const tests = [ + // Rounding conflict with maximum fraction/significand digits. + { + value: 4.321, + options: { + maximumFractionDigits: 2, + maximumSignificantDigits: 2, + }, + roundingPriorities: { + auto: "4.3", + lessPrecision: "4.3", + morePrecision: "4.32", + }, + }, + { + value: 4.321, + options: { + maximumFractionDigits: 2, + minimumFractionDigits: 2, + maximumSignificantDigits: 2, + }, + roundingPriorities: { + auto: "4.3", + lessPrecision: "4.3", + morePrecision: "4.32", + }, + }, + { + value: 4.321, + options: { + maximumFractionDigits: 2, + maximumSignificantDigits: 2, + minimumSignificantDigits: 2, + }, + roundingPriorities: { + auto: "4.3", + lessPrecision: "4.3", + morePrecision: "4.32", + }, + }, + { + value: 4.321, + options: { + maximumFractionDigits: 2, + minimumFractionDigits: 2, + maximumSignificantDigits: 2, + minimumSignificantDigits: 2, + }, + roundingPriorities: { + auto: "4.3", + lessPrecision: "4.3", + morePrecision: "4.32", + }, + }, + + // Rounding conflict with minimum fraction/significand digits. + { + value: 1.0, + options: { + minimumFractionDigits: 2, + minimumSignificantDigits: 2, + }, + roundingPriorities: { + auto: "1.0", + // Returning "1.00" for both options seems unexpected. Also filed at + // . + lessPrecision: "1.00", + morePrecision: "1.0", + }, + }, + { + value: 1.0, + options: { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + minimumSignificantDigits: 2, + }, + roundingPriorities: { + auto: "1.0", + lessPrecision: "1.00", + morePrecision: "1.0", + }, + }, + { + value: 1.0, + options: { + minimumFractionDigits: 2, + minimumSignificantDigits: 2, + maximumSignificantDigits: 2, + }, + roundingPriorities: { + auto: "1.0", + lessPrecision: "1.0", + morePrecision: "1.00", + }, + }, + { + value: 1.0, + options: { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + minimumSignificantDigits: 2, + maximumSignificantDigits: 2, + }, + roundingPriorities: { + auto: "1.0", + lessPrecision: "1.0", + morePrecision: "1.00", + }, + }, +]; + +for (let {value, options, roundingPriorities} of tests) { + for (let [roundingPriority, expected] of Object.entries(roundingPriorities)) { + let nf = new Intl.NumberFormat("en", {...options, roundingPriority}); + assertEq(nf.resolvedOptions().roundingPriority, roundingPriority); + assertEq(nf.format(value), expected, `value=${value}, roundingPriority=${roundingPriority}`); + } +} + +// Default value of "auto". +assertEq(new Intl.NumberFormat().resolvedOptions().roundingPriority, "auto"); + +// Invalid values. +for (let roundingPriority of ["", null, "more", "less", "never"]){ + assertThrowsInstanceOf(() => new Intl.NumberFormat("en", {roundingPriority}), RangeError); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); -- cgit v1.2.3