mirror of https://github.com/tc39/test262.git
Add tests for limits in PlainDate.
This commit is contained in:
parent
88f2eb7329
commit
aa77abd928
|
@ -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");
|
|
@ -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");
|
|
@ -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}`);
|
||||
});
|
|
@ -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}`);
|
||||
});
|
Loading…
Reference in New Issue