mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00:00
LibJS: Implement the Temporal.PlainDate constructor
And the simple Temporal.PlainDate.prototype getters, so that the constructed Temporal.PlainDate may actually be validated.
This commit is contained in:
parent
30fb2bf2e1
commit
a0c55f76e7
Notes:
github-actions[bot]
2024-11-23 13:48:20 +00:00
Author: https://github.com/trflynn89
Commit: a0c55f76e7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2513
Reviewed-by: https://github.com/shannonbooth ✅
30 changed files with 856 additions and 0 deletions
|
@ -0,0 +1,13 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 2", () => {
|
||||
expect(Temporal.PlainDate.compare).toHaveLength(2);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
const plainDate1 = new Temporal.PlainDate(2021, 7, 26);
|
||||
expect(Temporal.PlainDate.compare(plainDate1, plainDate1)).toBe(0);
|
||||
const plainDate2 = new Temporal.PlainDate(2021, 7, 27);
|
||||
expect(Temporal.PlainDate.compare(plainDate1, plainDate2)).toBe(-1);
|
||||
expect(Temporal.PlainDate.compare(plainDate2, plainDate1)).toBe(1);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,49 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 1", () => {
|
||||
expect(Temporal.PlainDate.from).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("PlainDate instance argument", () => {
|
||||
const plainDate = new Temporal.PlainDate(2021, 7, 26);
|
||||
const createdPlainDate = Temporal.PlainDate.from(plainDate);
|
||||
expect(createdPlainDate.year).toBe(2021);
|
||||
expect(createdPlainDate.month).toBe(7);
|
||||
expect(createdPlainDate.day).toBe(26);
|
||||
});
|
||||
|
||||
test("PlainDate string argument", () => {
|
||||
const createdPlainDate = Temporal.PlainDate.from("2021-07-26");
|
||||
expect(createdPlainDate.year).toBe(2021);
|
||||
expect(createdPlainDate.month).toBe(7);
|
||||
expect(createdPlainDate.day).toBe(26);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("missing fields", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainDate.from({});
|
||||
}).toThrowWithMessage(TypeError, "Required property year is missing or undefined");
|
||||
expect(() => {
|
||||
Temporal.PlainDate.from({ year: 0 });
|
||||
}).toThrowWithMessage(TypeError, "Required property day is missing or undefined");
|
||||
expect(() => {
|
||||
Temporal.PlainDate.from({ month: 1 });
|
||||
}).toThrowWithMessage(TypeError, "Required property year is missing or undefined");
|
||||
});
|
||||
|
||||
test("invalid date time string", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainDate.from("foo");
|
||||
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
|
||||
});
|
||||
|
||||
test("extended year must not be negative zero", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainDate.from("-000000-01-01");
|
||||
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
|
||||
expect(() => {
|
||||
Temporal.PlainDate.from("−000000-01-01"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,53 @@
|
|||
describe("errors", () => {
|
||||
test("called without new", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainDate();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Temporal.PlainDate constructor must be called with 'new'"
|
||||
);
|
||||
});
|
||||
|
||||
test("cannot pass Infinity", () => {
|
||||
expect(() => {
|
||||
new Temporal.PlainDate(Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain date");
|
||||
expect(() => {
|
||||
new Temporal.PlainDate(0, Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain date");
|
||||
expect(() => {
|
||||
new Temporal.PlainDate(0, 0, Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain date");
|
||||
expect(() => {
|
||||
new Temporal.PlainDate(-Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain date");
|
||||
expect(() => {
|
||||
new Temporal.PlainDate(0, -Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain date");
|
||||
expect(() => {
|
||||
new Temporal.PlainDate(0, 0, -Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain date");
|
||||
});
|
||||
|
||||
test("cannot pass invalid ISO month/day", () => {
|
||||
expect(() => {
|
||||
new Temporal.PlainDate(0, 0, 1);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain date");
|
||||
expect(() => {
|
||||
new Temporal.PlainDate(0, 1, 0);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain date");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("length is 3", () => {
|
||||
expect(Temporal.PlainDate).toHaveLength(3);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
const plainDate = new Temporal.PlainDate(2021, 7, 19);
|
||||
expect(typeof plainDate).toBe("object");
|
||||
expect(plainDate).toBeInstanceOf(Temporal.PlainDate);
|
||||
expect(Object.getPrototypeOf(plainDate)).toBe(Temporal.PlainDate.prototype);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("calendarId basic functionality", () => {
|
||||
const calendar = "iso8601";
|
||||
const plainDate = new Temporal.PlainDate(2000, 5, 1, calendar);
|
||||
expect(plainDate.calendarId).toBe("iso8601");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "calendarId", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.day).toBe(23);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "day", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.dayOfWeek).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "dayOfWeek", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.dayOfYear).toBe(204);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "dayOfYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.daysInMonth).toBe(31);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "daysInMonth", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.daysInWeek).toBe(7);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "daysInWeek", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.daysInYear).toBe(365);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "daysInYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const plainDate = new Temporal.PlainDate(2021, 7, 6);
|
||||
expect(plainDate.era).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "era", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const plainDate = new Temporal.PlainDate(2021, 7, 6);
|
||||
expect(plainDate.eraYear).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "eraYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.inLeapYear).toBeFalse();
|
||||
const leapDate = new Temporal.PlainDate(2020, 7, 23);
|
||||
expect(leapDate.inLeapYear).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "inLeapYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.month).toBe(7);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "month", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.monthCode).toBe("M07");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "monthCode", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.monthsInYear).toBe(12);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "monthsInYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.weekOfYear).toBe(29);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "weekOfYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2021, 7, 23);
|
||||
expect(date.year).toBe(2021);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "year", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const date = new Temporal.PlainDate(2023, 1, 1);
|
||||
expect(date.yearOfWeek).toBe(2022);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDate.prototype, "yearOfWeek", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue