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.
Temporal: Tests for removal of relativeTo from Duration.p.add
See tc39/proposal-temporal#2825. Various edits to existing tests so that they make more sense with the removal of relativeTo. New test specifically testing that calendar units cannot be added directly.
- Loading branch information
Showing
3 changed files
with
40 additions
and
5 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
35 changes: 35 additions & 0 deletions
35
test/built-ins/Temporal/Duration/prototype/add/no-calendar-units.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,35 @@ | ||
// Copyright (C) 2024 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.add | ||
description: > | ||
Throws if either the receiver or the argument is a duration with nonzero | ||
calendar units | ||
features: [Temporal] | ||
---*/ | ||
|
||
const blank = new Temporal.Duration(); | ||
|
||
const withYears = new Temporal.Duration(1); | ||
assert.throws(RangeError, () => withYears.add(blank), "should not add to receiver with years"); | ||
|
||
const withMonths = new Temporal.Duration(0, 1); | ||
assert.throws(RangeError, () => withMonths.add(blank), "should not add to receiver with months"); | ||
|
||
const withWeeks = new Temporal.Duration(0, 0, 1); | ||
assert.throws(RangeError, () => withWeeks.add(blank), "should not add to receiver with weeks"); | ||
|
||
const ok = new Temporal.Duration(0, 0, 0, 1); | ||
|
||
assert.throws(RangeError, () => ok.add(withYears), "should not add duration with years"); | ||
assert.throws(RangeError, () => ok.add(withMonths), "should not add duration with months"); | ||
assert.throws(RangeError, () => ok.add(withWeeks), "should not add duration with weeks"); | ||
|
||
assert.throws(RangeError, () => ok.add({ years: 1 }), "should not add property bag with years"); | ||
assert.throws(RangeError, () => ok.add({ months: 1 }), "should not add property bag with months"); | ||
assert.throws(RangeError, () => ok.add({ weeks: 1 }), "should not add property bag with weeks"); | ||
|
||
assert.throws(RangeError, () => ok.add('P1Y'), "should not add string with years"); | ||
assert.throws(RangeError, () => ok.add('P1M'), "should not add string with months"); | ||
assert.throws(RangeError, () => ok.add('P1W'), "should not add string with weeks"); |
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