Temporal: Coverage for Temporal.PlainTime

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

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.plaintime
description: >
OrdinaryCreateFromConstructor returns with an abrupt completion.
info: |
CreateTemporalTime ( time [ , newTarget ] )
...
2. Let object be ? OrdinaryCreateFromConstructor(newTarget,
"%Temporal.PlainTime.prototype%", « [[InitializedTemporalTime]], [[Time]] »).
...
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.PlainTime, [], newTarget)
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.with
description: >
Throws if overflow is "reject" and any value is outside the valid bounds.
info: |
Temporal.PlainTime.prototype.with ( temporalTimeLike [ , options ] )
...
19. Let result be ? RegulateTime(hour, minute, second, millisecond, microsecond, nanosecond, overflow).
...
RegulateTime ( hour, minute, second, millisecond, microsecond, nanosecond, overflow )
...
2. Else,
a. Assert: overflow is reject.
b. If IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
...
features: [Temporal]
---*/
var instance = new Temporal.PlainTime();
var temporalTimeLikes = [
{hour: -1},
{hour: 24},
{minute: -1},
{minute: 60},
{second: -1},
{second: 60},
{millisecond: -1},
{millisecond: 1000},
{microsecond: -1},
{microsecond: 1000},
{nanosecond: -1},
{nanosecond: 1000},
];
var options = {overflow: "reject"};
for (var temporalTimeLike of temporalTimeLikes) {
assert.throws(
RangeError,
() => instance.with(temporalTimeLike, options),
`temporalTimeLike = ${JSON.stringify(temporalTimeLike)}`
);
}

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.plaintime
description: >
Throws if any value is outside the valid bounds.
info: |
Temporal.PlainTime ( [ hour [ , minute [ , second [ , millisecond [ , microsecond [ , nanosecond ] ] ] ] ] ] )
...
8. If IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
...
features: [Temporal]
---*/
var invalidArgs = [
[-1],
[24],
[0, -1],
[0, 60],
[0, 0, -1],
[0, 0, 60],
[0, 0, 0, -1],
[0, 0, 0, 1000],
[0, 0, 0, 0, -1],
[0, 0, 0, 0, 1000],
[0, 0, 0, 0, 0, -1],
[0, 0, 0, 0, 0, 1000],
];
for (var args of invalidArgs) {
assert.throws(
RangeError,
() => new Temporal.PlainTime(...args),
`args = ${JSON.stringify(args)}`
);
}