From 46f847c2e84a6681b1200a31f65318d751cfca30 Mon Sep 17 00:00:00 2001 From: Romulo Cintra Date: Fri, 17 Dec 2021 20:33:27 +0100 Subject: [PATCH] NumberFormat v3 tests (#3283) * feat: nfv3 plural rules * test NaN and out of range values * add NumberFormat v3 proposal features * add feature to selectrange tests * add basic test NumberFormat.formatRange * add basic test NumberFormat.formatRangeToParts * update Plural Rules tests * refactor some tests * update formatRange tests * update formatRangeToParts tests * update feature flag * add locale: [en-US] * update selectRange tests * update tests * update en-US tests and add pt-PT * update prop-desc check * validate 1.1.25_4.a Co-authored-by: Romulo Cintra --- ...rgument-to-Intlmathematicalvalue-throws.js | 21 ++++++++ .../prototype/formatRange/builtin.js | 29 +++++++++++ .../prototype/formatRange/en-US.js | 37 ++++++++++++++ .../prototype/formatRange/invoked-as-func.js | 20 ++++++++ .../prototype/formatRange/length.js | 14 +++++ .../prototype/formatRange/name.js | 14 +++++ .../formatRange/nan-arguments-throws.js | 29 +++++++++++ .../prototype/formatRange/prop-desc.js | 20 ++++++++ .../prototype/formatRange/pt-PT.js | 37 ++++++++++++++ .../formatRange/undefined-arguments-throws.js | 20 ++++++++ .../formatRange/x-greater-than-y-throws.js | 51 +++++++++++++++++++ ...rgument-to-Intlmathematicalvalue-throws.js | 21 ++++++++ .../prototype/formatRangeToParts/builtin.js | 29 +++++++++++ .../prototype/formatRangeToParts/en-US.js | 51 +++++++++++++++++++ .../formatRangeToParts/invoked-as-func.js | 20 ++++++++ .../prototype/formatRangeToParts/length.js | 14 +++++ .../prototype/formatRangeToParts/name.js | 14 +++++ .../nan-arguments-throws.js | 29 +++++++++++ .../prototype/formatRangeToParts/prop-desc.js | 20 ++++++++ .../undefined-arguments-throws.js | 20 ++++++++ .../x-greater-than-y-throws.js | 51 +++++++++++++++++++ .../selectRange/argument-tonumber-throws.js | 24 +++++++++ .../prototype/selectRange/default-en-us.js | 14 +++++ .../prototype/selectRange/invoked-as-func.js | 21 ++++++++ .../prototype/selectRange/length.js | 16 ++++++ .../PluralRules/prototype/selectRange/name.js | 17 +++++++ .../selectRange/nan-arguments-throws.js | 21 ++++++++ .../prototype/selectRange/prop-desc.js | 21 ++++++++ .../selectRange/undefined-arguments-throws.js | 20 ++++++++ .../selectRange/x-greater-than-y-throws.js | 18 +++++++ 30 files changed, 733 insertions(+) create mode 100644 test/intl402/NumberFormat/prototype/formatRange/argument-to-Intlmathematicalvalue-throws.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/builtin.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/en-US.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/invoked-as-func.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/length.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/name.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/nan-arguments-throws.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/prop-desc.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/pt-PT.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/undefined-arguments-throws.js create mode 100644 test/intl402/NumberFormat/prototype/formatRange/x-greater-than-y-throws.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/argument-to-Intlmathematicalvalue-throws.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/builtin.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/en-US.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/invoked-as-func.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/length.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/name.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/nan-arguments-throws.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/prop-desc.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/undefined-arguments-throws.js create mode 100644 test/intl402/NumberFormat/prototype/formatRangeToParts/x-greater-than-y-throws.js create mode 100644 test/intl402/PluralRules/prototype/selectRange/argument-tonumber-throws.js create mode 100644 test/intl402/PluralRules/prototype/selectRange/default-en-us.js create mode 100644 test/intl402/PluralRules/prototype/selectRange/invoked-as-func.js create mode 100644 test/intl402/PluralRules/prototype/selectRange/length.js create mode 100644 test/intl402/PluralRules/prototype/selectRange/name.js create mode 100644 test/intl402/PluralRules/prototype/selectRange/nan-arguments-throws.js create mode 100644 test/intl402/PluralRules/prototype/selectRange/prop-desc.js create mode 100644 test/intl402/PluralRules/prototype/selectRange/undefined-arguments-throws.js create mode 100644 test/intl402/PluralRules/prototype/selectRange/x-greater-than-y-throws.js diff --git a/test/intl402/NumberFormat/prototype/formatRange/argument-to-Intlmathematicalvalue-throws.js b/test/intl402/NumberFormat/prototype/formatRange/argument-to-Intlmathematicalvalue-throws.js new file mode 100644 index 0000000000..a84088618c --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/argument-to-Intlmathematicalvalue-throws.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat-formatRange +description: > + "formatRange" basic tests when argument cannot be converted using ToIntlMathematicalValue +info: | + Intl.NumberFormat.prototype.formatRange( start, end ) + (...) + 4. Let x be ? ToIntlMathematicalValue(start). + 5. Let y be ? ToIntlMathematicalValue(end). +features: [Intl.NumberFormat-v3] +---*/ + + +const nf = new Intl.NumberFormat(); + +// Throw if arguments cannot be cast using the method ToIntlMathematicalValue +assert.throws(TypeError, () => { nf.formatRange(Symbol(102), 201) }); +assert.throws(TypeError, () => { nf.formatRange(102,Symbol(201)) }); diff --git a/test/intl402/NumberFormat/prototype/formatRange/builtin.js b/test/intl402/NumberFormat/prototype/formatRange/builtin.js new file mode 100644 index 0000000000..053fead450 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/builtin.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Tests that the Intl.NumberFormat.prototype.formatRange function meets the + requirements for built-in objects defined by the ECMAScript Language + Specification. +includes: [isConstructor.js] +features: [Reflect.construct,Intl.NumberFormat-v3] +---*/ + +const formatRange = Intl.NumberFormat.prototype.formatRange; + +assert.sameValue(Object.prototype.toString.call(formatRange), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(formatRange), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(formatRange), Function.prototype); + +assert.sameValue(formatRange.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(formatRange), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); diff --git a/test/intl402/NumberFormat/prototype/formatRange/en-US.js b/test/intl402/NumberFormat/prototype/formatRange/en-US.js new file mode 100644 index 0000000000..022856c126 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/en-US.js @@ -0,0 +1,37 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat-formatRange +description: Basic tests for the en-US output of formatRange() +locale: [en-US] +features: [Intl.NumberFormat-v3] +---*/ + +// Basic example test en-US +const nf = new Intl.NumberFormat("en-US", { + style: "currency", + currency: "USD", + maximumFractionDigits: 0, +}); + +assert.sameValue(nf.formatRange(3, 5), "$3 – $5"); +assert.sameValue(nf.formatRange(2.9, 3.1), "~$3"); + + +// Basic example test en-US using signDisplay to always +const nf2 = new Intl.NumberFormat("en-US", { + style: "currency", + currency: "USD", + signDisplay: "always", +}); + +assert.sameValue(nf2.formatRange(2.9, 3.1), "+$2.90–3.10"); + +// Basic example test en-US string formatting +const nf3 = new Intl.NumberFormat("en-US"); +const string1 = "987654321987654321"; +const string2 = "987654321987654322"; + +assert.sameValue(nf3.formatRange(string1, string2), "987,654,321,987,654,321–987,654,321,987,654,322"); + diff --git a/test/intl402/NumberFormat/prototype/formatRange/invoked-as-func.js b/test/intl402/NumberFormat/prototype/formatRange/invoked-as-func.js new file mode 100644 index 0000000000..225d252fae --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/invoked-as-func.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat-NumberFormat +description: basic tests internal slot initialization and call receiver errors +info: | + Intl.NumberFormat.prototype.formatRange(start, end ) + (...) + 2. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]) +features: [Intl.NumberFormat-v3] +---*/ + +const nf = new Intl.NumberFormat(); + +// Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]) +let f = nf['formatRange']; + +assert.sameValue(typeof f, 'function'); +assert.throws(TypeError, () => { f(1, 23) }); diff --git a/test/intl402/NumberFormat/prototype/formatRange/length.js b/test/intl402/NumberFormat/prototype/formatRange/length.js new file mode 100644 index 0000000000..697e8eec77 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/length.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Intl.NumberFormat.prototype.formatRange.length. +includes: [propertyHelper.js] +features: [Intl.NumberFormat-v3] +---*/ +verifyProperty(Intl.NumberFormat.prototype.formatRange, 'length', { + value: 2, + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/intl402/NumberFormat/prototype/formatRange/name.js b/test/intl402/NumberFormat/prototype/formatRange/name.js new file mode 100644 index 0000000000..8d83a9083e --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/name.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Intl.NumberFormat.prototype.formatRange.name value and descriptor. +includes: [propertyHelper.js] +features: [Intl.NumberFormat-v3] +---*/ +verifyProperty(Intl.NumberFormat.prototype.formatRange, 'name', { + value: 'formatRange', + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/intl402/NumberFormat/prototype/formatRange/nan-arguments-throws.js b/test/intl402/NumberFormat/prototype/formatRange/nan-arguments-throws.js new file mode 100644 index 0000000000..22df954128 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/nan-arguments-throws.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat-formatRange +description: > + "formatRange" Throws a RangeError if some of arguments is cast to NaN +info: | + Intl.NumberFormat.prototype.formatRange( start, end ) + (...) + 6. Return ? FormatNumericRange(nf, x, y). + + FormatNumericRange( numberFormat, x, y ) + 1. Let parts be ? PartitionNumberRangePattern(numberFormat, x, y). + + PartitionNumberRangePattern( numberFormat, x, y ) + 1. If x is NaN or y is NaN, throw a RangeError exception. +features: [Intl.NumberFormat-v3] +---*/ + + +const nf = new Intl.NumberFormat(); + +// If x or y is NaN ..., throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRange(NaN, 23) }); +assert.throws(RangeError, () => { nf.formatRange(12, NaN) }); +assert.throws(RangeError, () => { nf.formatRange(NaN, -23) }); +assert.throws(RangeError, () => { nf.formatRange(-12, NaN) }); +assert.throws(RangeError, () => { nf.formatRange(NaN, NaN) }); diff --git a/test/intl402/NumberFormat/prototype/formatRange/prop-desc.js b/test/intl402/NumberFormat/prototype/formatRange/prop-desc.js new file mode 100644 index 0000000000..bd595288b9 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/prop-desc.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Property type and descriptor. +includes: [propertyHelper.js] +features: [Intl.NumberFormat-v3] +---*/ + +assert.sameValue( + typeof Intl.NumberFormat.prototype.formatRange, + 'function', + '`typeof Intl.NumberFormat.prototype.formatRange` is `function`' +); + +verifyProperty(Intl.NumberFormat.prototype, 'formatRange', { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/intl402/NumberFormat/prototype/formatRange/pt-PT.js b/test/intl402/NumberFormat/prototype/formatRange/pt-PT.js new file mode 100644 index 0000000000..0d9c35987b --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/pt-PT.js @@ -0,0 +1,37 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat-formatRange +description: Basic tests for the pt-PT output of formatRange() +locale: [pt-PT] +features: [Intl.NumberFormat-v3] +---*/ + +// Basic example test pt-PT +const nf = new Intl.NumberFormat("pt-PT", { + style: "currency", + currency: "EUR", + maximumFractionDigits: 0, +}); + +assert.sameValue(nf.formatRange(3, 5), "3 - 5 €"); +assert.sameValue(nf.formatRange(2.9, 3.1), "~3 €"); + + +// Basic example test pt-PT using signDisplay to always +const nf2 = new Intl.NumberFormat("pt-PT", { + style: "currency", + currency: "EUR", + signDisplay: "always", +}); + +assert.sameValue(nf2.formatRange(2.9, 3.1), "+2,90 - 3,10 €"); + +// Basic example test pt-PT string formatting +const nf3 = new Intl.NumberFormat("pt-PT"); +const string1 = "987654321987654321"; +const string2 = "987654321987654322"; + +assert.sameValue(nf3.formatRange(string1, string2), "987 654 321 987 654 321 - 987 654 321 987 654 322"); + diff --git a/test/intl402/NumberFormat/prototype/formatRange/undefined-arguments-throws.js b/test/intl402/NumberFormat/prototype/formatRange/undefined-arguments-throws.js new file mode 100644 index 0000000000..040a60087a --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/undefined-arguments-throws.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat.prototype.formatRange +description: > + "formatRange" basic tests when arguments are undefined throw a TypeError exception. +info: | + Intl.NumberFormat.prototype.formatRange ( start, end ) + (...) + 3. If start is undefined or end is undefined, throw a TypeError exception. +features: [Intl.NumberFormat-v3] +---*/ + +const nf = new Intl.NumberFormat(); + +// If arguments are undefined throw a TypeError exception. +assert.throws(TypeError, () => { nf.formatRange(undefined, 23) }); +assert.throws(TypeError, () => { nf.formatRange(1,undefined) }); +assert.throws(TypeError, () => { nf.formatRange(undefined, undefined)}); diff --git a/test/intl402/NumberFormat/prototype/formatRange/x-greater-than-y-throws.js b/test/intl402/NumberFormat/prototype/formatRange/x-greater-than-y-throws.js new file mode 100644 index 0000000000..9b192d4bd3 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRange/x-greater-than-y-throws.js @@ -0,0 +1,51 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat.prototype.formatRange +description: > + "formatRange" basic tests when argument x > y, BigInt included and covers PartitionNumberRangePattern throw a RangeError exception. +info: | + 1.1.21 PartitionNumberRangePattern( numberFormat, x, y ) + (...) + 1.1.21_2.a. If y is a mathematical value and y < x, throw a RangeError exception. + 1.1.21._2.b if y is -∞, throw a RangeError exception. + 1.1.21._2.c if y is -0 and x ≥ 0, throw a RangeError exception. + (...) + 1.1.21._3.a if y is a mathematical value, throw a RangeError exception + 1.1.21._3.b if y is -∞, throw a RangeError exception. + 1.1.21._3.c if y is -0, throw a RangeError exception. + (...) + 1.1.21_4.a if y is a mathematical value and y < 0, throw a RangeError exception. + 1.1.21_4.b if y is -∞, throw a RangeError exception. + features: [Intl.NumberFormat-v3] +---*/ + +const nf = new Intl.NumberFormat(); + +// If x > y, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRange(23, 12) }); + +// 1.1.21_2 (...) +// If x > y, throw a RangeError exception and both x and y are bigint. +assert.throws(RangeError, () => { nf.formatRange(23n, 12n) }); +//if y is -∞, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRange(23, -Infinity) }); +//if y is -0 and x ≥ 0, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRange(23, -0) }); +assert.throws(RangeError, () => { nf.formatRange(0, -0) }); + +// 1.1.21_3 (...) +// if y is a mathematical value, throw a RangeError exception +assert.throws(RangeError, () => { nf.formatRange(Infinity, 23) }); +// if y is -∞, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRange(Infinity, -Infinity) }); +// if y is -0, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRange(Infinity, -0) }); + +// 1.1.21_4 (...) +// if y is a mathematical value and y < 0, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRange(-0, -1) }); +// if y is -∞, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRange(-0, -Infinity) }); + diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/argument-to-Intlmathematicalvalue-throws.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/argument-to-Intlmathematicalvalue-throws.js new file mode 100644 index 0000000000..21ab9cf8f0 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/argument-to-Intlmathematicalvalue-throws.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat-formatRangeToParts +description: > + "formatRangeToParts" basic tests when argument cannot be converted using ToIntlMathematicalValue +info: | + Intl.NumberFormat.prototype.formatRangeToParts( start, end ) + (...) + 4. Let x be ? ToIntlMathematicalValue(start). + 5. Let y be ? ToIntlMathematicalValue(end). +features: [Intl.NumberFormat-v3] +---*/ + + +const nf = new Intl.NumberFormat(); + +// Throw if arguments cannot be cast using the method ToIntlMathematicalValue +assert.throws(TypeError, () => { nf.formatRangeToParts(Symbol(102), 201) }); +assert.throws(TypeError, () => { nf.formatRangeToParts(102,Symbol(201)) }); diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/builtin.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/builtin.js new file mode 100644 index 0000000000..0a37bff91c --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/builtin.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Tests that the Intl.NumberFormat.prototype.formatRangeToParts function meets the + requirements for built-in objects defined by the ECMAScript Language + Specification. +includes: [isConstructor.js] +features: [Reflect.construct,Intl.NumberFormat-v3] +---*/ + +const formatRangeToParts = Intl.NumberFormat.prototype.formatRangeToParts; + +assert.sameValue(Object.prototype.toString.call(formatRangeToParts), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(formatRangeToParts), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(formatRangeToParts), Function.prototype); + +assert.sameValue(formatRangeToParts.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(formatRangeToParts), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/en-US.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/en-US.js new file mode 100644 index 0000000000..13199e40d8 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/en-US.js @@ -0,0 +1,51 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat-formatRangeToParts +description: Basic tests for the en-US output of formatRangeToParts() +locale: [en-US] +features: [Intl.NumberFormat-v3] +---*/ + +// Utils functions +function* zip(a, b) { + assert.sameValue(a.length, b.length); + for (let i = 0; i < a.length; ++i) { + yield [i, a[i], b[i]]; + } +} + +function compare(actual, expected) { + for (const [i, actualEntry, expectedEntry] of zip(actual, expected)) { + + // 1.1.25_4.a Let O be ObjectCreate(%ObjectPrototype%). + assert.sameValue(Object.getPrototypeOf(actualEntry), Object.prototype, `prototype for entry ${i}`); + // 1.1.25_4.b Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]) + verifyProperty(actualEntry, 'type', { enumerable: true, writable: true, configurable: true }); + // 1.1.25_4.c Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]). + verifyProperty(actualEntry, 'value', { enumerable: true, writable: true, configurable: true }); + // 1.1.25_4.d Perform ! CreateDataPropertyOrThrow(O, "source", part.[[Source]]). + verifyProperty(actualEntry, 'source', { enumerable: true, writable: true, configurable: true }); + + // assertions + assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`); + assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`); + assert.sameValue(actualEntry.source, expectedEntry.source, `source for entry ${i}`); + } +} + +// Basic example test en-US +const nf = new Intl.NumberFormat("en-US", { + style: "currency", + currency: "USD", + maximumFractionDigits: 0, +}); + +compare(nf.formatRangeToParts(3, 5), [ + {type: "currency", value: "$", source: "startRange"}, + {type: "integer", value: "3", source: "startRange"}, + {type: "literal", value: "–", source: "shared"}, + {type: "currency", value: "$", source: "endRange"}, + {type: "integer", value: "5", source: "endRange"} +]); diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/invoked-as-func.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/invoked-as-func.js new file mode 100644 index 0000000000..ee20733355 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/invoked-as-func.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat-NumberFormat +description: basic tests internal slot initialization and call receiver errors +info: | + Intl.NumberFormat.prototype.formatRangeToParts ( start, end ) + (...) + 2. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]) +features: [Intl.NumberFormat-v3] +---*/ + +const nf = new Intl.NumberFormat(); + +// Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]) +let f = nf['formatRangeToParts']; + +assert.sameValue(typeof f, 'function'); +assert.throws(TypeError, () => { f(1, 23) }); diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/length.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/length.js new file mode 100644 index 0000000000..5b4e1025d6 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/length.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Intl.NumberFormat.prototype.formatRangeToParts.length. +includes: [propertyHelper.js] +features: [Intl.NumberFormat-v3] +---*/ +verifyProperty(Intl.NumberFormat.prototype.formatRangeToParts, 'length', { + value: 2, + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/name.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/name.js new file mode 100644 index 0000000000..8697348369 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/name.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Intl.NumberFormat.prototype.formatRangeToParts.name value and descriptor. +includes: [propertyHelper.js] +features: [Intl.NumberFormat-v3] +---*/ +verifyProperty(Intl.NumberFormat.prototype.formatRangeToParts, 'name', { + value: 'formatRangeToParts', + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/nan-arguments-throws.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/nan-arguments-throws.js new file mode 100644 index 0000000000..3c20888427 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/nan-arguments-throws.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat-formatRangeToParts +description: > + "formatRangeToParts" Throws a RangeError if some of arguments is cast to NaN +info: | + Intl.NumberFormat.prototype.formatRangeToParts( start, end ) + (...) + 6. Return ? FormatNumericRangeToParts(nf, x, y). + + FormatNumericRangeToParts( numberFormat, x, y ) + 1. Let parts be ? PartitionNumberRangePattern(numberFormat, x, y). + + PartitionNumberRangePattern( numberFormat, x, y ) + 1. If x is NaN or y is NaN, throw a RangeError exception. +features: [Intl.NumberFormat-v3] +---*/ + + +const nf = new Intl.NumberFormat(); + +// If x or y is NaN ..., throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRangeToParts(NaN, 23) }); +assert.throws(RangeError, () => { nf.formatRangeToParts(12, NaN) }); +assert.throws(RangeError, () => { nf.formatRangeToParts(NaN, -23) }); +assert.throws(RangeError, () => { nf.formatRangeToParts(-12, NaN) }); +assert.throws(RangeError, () => { nf.formatRangeToParts(NaN, NaN) }); diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/prop-desc.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/prop-desc.js new file mode 100644 index 0000000000..fd0dfeb139 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/prop-desc.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Property type and descriptor. +includes: [propertyHelper.js] +features: [Intl.NumberFormat-v3] +---*/ + +assert.sameValue( + typeof Intl.NumberFormat.prototype.formatRangeToParts, + 'function', + '`typeof Intl.NumberFormat.prototype.formatRangeToParts` is `function`' +); + +verifyProperty(Intl.NumberFormat.prototype, 'formatRangeToParts', { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/undefined-arguments-throws.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/undefined-arguments-throws.js new file mode 100644 index 0000000000..cdeda839ee --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/undefined-arguments-throws.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat.prototype.formatRangeToParts +description: > + "formatRangeToParts" basic tests when arguments are undefined throw a TypeError exception. +info: | + Intl.NumberFormat.prototype.formatRangeToParts ( start, end ) + (...) + 3. If start is undefined or end is undefined, throw a TypeError exception. +features: [Intl.NumberFormat-v3] +---*/ + +const nf = new Intl.NumberFormat(); + +// If arguments are undefined throw a TypeError exception. +assert.throws(TypeError, () => { nf.formatRangeToParts(undefined, 23) }); +assert.throws(TypeError, () => { nf.formatRangeToParts(1,undefined) }); +assert.throws(TypeError, () => { nf.formatRangeToParts(undefined, undefined)}); diff --git a/test/intl402/NumberFormat/prototype/formatRangeToParts/x-greater-than-y-throws.js b/test/intl402/NumberFormat/prototype/formatRangeToParts/x-greater-than-y-throws.js new file mode 100644 index 0000000000..719f1bee00 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatRangeToParts/x-greater-than-y-throws.js @@ -0,0 +1,51 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat.prototype.formatRangeToParts +description: > + "formatRangeToParts" basic tests when argument x > y, BigInt included and covers PartitionNumberRangePattern throw a RangeError exception. +info: | + 1.1.21 PartitionNumberRangePattern( numberFormat, x, y ) + (...) + 1.1.21_2.a. If y is a mathematical value and y < x, throw a RangeError exception. + 1.1.21._2.b if y is -∞, throw a RangeError exception. + 1.1.21._2.c if y is -0 and x ≥ 0, throw a RangeError exception. + (...) + 1.1.21._3.a if y is a mathematical value, throw a RangeError exception + 1.1.21._3.b if y is -∞, throw a RangeError exception. + 1.1.21._3.c if y is -0, throw a RangeError exception. + (...) + 1.1.21_4.a if y is a mathematical value and y < 0, throw a RangeError exception. + 1.1.21_4.b if y is -∞, throw a RangeError exception. + features: [Intl.NumberFormat-v3] +---*/ + +const nf = new Intl.NumberFormat(); + +// If x > y, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRangeToParts(23, 12) }); + +// 1.1.21_2 (...) +// If x > y, throw a RangeError exception and both x and y are bigint. +assert.throws(RangeError, () => { nf.formatRangeToParts(23n, 12n) }); +//if y is -∞, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRangeToParts(23, -Infinity) }); +//if y is -0 and x ≥ 0, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRangeToParts(23, -0) }); +assert.throws(RangeError, () => { nf.formatRangeToParts(0, -0) }); + +// 1.1.21_3 (...) +// if y is a mathematical value, throw a RangeError exception +assert.throws(RangeError, () => { nf.formatRangeToParts(Infinity, 23) }); +// if y is -∞, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRangeToParts(Infinity, -Infinity) }); +// if y is -0, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRangeToParts(Infinity, -0) }); + +// 1.1.21_4 (...) +// if y is a mathematical value and y < 0, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRangeToParts(-0, -1) }); +// if y is -∞, throw a RangeError exception. +assert.throws(RangeError, () => { nf.formatRangeToParts(-0, -Infinity) }); + diff --git a/test/intl402/PluralRules/prototype/selectRange/argument-tonumber-throws.js b/test/intl402/PluralRules/prototype/selectRange/argument-tonumber-throws.js new file mode 100644 index 0000000000..7363c5f53a --- /dev/null +++ b/test/intl402/PluralRules/prototype/selectRange/argument-tonumber-throws.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.PluralRules.prototype.selectRange +description: > + "selectRange" basic tests when argument cannot be converted using ToNumber +info: | + Intl.PluralRules.prototype.selectRange ( start, end ) + (...) + 4. Let x be ? ToNumber(start). + 5. Let y be ? ToNumber(end). +locale: [en-US] +features: [Intl.NumberFormat-v3] +---*/ + +const pr = new Intl.PluralRules("en-US"); + +// Throw if arguments cannot be cast toNumber +assert.throws(TypeError, () => { pr.selectRange(Symbol(102), 201) }); +assert.throws(TypeError, () => { pr.selectRange(102,Symbol(201)) }); +assert.throws(TypeError, () => { pr.selectRange(23n, 100) }); +assert.throws(TypeError, () => { pr.selectRange(100, 23n) }); +assert.throws(TypeError, () => { pr.selectRange(23n, 23n) }); diff --git a/test/intl402/PluralRules/prototype/selectRange/default-en-us.js b/test/intl402/PluralRules/prototype/selectRange/default-en-us.js new file mode 100644 index 0000000000..f546191706 --- /dev/null +++ b/test/intl402/PluralRules/prototype/selectRange/default-en-us.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Intl.PluralRules.prototype.selectRange default behaviour returning "few" or "other" +locale: [en-US] +features: [Intl.NumberFormat-v3] +---*/ + +const pr = new Intl.PluralRules("en-US"); + +assert.sameValue(pr.selectRange(102, 201), "few"); +assert.sameValue(pr.selectRange(200, 200), "other"); + diff --git a/test/intl402/PluralRules/prototype/selectRange/invoked-as-func.js b/test/intl402/PluralRules/prototype/selectRange/invoked-as-func.js new file mode 100644 index 0000000000..d7d1493565 --- /dev/null +++ b/test/intl402/PluralRules/prototype/selectRange/invoked-as-func.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.PluralRules.prototype.selectRange +description: basic tests internal slot initialization and call receiver errors +info: | + Intl.PluralRules.prototype.selectRange(start, end ) + (...) + 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]) +features: [Intl.NumberFormat-v3] +---*/ + +const pr = new Intl.PluralRules(); + +// Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). +let sr = pr['selectRange']; + +assert.sameValue(typeof sr, 'function'); +assert.throws(TypeError, () => { sr(1, 23) }); + diff --git a/test/intl402/PluralRules/prototype/selectRange/length.js b/test/intl402/PluralRules/prototype/selectRange/length.js new file mode 100644 index 0000000000..aa2e00ae33 --- /dev/null +++ b/test/intl402/PluralRules/prototype/selectRange/length.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.PluralRules.prototype.selectRange +description: Intl.PluralRules.prototype.selectRange.length is 2 +includes: [propertyHelper.js] +features: [Intl.NumberFormat-v3] +---*/ + +verifyProperty(Intl.PluralRules.prototype.selectRange, 'length', { + value: 2, + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/intl402/PluralRules/prototype/selectRange/name.js b/test/intl402/PluralRules/prototype/selectRange/name.js new file mode 100644 index 0000000000..c3246b7e36 --- /dev/null +++ b/test/intl402/PluralRules/prototype/selectRange/name.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.PluralRules.prototype.selectRange +description: Intl.PluralRules.prototype.selectRange.name is "selectRange" +includes: [propertyHelper.js] +features: [Intl.NumberFormat-v3] +---*/ + +verifyProperty(Intl.PluralRules.prototype.selectRange, 'name', { + value: 'selectRange', + enumerable: false, + writable: false, + configurable: true, +}); + diff --git a/test/intl402/PluralRules/prototype/selectRange/nan-arguments-throws.js b/test/intl402/PluralRules/prototype/selectRange/nan-arguments-throws.js new file mode 100644 index 0000000000..378c46fb0f --- /dev/null +++ b/test/intl402/PluralRules/prototype/selectRange/nan-arguments-throws.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.PluralRules.prototype.selectRange +description: > + "selectRange" Throws a RangeError if some of arguments is cast to NaN +info: | + Intl.PluralRules.prototype.selectRange ( start, end ) + (...) + WIP: https://github.com/tc39/proposal-intl-numberformat-v3/pull/76 + + +features: [Intl.NumberFormat-v3] +---*/ + +const pr = new Intl.PluralRules(); + +assert.throws(RangeError, () => { pr.selectRange(NaN, 100) }, "NaN/Number"); +assert.throws(RangeError, () => { pr.selectRange(100, NaN) }, "Number/NaN"); +assert.throws(RangeError, () => { pr.selectRange(NaN, NaN) }, "NaN/NaN"); diff --git a/test/intl402/PluralRules/prototype/selectRange/prop-desc.js b/test/intl402/PluralRules/prototype/selectRange/prop-desc.js new file mode 100644 index 0000000000..fee3929d09 --- /dev/null +++ b/test/intl402/PluralRules/prototype/selectRange/prop-desc.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.PluralRules.prototype.selectRange +description: Property descriptor of Intl.PluralRules.prototype.selectRange +includes: [propertyHelper.js] +features: [Intl.NumberFormat-v3] +---*/ + +assert.sameValue( + typeof Intl.PluralRules.prototype.selectRange, + 'function', + '`typeof Intl.PluralRules.prototype.selectRange` is `function`' +); + +verifyProperty(Intl.PluralRules.prototype, 'selectRange', { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/intl402/PluralRules/prototype/selectRange/undefined-arguments-throws.js b/test/intl402/PluralRules/prototype/selectRange/undefined-arguments-throws.js new file mode 100644 index 0000000000..f98897b10e --- /dev/null +++ b/test/intl402/PluralRules/prototype/selectRange/undefined-arguments-throws.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.PluralRules.prototype.selectRange +description: > + "selectRange" basic tests when arguments are undefined throw a TypeError exception. +info: | + Intl.PluralRules.prototype.selectRange ( start, end ) + (...) + 3. If start is undefined or end is undefined, throw a TypeError exception. +features: [Intl.NumberFormat-v3] +---*/ + +const pr = new Intl.PluralRules(); + +// 1. If arguments are undefined throw a TypeError exception. +assert.throws(TypeError, () => { pr.selectRange(undefined, 201) }); +assert.throws(TypeError, () => { pr.selectRange(102, undefined) }); +assert.throws(TypeError, () => { pr.selectRange(undefined, undefined)}); diff --git a/test/intl402/PluralRules/prototype/selectRange/x-greater-than-y-throws.js b/test/intl402/PluralRules/prototype/selectRange/x-greater-than-y-throws.js new file mode 100644 index 0000000000..bc5108922d --- /dev/null +++ b/test/intl402/PluralRules/prototype/selectRange/x-greater-than-y-throws.js @@ -0,0 +1,18 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.PluralRules.prototype.selectRange +description: > + "selectRange" basic tests when argument x > y, throw a RangeError exception. +info: | + 1.1.6 ResolvePluralRange ( pluralRules, x, y ) + (...) + 5. If x > y, throw a RangeError exception. +features: [Intl.NumberFormat-v3] +---*/ + +const pr = new Intl.PluralRules(); + +// 1. If x > y, throw a RangeError exception. +assert.throws(RangeError, () => { pr.selectRange(201, 102) });