mirror of https://github.com/tc39/test262.git
Test PlainDate#{add,subtract}.
This commit is contained in:
parent
3dfc587f36
commit
3fd429b231
16
test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-duration.js
vendored
Normal file
16
test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-duration.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.add
|
||||
description: RangeError thrown when signs don't match in the duration
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarThrowEverything();
|
||||
const date = new Temporal.PlainDate(2000, 5, 2, calendar);
|
||||
const duration = { months: 1, days: -30 };
|
||||
for (const overflow of ["constrain", "reject"]) {
|
||||
assert.throws(RangeError, () => date.add(duration, { overflow }));
|
||||
}
|
18
test/built-ins/Temporal/PlainDate/prototype/add/argument-missing-properties.js
vendored
Normal file
18
test/built-ins/Temporal/PlainDate/prototype/add/argument-missing-properties.js
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.add
|
||||
description: TypeError for missing properties
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const date = new Temporal.PlainDate(2000, 5, 2);
|
||||
const options = {
|
||||
get overflow() {
|
||||
TemporalHelpers.assertUnreachable("should not get overflow");
|
||||
}
|
||||
};
|
||||
assert.throws(TypeError, () => date.add({}, options), "empty object");
|
||||
assert.throws(TypeError, () => date.add({ month: 12 }, options), "misspelled 'months'");
|
|
@ -18,4 +18,6 @@ features: [Temporal]
|
|||
|
||||
const date = new Temporal.PlainDate(2000, 5, 2);
|
||||
const duration = new Temporal.Duration(3, 3, 0, 3);
|
||||
assert.throws(RangeError, () => date.add(duration, { overflow: "other string" }));
|
||||
for (const overflow of ["", "CONSTRAIN", "balance", "other string", "constra\u0131n"]) {
|
||||
assert.throws(RangeError, () => date.add(duration, { overflow }));
|
||||
}
|
||||
|
|
|
@ -24,3 +24,5 @@ const explicit = date.add(duration, { overflow: undefined });
|
|||
TemporalHelpers.assertPlainDate(explicit, 2003, 6, "M06", 30, "default overflow is constrain");
|
||||
const implicit = date.add(duration, {});
|
||||
TemporalHelpers.assertPlainDate(implicit, 2003, 6, "M06", 30, "default overflow is constrain");
|
||||
const lambda = date.add(duration, () => {});
|
||||
TemporalHelpers.assertPlainDate(lambda, 2003, 6, "M06", 30, "default overflow is constrain");
|
||||
|
|
16
test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-duration.js
vendored
Normal file
16
test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-duration.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.subtract
|
||||
description: RangeError thrown when signs don't match in the duration
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarThrowEverything();
|
||||
const date = new Temporal.PlainDate(2000, 5, 2, calendar);
|
||||
const duration = { months: 1, days: -30 };
|
||||
for (const overflow of ["constrain", "reject"]) {
|
||||
assert.throws(RangeError, () => date.subtract(duration, { overflow }));
|
||||
}
|
18
test/built-ins/Temporal/PlainDate/prototype/subtract/argument-missing-properties.js
vendored
Normal file
18
test/built-ins/Temporal/PlainDate/prototype/subtract/argument-missing-properties.js
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.subtract
|
||||
description: TypeError for missing properties
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const date = new Temporal.PlainDate(2000, 5, 2);
|
||||
const options = {
|
||||
get overflow() {
|
||||
TemporalHelpers.assertUnreachable("should not get overflow");
|
||||
}
|
||||
};
|
||||
assert.throws(TypeError, () => date.subtract({}, options), "empty object");
|
||||
assert.throws(TypeError, () => date.subtract({ month: 12 }, options), "misspelled 'months'");
|
|
@ -18,4 +18,6 @@ features: [Temporal]
|
|||
|
||||
const date = new Temporal.PlainDate(2000, 5, 2);
|
||||
const duration = new Temporal.Duration(3, 3, 0, 3);
|
||||
assert.throws(RangeError, () => date.subtract(duration, { overflow: "other string" }));
|
||||
for (const overflow of ["", "CONSTRAIN", "balance", "other string", "constra\u0131n"]) {
|
||||
assert.throws(RangeError, () => date.subtract(duration, { overflow }));
|
||||
}
|
||||
|
|
|
@ -24,3 +24,5 @@ const explicit = date.subtract(duration, { overflow: undefined });
|
|||
TemporalHelpers.assertPlainDate(explicit, 1997, 4, "M04", 30, "default overflow is constrain");
|
||||
const implicit = date.subtract(duration, {});
|
||||
TemporalHelpers.assertPlainDate(implicit, 1997, 4, "M04", 30, "default overflow is constrain");
|
||||
const lambda = date.subtract(duration, {});
|
||||
TemporalHelpers.assertPlainDate(lambda, 1997, 4, "M04", 30, "default overflow is constrain");
|
||||
|
|
Loading…
Reference in New Issue