mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 21:29:06 +00:00
LibJS: Implement the Temporal.PlainTime constructor
And the simple Temporal.PlainTime.prototype getters, so that the constructed Temporal.PlainTime may actually be validated.
This commit is contained in:
parent
971f794127
commit
66365fef57
Notes:
github-actions[bot]
2024-11-24 00:38:03 +00:00
Author: https://github.com/trflynn89
Commit: 66365fef57
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2535
22 changed files with 693 additions and 1 deletions
|
@ -0,0 +1,67 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 1", () => {
|
||||
expect(Temporal.PlainTime.from).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("PlainTime instance argument", () => {
|
||||
const plainTime = new Temporal.PlainTime(18, 45, 37, 1, 2, 3);
|
||||
const createdPlainTime = Temporal.PlainTime.from(plainTime);
|
||||
expect(createdPlainTime.hour).toBe(18);
|
||||
expect(createdPlainTime.minute).toBe(45);
|
||||
expect(createdPlainTime.second).toBe(37);
|
||||
expect(createdPlainTime.millisecond).toBe(1);
|
||||
expect(createdPlainTime.microsecond).toBe(2);
|
||||
expect(createdPlainTime.nanosecond).toBe(3);
|
||||
});
|
||||
|
||||
test("PlainTime string argument", () => {
|
||||
const createdPlainTime = Temporal.PlainTime.from("2021-08-27T18:44:11");
|
||||
expect(createdPlainTime.hour).toBe(18);
|
||||
expect(createdPlainTime.minute).toBe(44);
|
||||
expect(createdPlainTime.second).toBe(11);
|
||||
expect(createdPlainTime.millisecond).toBe(0);
|
||||
expect(createdPlainTime.microsecond).toBe(0);
|
||||
expect(createdPlainTime.nanosecond).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("string must not contain a UTC designator", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainTime.from("2021-07-06T23:42:01Z");
|
||||
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
|
||||
});
|
||||
|
||||
test("extended year must not be negative zero", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainTime.from("-000000-01-01T00:00:00");
|
||||
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
|
||||
expect(() => {
|
||||
Temporal.PlainTime.from("−000000-01-01T00:00:00"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
|
||||
});
|
||||
|
||||
test("ambiguous string must contain a time designator", () => {
|
||||
const values = [
|
||||
// YYYY-MM or HHMM-UU
|
||||
"2021-12",
|
||||
// MMDD or HHMM
|
||||
"1214",
|
||||
"0229",
|
||||
"1130",
|
||||
// MM-DD or HH-UU
|
||||
"12-14",
|
||||
// YYYYMM or HHMMSS
|
||||
"202112",
|
||||
];
|
||||
for (const value of values) {
|
||||
expect(() => {
|
||||
Temporal.PlainTime.from(value);
|
||||
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
|
||||
|
||||
expect(() => {
|
||||
Temporal.PlainTime.from(`T${value}`);
|
||||
}).not.toThrow();
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue