Test PlainDate#{add,subtract}.

This commit is contained in:
Ms2ger 2022-01-20 11:54:12 +01:00 committed by Rick Waldron
parent 3dfc587f36
commit 3fd429b231
8 changed files with 78 additions and 2 deletions

View 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 }));
}

View 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'");

View File

@ -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 }));
}

View File

@ -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");

View 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 }));
}

View 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'");

View File

@ -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 }));
}

View File

@ -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");