-
Notifications
You must be signed in to change notification settings - Fork 472
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/subtract
See tc39/proposal-temporal#2825. Various edits to existing tests so that they make more sense with the removal of relativeTo. New tests specifically testing that calendar units cannot be added or subtracted directly.
- Loading branch information
Showing
6 changed files
with
80 additions
and
10 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
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/subtract/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.subtract | ||
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.subtract(blank), "should not subtract from receiver with years"); | ||
|
||
const withMonths = new Temporal.Duration(0, 1); | ||
assert.throws(RangeError, () => withMonths.subtract(blank), "should not subtract from receiver with months"); | ||
|
||
const withWeeks = new Temporal.Duration(0, 0, 1); | ||
assert.throws(RangeError, () => withWeeks.subtract(blank), "should not subtract from receiver with weeks"); | ||
|
||
const ok = new Temporal.Duration(0, 0, 0, 1); | ||
|
||
assert.throws(RangeError, () => ok.subtract(withYears), "should not subtract duration with years"); | ||
assert.throws(RangeError, () => ok.subtract(withMonths), "should not subtract duration with months"); | ||
assert.throws(RangeError, () => ok.subtract(withWeeks), "should not subtract duration with weeks"); | ||
|
||
assert.throws(RangeError, () => ok.subtract({ years: 1 }), "should not subtract property bag with years"); | ||
assert.throws(RangeError, () => ok.subtract({ months: 1 }), "should not subtract property bag with months"); | ||
assert.throws(RangeError, () => ok.subtract({ weeks: 1 }), "should not subtract property bag with weeks"); | ||
|
||
assert.throws(RangeError, () => ok.subtract('P1Y'), "should not subtract string with years"); | ||
assert.throws(RangeError, () => ok.subtract('P1M'), "should not subtract string with months"); | ||
assert.throws(RangeError, () => ok.subtract('P1W'), "should not subtract 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