-
Notifications
You must be signed in to change notification settings - Fork 474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for Temporal.Instant.p*.subtract #3076
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
test/built-ins/Temporal/Instant/prototype/subtract/normal.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,38 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.subtract | ||
description: Temporal.Instant.prototype.subtract() return correct value with Temporal.Instant object. | ||
info: | | ||
1. Let instant be the this value. | ||
2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]). | ||
3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « "years", "months", "weeks", "days" »). | ||
4. Let ns be ? AddInstant(instant.[[EpochNanoseconds]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]). | ||
5. Return ! CreateTemporalInstant(ns). | ||
features: [Temporal] | ||
---*/ | ||
let i1 = new Temporal.Instant(50000n); | ||
assert.sameValue(-2952001n, | ||
i1.subtract(new Temporal.Duration(0,0,0,0,0,0,0,3,2,1)).epochNanoseconds); | ||
|
||
assert.sameValue(BigInt(-4 * 1e9) - 2952001n, | ||
i1.subtract(new Temporal.Duration(0,0,0,0,0,0,4,3,2,1)).epochNanoseconds); | ||
|
||
assert.sameValue(BigInt(5 * 60 + 4) * -1000000000n - 2952001n, | ||
i1.subtract(new Temporal.Duration(0,0,0,0,0,5,4,3,2,1)).epochNanoseconds); | ||
|
||
assert.sameValue(BigInt(6 * 3600 + 5 * 60 + 4) * -1000000000n - 2952001n, | ||
i1.subtract(new Temporal.Duration(0,0,0,0,6,5,4,3,2,1)).epochNanoseconds); | ||
|
||
assert.sameValue(3052001n, | ||
i1.subtract(new Temporal.Duration(0,0,0,0,0,0,0,-3,-2,-1)).epochNanoseconds); | ||
|
||
assert.sameValue(BigInt(4 * 1e9) + 3052001n, | ||
i1.subtract(new Temporal.Duration(0,0,0,0,0,0,-4,-3,-2,-1)).epochNanoseconds); | ||
|
||
assert.sameValue(BigInt(5 * 60 + 4) * 1000000000n + 3052001n, | ||
i1.subtract(new Temporal.Duration(0,0,0,0,0,-5,-4,-3,-2,-1)).epochNanoseconds); | ||
|
||
assert.sameValue(BigInt(6 * 3600 + 5 * 60 + 4) * 1000000000n + 3052001n, | ||
i1.subtract(new Temporal.Duration(0,0,0,0,-6,-5,-4,-3,-2,-1)).epochNanoseconds); |
21 changes: 21 additions & 0 deletions
21
test/built-ins/Temporal/Instant/prototype/subtract/throw-range-error-from-AddInstant.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,21 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.subtract | ||
description: Temporal.Instant.prototype.subtract() throws RangeError while the result is too big or too small. | ||
info: | | ||
1. Let instant be the this value. | ||
2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]). | ||
3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « "years", "months", "weeks", "days" »). | ||
4. Let ns be ? AddInstant(instant.[[EpochNanoseconds]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]). | ||
5. Return ! CreateTemporalInstant(ns). | ||
features: [Temporal] | ||
---*/ | ||
let i1 = new Temporal.Instant(-86400n * 99999999999999999n); | ||
assert.throws(RangeError, () => i1.subtract(new Temporal.Duration(0, 0, 0, 0, 999999999)), | ||
"subtract show throw from AddInstant while the result is out of range"); | ||
|
||
let i2 = new Temporal.Instant(86400n * 99999999999999999n); | ||
assert.throws(RangeError, () => i2.subtract(new Temporal.Duration(0, 0, 0, 0, -999999999)), | ||
"subtract show throw from AddInstant while the result is out of range"); |
29 changes: 29 additions & 0 deletions
29
...s/Temporal/Instant/prototype/subtract/throw-range-error-from-ToLimitedTemporalDuration.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) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.subtract | ||
description: Temporal.Instant.prototype.subtract() throws RangeError while the duration has | ||
non zeros years, months, weeks or days. | ||
info: | | ||
1. Let instant be the this value. | ||
3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « "years", "months", "weeks", "days" »). | ||
features: [Temporal] | ||
---*/ | ||
let i1 = new Temporal.Instant(500000n); | ||
assert.throws(RangeError, () => i1.subtract(new Temporal.Duration(1)), | ||
"subtract throw RangeError while the duration has non zero years"); | ||
assert.throws(RangeError, () => i1.subtract(new Temporal.Duration(0, 2)), | ||
"subtract throw RangeError while the duration has non zero months"); | ||
assert.throws(RangeError, () => i1.subtract(new Temporal.Duration(0, 0, 3)), | ||
"subtract throw RangeError while the duration has non zero weeks"); | ||
assert.throws(RangeError, () => i1.subtract(new Temporal.Duration(0, 0, 0, 4)), | ||
"subtract throw RangeError while the duration has non zero days"); | ||
assert.throws(RangeError, () => i1.subtract(new Temporal.Duration(-1)), | ||
"subtract throw RangeError while the duration has non zero years"); | ||
assert.throws(RangeError, () => i1.subtract(new Temporal.Duration(0, -2)), | ||
"subtract throw RangeError while the duration has non zero months"); | ||
assert.throws(RangeError, () => i1.subtract(new Temporal.Duration(0, 0, -3)), | ||
"subtract throw RangeError while the duration has non zero weeks"); | ||
assert.throws(RangeError, () => i1.subtract(new Temporal.Duration(0, 0, 0, -4)), | ||
"subtract throw RangeError while the duration has non zero days"); |
18 changes: 18 additions & 0 deletions
18
...uilt-ins/Temporal/Instant/prototype/subtract/throw-type-error-from-RequireInternalSlot.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,18 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.subtract | ||
description: Temporal.Instant.prototype.subtract() throws TypeError while instant does | ||
not have [[InitializedTemporalInstant]]. | ||
info: | | ||
1. Let instant be the this value. | ||
2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]). | ||
features: [Temporal] | ||
---*/ | ||
let i1 = new Temporal.Instant(50000n); | ||
|
||
// Test RequireInternalSlot Throw TypeError | ||
let badInstant = { subtract: i1.subtract }; | ||
assert.throws(TypeError, () => badInstant.subtract(new Temporal.Duration(0, 0, 0, 0, 5)), | ||
"Throw TypeError while instant does not have [[InitializedTemporalInstant]]"); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider combining with https://github.com/tc39/proposal-temporal/blob/main/polyfill/test/Instant/prototype/subtract/result-out-of-range.js