mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 21:58:10 +00:00

Previously parse_time_zone_numeric_utc_offset_syntax() would return true to indicate success when parsing a string with an invalid number of digits in the fractional seconds part (e.g. 23:59:59.9999999999). We need to check if the lexer has any characters remaining, and return false if that's the case.
78 lines
2.8 KiB
JavaScript
78 lines
2.8 KiB
JavaScript
describe("errors", () => {
|
|
test("called without new", () => {
|
|
expect(() => {
|
|
Temporal.TimeZone();
|
|
}).toThrowWithMessage(TypeError, "Temporal.TimeZone constructor must be called with 'new'");
|
|
});
|
|
|
|
test("Invalid time zone name", () => {
|
|
expect(() => {
|
|
new Temporal.TimeZone("foo");
|
|
}).toThrowWithMessage(RangeError, "Invalid time zone name 'foo'");
|
|
});
|
|
|
|
test("Invalid numeric UTC offset", () => {
|
|
// FIXME: Error message should probably say '...name or UTC offset ...' :^)
|
|
expect(() => {
|
|
new Temporal.TimeZone("0123456");
|
|
}).toThrowWithMessage(RangeError, "Invalid time zone name '0123456'");
|
|
expect(() => {
|
|
new Temporal.TimeZone("23:59:59.9999999999");
|
|
}).toThrowWithMessage(RangeError, "Invalid time zone name '23:59:59.9999999999'");
|
|
});
|
|
});
|
|
|
|
describe("normal behavior", () => {
|
|
test("length is 1", () => {
|
|
expect(Temporal.TimeZone).toHaveLength(1);
|
|
});
|
|
|
|
test("basic functionality", () => {
|
|
const timeZone = new Temporal.TimeZone("UTC");
|
|
expect(timeZone.id).toBe("UTC");
|
|
expect(typeof timeZone).toBe("object");
|
|
expect(timeZone).toBeInstanceOf(Temporal.TimeZone);
|
|
expect(Object.getPrototypeOf(timeZone)).toBe(Temporal.TimeZone.prototype);
|
|
});
|
|
|
|
test("canonicalizes time zone name", () => {
|
|
expect(new Temporal.TimeZone("Utc").id).toBe("UTC");
|
|
expect(new Temporal.TimeZone("utc").id).toBe("UTC");
|
|
expect(new Temporal.TimeZone("uTC").id).toBe("UTC");
|
|
});
|
|
|
|
test("numeric UTC offset", () => {
|
|
const signs = [
|
|
["+", "+"],
|
|
["-", "-"],
|
|
["\u2212", "-"],
|
|
];
|
|
const values = [
|
|
["01", "01:00"],
|
|
["0123", "01:23"],
|
|
["012345", "01:23:45"],
|
|
["012345.6", "01:23:45.6"],
|
|
["012345.123", "01:23:45.123"],
|
|
["012345.123456789", "01:23:45.123456789"],
|
|
["012345,6", "01:23:45.6"],
|
|
["012345,123", "01:23:45.123"],
|
|
["012345,123456789", "01:23:45.123456789"],
|
|
["01:23", "01:23"],
|
|
["01:23:45", "01:23:45"],
|
|
["01:23:45.6", "01:23:45.6"],
|
|
["01:23:45.123", "01:23:45.123"],
|
|
["01:23:45.123456789", "01:23:45.123456789"],
|
|
["01:23:45,6", "01:23:45.6"],
|
|
["01:23:45,123", "01:23:45.123"],
|
|
["01:23:45,123456789", "01:23:45.123456789"],
|
|
["23:59:59.999999999", "23:59:59.999999999"],
|
|
];
|
|
for (const [sign, expectedSign] of signs) {
|
|
for (const [offset, expectedOffset] of values) {
|
|
expect(new Temporal.TimeZone(`${sign}${offset}`).id).toBe(
|
|
`${expectedSign}${expectedOffset}`
|
|
);
|
|
}
|
|
}
|
|
});
|
|
});
|