Add test for firstDayOfWeek in LocaleInfo PR 70

Test for enhancement in
https://github.com/tc39/proposal-intl-locale-info/pull/70
This commit is contained in:
Frank Tang 2023-09-15 13:52:44 -07:00 committed by Philip Chimento
parent 873f260478
commit 96727cae1c
9 changed files with 337 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Copyright 2023 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks error cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
x. Let numberingSystem be ? GetOption(options, "firstDayOfWeek", "string", < *"mon"*, *"tue"*, *"wed"*, *"thu"*, *"fri"*, *"sat"*, *"sun"*, *"0"*, *"1"*, *"2"*, *"3"*, *"4"*, *"5"*, *"6"*, *"7"*> , undefined).
...
features: [Intl.Locale,Intl.Locale-info]
---*/
const invalidFirstDayOfWeekOptions = [
"",
"m",
"mo",
"monday",
true,
false,
null,
];
for (const firstDayOfWeek of invalidFirstDayOfWeekOptions) {
assert.throws(RangeError, function() {
new Intl.Locale('en', {firstDayOfWeek});
}, `new Intl.Locale("en", {firstDayOfWeek: "${firstDayOfWeek}"}) throws RangeError`);
}

View File

@ -0,0 +1,65 @@
// Copyright 2023 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks valid cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
x. Let numberingSystem be ? GetOption(options, "firstDayOfWeek", "string", < *"mon"*, *"tue"*, *"wed"*, *"thu"*, *"fri"*, *"sat"*, *"sun"*, *"0"*, *"1"*, *"2"*, *"3"*, *"4"*, *"5"*, *"6"*, *"7"*> , undefined).
x. Let firstDay be *undefined*.
x. If fw is not *undefined*, then
x. Set firstDay to !WeekdayToString(fw).
x. Set opt.[[fw]] to firstDay.
...
x. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
...
x. Let firstDay be *undefined*.
x. If r.[[fw]] is not *undefined*, then
x. Set firstDay to ! WeekdayToNumber(r.[[fw]]).
x. Set locale.[[FirstDayOfWeek]] to firstDay.
...
features: [Intl.Locale,Intl.Locale-info]
---*/
const validFirstDayOfWeekOptions = [
["mon", "en-u-fw-mon"],
["tue", "en-u-fw-tue"],
["wed", "en-u-fw-wed"],
["thu", "en-u-fw-thu"],
["fri", "en-u-fw-fri"],
["sat", "en-u-fw-sat"],
["sun", "en-u-fw-sun"],
["1", "en-u-fw-mon"],
["2", "en-u-fw-tue"],
["3", "en-u-fw-wed"],
["4", "en-u-fw-thu"],
["5", "en-u-fw-fri"],
["6", "en-u-fw-sat"],
["7", "en-u-fw-sun"],
["0", "en-u-fw-sun"],
[1, "en-u-fw-mon"],
[2, "en-u-fw-tue"],
[3, "en-u-fw-wed"],
[4, "en-u-fw-thu"],
[5, "en-u-fw-fri"],
[6, "en-u-fw-sat"],
[7, "en-u-fw-sun"],
[0, "en-u-fw-sun"],
];
for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) {
assert.sameValue(
new Intl.Locale('en', { firstDayOfWeek }).toString(),
expected,
`new Intl.Locale("en", { firstDayOfWeek: ${firstDayOfWeek} }).toString() returns "${expected}"`
);
assert.sameValue(
new Intl.Locale('en-u-fw-WED', { firstDayOfWeek }).toString(),
expected,
`new Intl.Locale("en-u-fw-WED", { firstDayOfWeek: ${firstDayOfWeek} }).toString() returns "${expected}"`
);
}

View File

@ -0,0 +1,30 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.Locale.prototype.firstDayOfWeek
description: >
Verifies the branding check for the "firstDayOfWeek" property of the Locale prototype object.
info: |
Intl.Locale.prototype.firstDayOfWeek
2. If Type(loc) is not Object or loc does not have an [[InitializedLocale]] internal slot, then
a. Throw a TypeError exception.
features: [Intl.Locale,Intl.Locale-info]
---*/
const propdesc = Object.getOwnPropertyDescriptor(Intl.Locale.prototype, "firstDayOfWeek");
const invalidValues = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
Intl.Locale.prototype,
];
for (const invalidValue of invalidValues) {
assert.throws(TypeError, () => propdesc.get.call(invalidValue));
}

View File

@ -0,0 +1,22 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale.prototype.firstDayOfWeek
description: >
Checks the "name" property of Intl.Locale.prototype.firstDayOfWeek.
info: |
Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor.
Every built-in function object, including constructors, that is not identified as an anonymous function has a name property whose value is a String. Unless otherwise specified, this value is the name that is given to the function in this specification. Functions that are specified as get or set accessor functions of built-in properties have "get " or "set " prepended to the property name string.
Unless otherwise specified, the name property of a built-in function object, if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Intl.Locale,Intl.Locale-info]
---*/
const getter = Object.getOwnPropertyDescriptor(Intl.Locale.prototype, "firstDayOfWeek").get;
verifyProperty(getter, "name", {
value: "get firstDayOfWeek",
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,25 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks the "firstDayOfWeek" property of the Locale prototype object.
info: |
Intl.Locale.prototype.firstDayOfWeek
Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor.
Every accessor property described in clauses 18 through 26 and in Annex B.2 has the attributes { [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. If only a get accessor function is described, the set accessor function is the default value, undefined.
includes: [propertyHelper.js]
features: [Intl.Locale,Intl.Locale-info]
---*/
const propdesc = Object.getOwnPropertyDescriptor(Intl.Locale.prototype, "firstDayOfWeek");
assert.sameValue(propdesc.set, undefined);
assert.sameValue(typeof propdesc.get, "function");
verifyProperty(Intl.Locale.prototype, "firstDayOfWeek", {
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,30 @@
// Copyright 2023 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks valid cases for the options argument to the Locale constructor.
info: |
Intl.Locale.prototype.firstDayOfWeek
3. Return loc.[[FirstDayOfWeek]].
features: [Intl.Locale,Intl.Locale-info]
---*/
const validIds = [
["en-u-fw-mon", 1],
["en-u-fw-tue", 2],
["en-u-fw-wed", 3],
["en-u-fw-thu", 4],
["en-u-fw-fri", 5],
["en-u-fw-sat", 6],
["en-u-fw-sun", 7],
];
for (const [id, expected] of validIds) {
assert.sameValue(
new Intl.Locale(id).firstDayOfWeek,
expected,
`new Intl.Locale(${id}).firstDayOfWeek returns "${expected}"`
);
}

View File

@ -0,0 +1,51 @@
// Copyright 2023 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks valid cases for the options argument to the Locale constructor.
info: |
Intl.Locale.prototype.firstDayOfWeek
3. Return loc.[[FirstDayOfWeek]].
features: [Intl.Locale,Intl.Locale-info]
---*/
const validFirstDayOfWeekOptions = [
["mon", 1],
["tue", 2],
["wed", 3],
["thu", 4],
["fri", 5],
["sat", 6],
["sun", 7],
["1", 1],
["2", 2],
["3", 3],
["4", 4],
["5", 5],
["6", 6],
["7", 7],
["0", 7],
[1, 1],
[2, 2],
[3, 3],
[4, 4],
[5, 5],
[6, 6],
[7, 7],
[0, 7],
];
for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) {
assert.sameValue(
new Intl.Locale('en', { firstDayOfWeek }).firstDayOfWeek,
expected,
`new Intl.Locale("en", { firstDayOfWeek: ${firstDayOfWeek} }).firstDayOfWeek returns "${expected}"`
);
assert.sameValue(
new Intl.Locale('en-u-fw-WED', { firstDayOfWeek }).firstDayOfWeek,
expected,
`new Intl.Locale("en-u-fw-WED", { firstDayOfWeek: ${firstDayOfWeek} }).firstDayOfWeek returns "${expected}"`
);
}

View File

@ -0,0 +1,31 @@
// Copyright 2023 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale.prototype.getWeekInfo
description: >
Checks that the return value of Intl.Locale.prototype.getWeekInfo is an Object
with the correct keys and properties.
info: |
get Intl.Locale.prototype.getWeekInfo
...
6. Perform ! CreateDataPropertyOrThrow(info, "firstDay", wi.[[FirstDay]]).
features: [Reflect,Intl.Locale,Intl.Locale-info]
---*/
const validFirstDayOfWeekIds = [
["en-u-fw-mon", 1],
["en-u-fw-tue", 2],
["en-u-fw-wed", 3],
["en-u-fw-thu", 4],
["en-u-fw-fri", 5],
["en-u-fw-sat", 6],
["en-u-fw-sun", 7],
];
for (const [id, expected] of validFirstDayOfWeekIds) {
assert.sameValue(
new Intl.Locale(id).getWeekInfo().firstDay,
expected,
`new Intl.Locale(${id}).getWeekInfo().firstDay returns "${expected}"`
);
}

View File

@ -0,0 +1,52 @@
// Copyright 2023 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale.prototype.getWeekInfo
description: >
Checks that the return value of Intl.Locale.prototype.getWeekInfo is an Object
with the correct keys and properties.
info: |
get Intl.Locale.prototype.getWeekInfo
...
6. Perform ! CreateDataPropertyOrThrow(info, "firstDay", wi.[[FirstDay]]).
features: [Reflect,Intl.Locale,Intl.Locale-info]
---*/
const validFirstDayOfWeekOptions = [
["mon", 1],
["tue", 2],
["wed", 3],
["thu", 4],
["fri", 5],
["sat", 6],
["sun", 7],
["1", 1],
["2", 2],
["3", 3],
["4", 4],
["5", 5],
["6", 6],
["7", 7],
["0", 7],
[1, 1],
[2, 2],
[3, 3],
[4, 4],
[5, 5],
[6, 6],
[7, 7],
[0, 7],
];
for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) {
assert.sameValue(
new Intl.Locale('en', { firstDayOfWeek }).getWeekInfo().firstDay,
expected,
`new Intl.Locale("en", { firstDayOfWeek: ${firstDayOfWeek} }).getWeekInfo().firstDay returns "${expected}"`
);
assert.sameValue(
new Intl.Locale('en-u-fw-WED', { firstDayOfWeek }).getWeekInfo().firstDay,
expected,
`new Intl.Locale("en-u-fw-WED", { firstDayOfWeek: ${firstDayOfWeek} }).firstDayOfWeek returns "${expected}"`
);
}