mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-03 14:50:18 +00:00
LibJS: Implement Temporal.Instant.fromEpochMilliseconds()
This commit is contained in:
parent
2401e45720
commit
66ff772254
Notes:
sideshowbarker
2024-07-18 10:00:33 +09:00
Author: https://github.com/linusg
Commit: 66ff772254
Pull-request: https://github.com/SerenityOS/serenity/pull/8580
4 changed files with 81 additions and 0 deletions
|
@ -0,0 +1,52 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 1", () => {
|
||||
expect(Temporal.Instant.fromEpochMilliseconds).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
expect(Temporal.Instant.fromEpochMilliseconds(0).epochMilliseconds).toBe(0);
|
||||
expect(Temporal.Instant.fromEpochMilliseconds(1).epochMilliseconds).toBe(1);
|
||||
expect(Temporal.Instant.fromEpochMilliseconds(999_999_999).epochMilliseconds).toBe(
|
||||
999_999_999
|
||||
);
|
||||
expect(
|
||||
Temporal.Instant.fromEpochMilliseconds(8_640_000_000_000_000).epochMilliseconds
|
||||
).toBe(8_640_000_000_000_000);
|
||||
|
||||
expect(Temporal.Instant.fromEpochMilliseconds(-0).epochMilliseconds).toBe(0);
|
||||
expect(Temporal.Instant.fromEpochMilliseconds(-1).epochMilliseconds).toBe(-1);
|
||||
expect(Temporal.Instant.fromEpochMilliseconds(-999_999_999).epochMilliseconds).toBe(
|
||||
-999_999_999
|
||||
);
|
||||
expect(
|
||||
Temporal.Instant.fromEpochMilliseconds(-8_640_000_000_000_000).epochMilliseconds
|
||||
).toBe(-8_640_000_000_000_000);
|
||||
});
|
||||
});
|
||||
|
||||
test("errors", () => {
|
||||
test("argument must be coercible to BigInt", () => {
|
||||
expect(() => {
|
||||
Temporal.Instant.fromEpochMilliseconds(1.23);
|
||||
}).toThrowWithMessage(RangeError, "Cannot convert non-integral number to BigInt");
|
||||
// NOTE: ToNumber is called on the argument first, so this is effectively NaN.
|
||||
expect(() => {
|
||||
Temporal.Instant.fromEpochMilliseconds("foo");
|
||||
}).toThrowWithMessage(RangeError, "Cannot convert non-integral number to BigInt");
|
||||
});
|
||||
|
||||
test("out-of-range epoch milliseconds value", () => {
|
||||
expect(() => {
|
||||
Temporal.Instant.fromEpochMilliseconds(8_640_000_000_000_001);
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
|
||||
);
|
||||
expect(() => {
|
||||
Temporal.Instant.fromEpochMilliseconds(-8_640_000_000_000_001);
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue