From a922295e34faabcc76bb66c35395f3c90a28c0f9 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Tue, 18 Jul 2023 10:30:19 -0700 Subject: [PATCH] Add tests for ECMA402 PR 786 https://github.com/tc39/ecma402/pull/786 This ECMA402 PR 786 reach TC39 consensus in July 2023 meeting --- ...ws-for-maximumFractionDigits-over-limit.js | 22 +++++++++++++++++++ ...s-for-maximumFractionDigits-under-limit.js | 22 +++++++++++++++++++ ...ws-for-minimumFractionDigits-over-limit.js | 22 +++++++++++++++++++ ...s-for-minimumFractionDigits-under-limit.js | 22 +++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 test/intl402/NumberFormat/throws-for-maximumFractionDigits-over-limit.js create mode 100644 test/intl402/NumberFormat/throws-for-maximumFractionDigits-under-limit.js create mode 100644 test/intl402/NumberFormat/throws-for-minimumFractionDigits-over-limit.js create mode 100644 test/intl402/NumberFormat/throws-for-minimumFractionDigits-under-limit.js diff --git a/test/intl402/NumberFormat/throws-for-maximumFractionDigits-over-limit.js b/test/intl402/NumberFormat/throws-for-maximumFractionDigits-over-limit.js new file mode 100644 index 00000000000..f1eaedfa227 --- /dev/null +++ b/test/intl402/NumberFormat/throws-for-maximumFractionDigits-over-limit.js @@ -0,0 +1,22 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializenumberformat +description: > + Tests that the options maximumFractionDigits limit to the range 0 - 100. +info: | + InitializeNumberFormat ( numberFormat, locales, options ) + + 25.a.ii. Set mxfd to ? DefaultNumberOption(mxfd, 0, 100, undefined). + + DefaultNumberOption ( value, minimum, maximum, fallback ) + + 3. If value is NaN or less than minimum or greater than maximum, throw a RangeError exception. +---*/ + +let wontThrow = new Intl.NumberFormat(undefined, {maximumFractionDigits: 100}); + +assert.throws(RangeError, function () { + return new Intl.NumberFormat(undefined, {maximumFractionDigits: 101}); +}, "Throws RangeError when maximumFractionDigits is more than 100."); diff --git a/test/intl402/NumberFormat/throws-for-maximumFractionDigits-under-limit.js b/test/intl402/NumberFormat/throws-for-maximumFractionDigits-under-limit.js new file mode 100644 index 00000000000..760735699e9 --- /dev/null +++ b/test/intl402/NumberFormat/throws-for-maximumFractionDigits-under-limit.js @@ -0,0 +1,22 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializenumberformat +description: > + Tests that the options maximumFractionDigits limit to the range 0 - 100. +info: | + InitializeNumberFormat ( numberFormat, locales, options ) + + 25.a.ii. Set mxfd to ? DefaultNumberOption(mxfd, 0, 100, undefined). + + DefaultNumberOption ( value, minimum, maximum, fallback ) + + 3. If value is NaN or less than minimum or greater than maximum, throw a RangeError exception. +---*/ + +let wontThrow = new Intl.NumberFormat(undefined, {maximumFractionDigits: 0}); + +assert.throws(RangeError, function () { + return new Intl.NumberFormat(undefined, {maximumFractionDigits: -1}); +}, "Throws RangeError when maximumFractionDigits is less than 0."); diff --git a/test/intl402/NumberFormat/throws-for-minimumFractionDigits-over-limit.js b/test/intl402/NumberFormat/throws-for-minimumFractionDigits-over-limit.js new file mode 100644 index 00000000000..59905731dc1 --- /dev/null +++ b/test/intl402/NumberFormat/throws-for-minimumFractionDigits-over-limit.js @@ -0,0 +1,22 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializenumberformat +description: > + Tests that the options minimumFractionDigits limit to the range 0 - 100. +info: | + InitializeNumberFormat ( numberFormat, locales, options ) + + 25.a.ii. Set mxfd to ? DefaultNumberOption(mxfd, 0, 100, undefined). + + DefaultNumberOption ( value, minimum, maximum, fallback ) + + 3. If value is NaN or less than minimum or greater than maximum, throw a RangeError exception. +---*/ + +let wontThrow = new Intl.NumberFormat(undefined, {minimumFractionDigits: 100}); + +assert.throws(RangeError, function () { + return new Intl.NumberFormat(undefined, {minimumFractionDigits: 101}); +}, "Throws RangeError when minimumFractionDigits is more than 100."); diff --git a/test/intl402/NumberFormat/throws-for-minimumFractionDigits-under-limit.js b/test/intl402/NumberFormat/throws-for-minimumFractionDigits-under-limit.js new file mode 100644 index 00000000000..80e286a93e6 --- /dev/null +++ b/test/intl402/NumberFormat/throws-for-minimumFractionDigits-under-limit.js @@ -0,0 +1,22 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializenumberformat +description: > + Tests that the options minimumFractionDigits limit to the range 0 - 100. +info: | + InitializeNumberFormat ( numberFormat, locales, options ) + + 25.a.ii. Set mxfd to ? DefaultNumberOption(mxfd, 0, 100, undefined). + + DefaultNumberOption ( value, minimum, maximum, fallback ) + + 3. If value is NaN or less than minimum or greater than maximum, throw a RangeError exception. +---*/ + +let wontThrow = new Intl.NumberFormat(undefined, {minimumFractionDigits: 0}); + +assert.throws(RangeError, function () { + return new Intl.NumberFormat(undefined, {minimumFractionDigits: -1}); +}, "Throws RangeError when minimumFractionDigits is less than 0.");