forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for Temporal.Duration.p*.abs
(Philip, March 2022: This was originally Frank's PR tc39#3062. I did some reformatting and removed duplicate tests)
- Loading branch information
1 parent
f894988
commit 1a516bc
Showing
1 changed file
with
39 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,39 @@ | ||
// 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.duration.prototype.abs | ||
description: Temporal.Duration.prototype.abs will return absolute value of the input duration. | ||
info: | | ||
1. Let duration be the this value. | ||
2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). | ||
3. Return ? CreateTemporalDuration(abs(duration.[[Years]]), abs(duration.[[Months]]), abs(duration.[[Weeks]]), abs(duration.[[Days]]), abs(duration.[[Hours]]), abs(duration.[[Minutes]]), abs(duration.[[Seconds]]), abs(duration.[[Milliseconds]]), abs(duration.[[Microseconds]]), abs(duration.[[Nanoseconds]])). | ||
features: [Temporal] | ||
includes: [temporalHelpers.js] | ||
---*/ | ||
|
||
let d1 = new Temporal.Duration(); | ||
TemporalHelpers.assertDuration( | ||
d1.abs(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "empty"); | ||
|
||
let d2 = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | ||
TemporalHelpers.assertDuration( | ||
d2.abs(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "positive"); | ||
|
||
let d3 = new Temporal.Duration(1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5); | ||
TemporalHelpers.assertDuration( | ||
d3.abs(), 1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5, "large positive"); | ||
|
||
let d4 = new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10); | ||
TemporalHelpers.assertDuration( | ||
d4.abs(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "negative"); | ||
|
||
// Test with some zeros | ||
let d5 = new Temporal.Duration(1, 0, 3, 0, 5, 0, 7, 0, 9, 0); | ||
TemporalHelpers.assertDuration( | ||
d5.abs(), 1, 0, 3, 0, 5, 0, 7, 0, 9, 0, "some zeros"); | ||
|
||
let d6 = new Temporal.Duration(0, 2, 0, 4, 0, 6, 0, 8, 0, 10); | ||
TemporalHelpers.assertDuration( | ||
d6.abs(), 0, 2, 0, 4, 0, 6, 0, 8, 0, 10, "other zeros"); |