ladybird/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.fromEpochNanoseconds.js
Timothy Flynn 019c529c07 Meta: Increase the line length enforced by prettier to 120
This matches our coding style recommendation in CodingStyle.md, and
matches our python formatting.
2025-10-31 19:55:50 -04:00

48 lines
2.0 KiB
JavaScript

describe("correct behavior", () => {
test("length is 1", () => {
expect(Temporal.Instant.fromEpochNanoseconds).toHaveLength(1);
});
test("basic functionality", () => {
expect(Temporal.Instant.fromEpochNanoseconds(0n).epochNanoseconds).toBe(0n);
expect(Temporal.Instant.fromEpochNanoseconds(1n).epochNanoseconds).toBe(1n);
expect(Temporal.Instant.fromEpochNanoseconds(999_999_999n).epochNanoseconds).toBe(999_999_999n);
expect(Temporal.Instant.fromEpochNanoseconds(8_640_000_000_000_000_000_000n).epochNanoseconds).toBe(
8_640_000_000_000_000_000_000n
);
expect(Temporal.Instant.fromEpochNanoseconds(-0n).epochNanoseconds).toBe(0n);
expect(Temporal.Instant.fromEpochNanoseconds(-1n).epochNanoseconds).toBe(-1n);
expect(Temporal.Instant.fromEpochNanoseconds(-999_999_999n).epochNanoseconds).toBe(-999_999_999n);
expect(Temporal.Instant.fromEpochNanoseconds(-8_640_000_000_000_000_000_000n).epochNanoseconds).toBe(
-8_640_000_000_000_000_000_000n
);
});
});
describe("errors", () => {
test("argument must be coercible to BigInt", () => {
expect(() => {
Temporal.Instant.fromEpochNanoseconds(123);
}).toThrowWithMessage(TypeError, "Cannot convert number to BigInt");
expect(() => {
Temporal.Instant.fromEpochNanoseconds("foo");
}).toThrowWithMessage(SyntaxError, "Invalid value for BigInt: foo");
});
test("out-of-range epoch nanoseconds value", () => {
expect(() => {
Temporal.Instant.fromEpochNanoseconds(8_640_000_000_000_000_000_001n);
}).toThrowWithMessage(
RangeError,
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
);
expect(() => {
Temporal.Instant.fromEpochNanoseconds(-8_640_000_000_000_000_000_001n);
}).toThrowWithMessage(
RangeError,
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
);
});
});