Temporal: Coverage for Temporal.Instant

This commit is contained in:
André Bargull 2024-11-19 16:30:19 +01:00 committed by Philip Chimento
parent fef2f1cf61
commit 934563c6c4
7 changed files with 170 additions and 0 deletions

View File

@ -0,0 +1,17 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.fromepochmilliseconds
description: >
TypeError thrown if input is of wrong primitive type.
info: |
Temporal.Instant.fromEpochMilliseconds ( epochMilliseconds )
1. Set epochMilliseconds to ? ToNumber(epochMilliseconds).
...
features: [Temporal]
---*/
assert.throws(TypeError, () => Temporal.Instant.fromEpochMilliseconds(42n), "number");
assert.throws(TypeError, () => Temporal.Instant.fromEpochMilliseconds(Symbol()), "symbol");

View File

@ -0,0 +1,28 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.fromepochmilliseconds
description: >
RangeError thrown if input doesn't convert.
info: |
Temporal.Instant.fromEpochMilliseconds ( epochMilliseconds )
...
2. Set epochMilliseconds to ? NumberToBigInt(epochMilliseconds).
...
NumberToBigInt ( number )
1. If number is not an integral Number, throw a RangeError exception.
...
features: [Temporal]
---*/
assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(), "undefined");
assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(undefined), "undefined");
assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(Infinity), "Infinity");
assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(-Infinity), "-Infinity");
assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(NaN), "NaN");
assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(1.3), "1.3");
assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(-0.5), "-0.5");

View File

@ -0,0 +1,20 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.fromepochnanoseconds
description: >
TypeError thrown if input is of wrong primitive type.
info: |
Temporal.Instant.fromEpochNanoseconds ( epochNanoseconds )
1. Set epochNanoseconds to ? ToBigInt(epochNanoseconds).
...
features: [Temporal]
---*/
assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(), "undefined");
assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(undefined), "undefined");
assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(null), "null");
assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(42), "number");
assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(Symbol()), "symbol");

View File

@ -0,0 +1,20 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.fromepochnanoseconds
description: >
Throws a RangeError if the input is not a valid epoch nanoseconds value.
info: |
Temporal.Instant.fromEpochNanoseconds ( epochNanoseconds )
...
2. If IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
...
features: [Temporal]
---*/
var limit = 8640000000000000000000n;
assert.throws(RangeError, () => Temporal.Instant.fromEpochNanoseconds(-limit - 1n));
assert.throws(RangeError, () => Temporal.Instant.fromEpochNanoseconds(limit + 1n));

View File

@ -0,0 +1,39 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant
description: >
OrdinaryCreateFromConstructor returns with an abrupt completion.
info: |
CreateTemporalInstant ( epochNanoseconds [ , newTarget ] )
...
3. Let object be ? OrdinaryCreateFromConstructor(newTarget,
"%Temporal.Instant.prototype%", « [[InitializedTemporalInstant]], [[EpochNanoseconds]] »).
...
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
...
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
...
2. Let proto be ? Get(constructor, "prototype").
...
features: [Temporal]
---*/
var newTarget = Object.defineProperty(function(){}.bind(), "prototype", {
get() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.construct(Temporal.Instant, [0n], newTarget)
});

View File

@ -0,0 +1,21 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant
description: >
Throws a RangeError if the input is far away from the epoch nanoseconds limits.
features: [Temporal]
---*/
assert.throws(
RangeError,
() => new Temporal.Instant(2n ** 128n),
"2n ** 128n"
);
assert.throws(
RangeError,
() => new Temporal.Instant(-(2n ** 128n)),
"-(2n ** 128n)"
);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.prototype.tostring
description: >
Accessor property for "timeZone" throws an error.
info: |
Temporal.Instant.prototype.toString ( [ options ] )
...
9. Let timeZone be ? Get(resolvedOptions, "timeZone").
...
features: [Temporal]
---*/
var instance = new Temporal.Instant(0n);
var options = {
get timeZone() {
throw new Test262Error();
}
};
assert.throws(Test262Error, () => instance.toString(options));