-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for Date.prototype.toTemporalInstant
- Loading branch information
Showing
8 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2024 André Bargull. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-date.prototype.totemporalinstant | ||
description: > | ||
Date.prototype.toTemporalInstant.length is 0. | ||
info: | | ||
Date.prototype.toTemporalInstant ( ) | ||
17 ECMAScript Standard Built-in Objects: | ||
Every built-in function object, including constructors, has a "length" | ||
property whose value is a non-negative integral Number. Unless otherwise | ||
specified, this value is the number of required parameters shown in the | ||
subclause heading for the function description. Optional parameters and rest | ||
parameters are not included in the parameter count. | ||
Unless otherwise specified, the "length" property of a built-in function | ||
object has the attributes { [[Writable]]: false, [[Enumerable]]: false, | ||
[[Configurable]]: true }. | ||
includes: [propertyHelper.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
verifyProperty(Date.prototype.toTemporalInstant, "length", { | ||
value: 0, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-date.prototype.totemporalinstant | ||
description: > | ||
Date.prototype.toTemporalInstant.name is "toTemporalInstant". | ||
info: | | ||
Date.prototype.toTemporalInstant ( ) | ||
17 ECMAScript Standard Built-in Objects: | ||
Every built-in Function object, including constructors, that is not | ||
identified as an anonymous function has a name property whose value | ||
is a String. | ||
Unless otherwise specified, the name property of a built-in Function | ||
object, if it exists, has the attributes { [[Writable]]: false, | ||
[[Enumerable]]: false, [[Configurable]]: true }. | ||
includes: [propertyHelper.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
verifyProperty(Date.prototype.toTemporalInstant, "name", { | ||
value: "toTemporalInstant", | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Date/prototype/toTemporalInstant/not-a-constructor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2024 André Bargull. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-date.prototype.totemporalinstant | ||
description: > | ||
Date.prototype.toTemporalInstant does not implement [[Construct]] | ||
info: | | ||
ECMAScript Function Objects | ||
Built-in function objects that are not identified as constructors do not | ||
implement the [[Construct]] internal method unless otherwise specified in | ||
the description of a particular function. | ||
includes: [isConstructor.js] | ||
features: [Temporal, Reflect.construct] | ||
---*/ | ||
|
||
assert.sameValue( | ||
isConstructor(Date.prototype.toTemporalInstant), | ||
false, | ||
'isConstructor(Date.prototype.toTemporalInstant) must return false' | ||
); | ||
|
||
var date = new Date(0); | ||
|
||
assert.throws(TypeError, function() { | ||
new date.toTemporalInstant(); | ||
}); | ||
|
23 changes: 23 additions & 0 deletions
23
test/built-ins/Date/prototype/toTemporalInstant/prop-desc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2024 André Bargull. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-date.prototype.totemporalinstant | ||
description: > | ||
Property descriptor for Date.prototype.toTemporalInstant. | ||
info: | | ||
Date.prototype.toTemporalInstant ( ) | ||
17 ECMAScript Standard Built-in Objects: | ||
Every other data property described in clauses 19 through 28 and in | ||
Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, | ||
[[Configurable]]: true } unless otherwise specified. | ||
includes: [propertyHelper.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
verifyProperty(Date.prototype, "toTemporalInstant", { | ||
writable: true, | ||
enumerable: false, | ||
configurable: true, | ||
}); |
22 changes: 22 additions & 0 deletions
22
test/built-ins/Date/prototype/toTemporalInstant/this-value-invalid-date.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2024 André Bargull. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-date.prototype.totemporalinstant | ||
description: > | ||
Throws RangeError for invalid dates. | ||
info: | | ||
Date.prototype.toTemporalInstant ( ) | ||
... | ||
3. Let t be dateObject.[[DateValue]]. | ||
4. Let ns be ? NumberToBigInt(t) × ℤ(10**6). | ||
... | ||
features: [Temporal] | ||
---*/ | ||
|
||
var date = new Date(NaN); | ||
|
||
assert.throws(RangeError, function() { | ||
date.toTemporalInstant(); | ||
}); |
43 changes: 43 additions & 0 deletions
43
test/built-ins/Date/prototype/toTemporalInstant/this-value-non-date.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (C) 2024 André Bargull. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-date.prototype.totemporalinstant | ||
description: > | ||
Behaviour when "this" value is an Object without a [[DateValue]] internal slot | ||
info: | | ||
Date.prototype.toTemporalInstant ( ) | ||
1. Let dateObject be the this value. | ||
2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]). | ||
... | ||
features: [Temporal] | ||
---*/ | ||
|
||
var toTemporalInstant = Date.prototype.toTemporalInstant; | ||
|
||
var args = (function() { | ||
return arguments; | ||
}()); | ||
|
||
assert.sameValue(typeof toTemporalInstant, "function"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call({}); | ||
}, "ordinary object"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call([]); | ||
}, "array exotic object"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(args); | ||
}, "arguments exotic object"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(function(){}); | ||
}, "function object"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(Date.prototype); | ||
}, "Date.prototype"); |
48 changes: 48 additions & 0 deletions
48
test/built-ins/Date/prototype/toTemporalInstant/this-value-non-object.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (C) 2024 André Bargull. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-date.prototype.totemporalinstant | ||
description: > | ||
Behaviour when "this" value is not an Object | ||
info: | | ||
Date.prototype.toTemporalInstant ( ) | ||
1. Let dateObject be the this value. | ||
2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]). | ||
... | ||
features: [Temporal, Symbol, BigInt] | ||
---*/ | ||
|
||
var toTemporalInstant = Date.prototype.toTemporalInstant; | ||
var symbol = Symbol(); | ||
|
||
assert.sameValue(typeof toTemporalInstant, "function"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(0); | ||
}, "number"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(true); | ||
}, "boolean"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(null); | ||
}, "null"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(undefined); | ||
}, "undefined"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(""); | ||
}, "string"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(symbol); | ||
}, "symbol"); | ||
|
||
assert.throws(TypeError, function() { | ||
toTemporalInstant.call(0n); | ||
}, "bigint"); |
46 changes: 46 additions & 0 deletions
46
test/built-ins/Date/prototype/toTemporalInstant/this-value-valid-date.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2024 André Bargull. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-date.prototype.totemporalinstant | ||
description: > | ||
Return value for valid dates. | ||
info: | | ||
Date.prototype.toTemporalInstant ( ) | ||
... | ||
3. Let t be dateObject.[[DateValue]]. | ||
4. Let ns be ? NumberToBigInt(t) × ℤ(10**6). | ||
5. Return ! CreateTemporalInstant(ns). | ||
features: [Temporal, BigInt] | ||
---*/ | ||
|
||
assert.sameValue( | ||
new Date(0).toTemporalInstant().epochNanoseconds, | ||
0n, | ||
"the (Unix) epoch" | ||
); | ||
|
||
assert.sameValue( | ||
new Date(123_456_789).toTemporalInstant().epochNanoseconds, | ||
123_456_789_000_000n, | ||
"date after the (Unix) epoch" | ||
); | ||
|
||
assert.sameValue( | ||
new Date(-123_456_789).toTemporalInstant().epochNanoseconds, | ||
-123_456_789_000_000n, | ||
"date before the (Unix) epoch" | ||
); | ||
|
||
assert.sameValue( | ||
new Date(-8.64e15).toTemporalInstant().epochNanoseconds, | ||
-8640_000_000_000_000_000_000n, | ||
"start of time" | ||
); | ||
|
||
assert.sameValue( | ||
new Date(8.64e15).toTemporalInstant().epochNanoseconds, | ||
8640_000_000_000_000_000_000n, | ||
"end of time" | ||
); |