1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00
serenity/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.js
2022-01-11 21:16:33 +01:00

68 lines
2.4 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'");
});
});
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}`
);
}
}
});
});