mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:37:35 +00:00
LibJS: Implement Intl.Locale.prototype.firstDayOfWeek
This is a normative change in the Intl Locale Info spec. See:
f03a814
This commit is contained in:
parent
b5875700e2
commit
a357874c77
7 changed files with 227 additions and 31 deletions
|
@ -0,0 +1,44 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.firstDayOfWeek;
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
|
||||
test("invalid options", () => {
|
||||
[100, Infinity, NaN, "hello", 152n, true].forEach(value => {
|
||||
expect(() => {
|
||||
new Intl.Locale("en", { firstDayOfWeek: value }).firstDayOfWeek;
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
`${value} is not a valid value for option firstDayOfWeek`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// FIXME: Spec issue: It is not yet clear if the following invalid values should throw. For now, this tests our
|
||||
// existing workaround behavior, which returns "undefined" for invalid extensions.
|
||||
// https://github.com/tc39/proposal-intl-locale-info/issues/78
|
||||
test("invalid extensions", () => {
|
||||
[100, Infinity, NaN, "hello", 152n, true].forEach(value => {
|
||||
expect(new Intl.Locale(`en-u-fw-${value}`).firstDayOfWeek).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("valid options", () => {
|
||||
expect(new Intl.Locale("en").firstDayOfWeek).toBeUndefined();
|
||||
|
||||
["mon", "tue", "wed", "thu", "fri", "sat", "sun"].forEach((day, index) => {
|
||||
expect(new Intl.Locale(`en-u-fw-${day}`).firstDayOfWeek).toBe(index + 1);
|
||||
expect(new Intl.Locale("en", { firstDayOfWeek: day }).firstDayOfWeek).toBe(index + 1);
|
||||
expect(new Intl.Locale("en", { firstDayOfWeek: index + 1 }).firstDayOfWeek).toBe(
|
||||
index + 1
|
||||
);
|
||||
expect(new Intl.Locale("en-u-fw-mon", { firstDayOfWeek: day }).firstDayOfWeek).toBe(
|
||||
index + 1
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue