mirror of
https://github.com/tc39/test262.git
synced 2025-07-30 09:24:41 +02:00
Temporal: Coverage for Temporal.Instant
This commit is contained in:
parent
fef2f1cf61
commit
934563c6c4
@ -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");
|
@ -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");
|
@ -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");
|
@ -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));
|
@ -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)
|
||||
});
|
21
test/built-ins/Temporal/Instant/large-bigint.js
Normal file
21
test/built-ins/Temporal/Instant/large-bigint.js
Normal 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)"
|
||||
);
|
25
test/built-ins/Temporal/Instant/prototype/toString/get-timezone-throws.js
vendored
Normal file
25
test/built-ins/Temporal/Instant/prototype/toString/get-timezone-throws.js
vendored
Normal 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));
|
Loading…
x
Reference in New Issue
Block a user