-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Tests for upper limit on rounding increments
Previously in a few cases (calendar units in Duration) the value for the roundingIncrement option had no upper limit, other than having to be finite. These tests cover a normative change limiting it to 1e9. Normative PR: tc39/proposal-temporal#2480
- Loading branch information
Showing
35 changed files
with
346 additions
and
104 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Duration/prototype/round/roundingincrement-non-integer.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) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: Rounding for roundingIncrement option | ||
info: | | ||
sec-temporal-totemporalroundingincrement: | ||
3. Let _integerIncrement_ be truncate(ℝ(_increment_)). | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(1); | ||
const options = { | ||
smallestUnit: "years", | ||
roundingMode: "expand", | ||
relativeTo: new Temporal.PlainDate(2000, 1, 1), | ||
}; | ||
const result = instance.round({ ...options, roundingIncrement: 2.5 }); | ||
TemporalHelpers.assertDuration(result, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2"); | ||
const result2 = instance.round({ ...options, roundingIncrement: 1e9 + 0.5 }); | ||
TemporalHelpers.assertDuration(result2, 1e9, 0, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); |
19 changes: 19 additions & 0 deletions
19
test/built-ins/Temporal/Duration/prototype/round/roundingincrement-out-of-range.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,19 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: RangeError thrown when roundingIncrement option out of range | ||
info: | | ||
sec-temporal-totemporalroundingincrement: | ||
4. If _integerIncrement_ < 1 or _integerIncrement_ > 10<sup>9</sup>, throw a *RangeError* exception. | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(1); | ||
const options = { smallestUnit: "years", relativeTo: new Temporal.PlainDate(2000, 1, 1) }; | ||
assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: -Infinity })); | ||
assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: -1 })); | ||
assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: 0 })); | ||
assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: 1e9 + 1 })); | ||
assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: Infinity })); |
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.