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/rounding-priority.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/rounding-priority.js | 132 |
1 files changed, 132 insertions, 0 deletions
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 + // <https://github.com/tc39/proposal-intl-numberformat-v3/issues/52>. + 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); |