Add tests for limits in PlainDate.

This commit is contained in:
Ms2ger 2021-12-28 11:05:48 +01:00 committed by Rick Waldron
parent 88f2eb7329
commit aa77abd928
4 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,28 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.from
description: PlainDate.from enforces the supported range
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const tooEarly = { year: -271821, month: 4, day: 18 };
const tooLate = { year: 275760, month: 9, day: 14 };
["reject", "constrain"].forEach((overflow) => {
[tooEarly, tooLate, "-271821-04-18", "+275760-09-14"].forEach((value) => {
assert.throws(RangeError, () => Temporal.PlainDate.from(value, { overflow }),
`${JSON.stringify(value)} with ${overflow}`);
});
});
TemporalHelpers.assertPlainDate(Temporal.PlainDate.from({ year: -271821, month: 4, day: 19 }),
-271821, 4, "M04", 19, "min object");
TemporalHelpers.assertPlainDate(Temporal.PlainDate.from({ year: 275760, month: 9, day: 13 }),
275760, 9, "M09", 13, "max object");
TemporalHelpers.assertPlainDate(Temporal.PlainDate.from("-271821-04-19"),
-271821, 4, "M04", 19, "min string");
TemporalHelpers.assertPlainDate(Temporal.PlainDate.from("+275760-09-13"),
275760, 9, "M09", 13, "max string");

View File

@ -0,0 +1,16 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate
description: Limits for the PlainDate constructor.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
assert.throws(RangeError, () => new Temporal.PlainDate(-271821, 4, 18), "min");
assert.throws(RangeError, () => new Temporal.PlainDate(275760, 9, 14), "max");
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(-271821, 4, 19),
-271821, 4, "M04", 19, "min");
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(275760, 9, 13),
275760, 9, "M09", 13, "max");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Temporal.PlainDate.prototype.add throws a RangeError if the calculation crosses a limit
esid: sec-temporal.plaindate.prototype.add
features: [Temporal]
---*/
const min = Temporal.PlainDate.from("-271821-04-19");
const max = Temporal.PlainDate.from("+275760-09-13");
["reject", "constrain"].forEach((overflow) => {
assert.throws(RangeError, () => min.add({ days: -1 }, { overflow }), `min with ${overflow}`);
assert.throws(RangeError, () => max.add({ days: 1 }, { overflow }), `max with ${overflow}`);
});

View File

@ -0,0 +1,15 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Temporal.PlainDate.prototype.subtract throws a RangeError if the calculation crosses a limit
esid: sec-temporal.plaindate.prototype.subtract
features: [Temporal]
---*/
const min = Temporal.PlainDate.from("-271821-04-19");
const max = Temporal.PlainDate.from("+275760-09-13");
["reject", "constrain"].forEach((overflow) => {
assert.throws(RangeError, () => min.subtract({ days: 1 }, { overflow }), `min with ${overflow}`);
assert.throws(RangeError, () => max.subtract({ days: -1 }, { overflow }), `max with ${overflow}`);
});