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 <romulocintra@gmqil.com>
This commit is contained in:
Romulo Cintra 2021-12-17 20:33:27 +01:00 committed by GitHub
parent 10bfc6c9d2
commit 46f847c2e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 733 additions and 0 deletions

View File

@ -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)) });

View File

@ -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.");

View File

@ -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.903.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,321987,654,321,987,654,322");

View File

@ -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) });

View File

@ -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,
});

View File

@ -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,
});

View File

@ -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) });

View File

@ -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,
});

View File

@ -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");

View File

@ -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)});

View File

@ -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) });

View File

@ -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)) });

View File

@ -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.");

View File

@ -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"}
]);

View File

@ -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) });

View File

@ -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,
});

View File

@ -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,
});

View File

@ -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) });

View File

@ -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,
});

View File

@ -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)});

View File

@ -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) });

View File

@ -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) });

View File

@ -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");

View File

@ -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) });

View File

@ -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,
});

View File

@ -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,
});

View File

@ -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");

View File

@ -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,
});

View File

@ -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)});

View File

@ -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) });