Temporal: Expand ISO8601 PlainDate.p.with tests

Move coverage of plural units to a separate file, and add some more
coverage for the overflow option.
This commit is contained in:
Philip Chimento 2025-11-16 09:58:11 -08:00 committed by Ms2ger
parent 2f0cc98718
commit f4367bc315
3 changed files with 73 additions and 5 deletions

View File

@ -21,8 +21,3 @@ TemporalHelpers.assertPlainDate(withMonthCode, 1976, 5, "M05", 18, "with(monthCo
const withDay = plainDate.with({ day: 17 });
TemporalHelpers.assertPlainDate(withDay, 1976, 11, "M11", 17, "with(day)");
const withPlural = plainDate.with({ months: 12, day: 15 });
TemporalHelpers.assertPlainDate(withPlural, 1976, 11, "M11", 15, "with(plural)");
assert.throws(RangeError, () => plainDate.with({ month: 5, monthCode: 'M06' }));

View File

@ -0,0 +1,59 @@
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.with
description: Basic tests for the overflow option
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const date = new Temporal.PlainDate(1976, 11, 18);
assert.throws(
RangeError,
() => date.with({ year: -300000 }),
"too-low year rejects even with overflow constrain");
assert.throws(
RangeError,
() => date.with({ year: 300000 }),
"too-high year rejects even with overflow constrain");
assert.throws(
RangeError,
() => date.with({ month: 0 }),
"non-positive month rejects even with overflow constrain");
TemporalHelpers.assertPlainDate(
date.with({ month: 13 }),
1976, 12, "M12", 18,
"too-high month is constrained to highest value");
assert.throws(RangeError, function () {
date.with({ month: 13 }, { overflow: "reject" });
}, "too-high month rejects");
assert.throws(
RangeError,
() => date.with({ monthCode: "M13" }),
"Invalid monthCode for calendar rejects even with overflow constrain");
assert.throws(
RangeError,
() => date.with({ day: 0 }),
"non-positive day rejects even with overflow constrain");
TemporalHelpers.assertPlainDate(
date.with({ day: 31 }),
1976, 11, "M11", 30,
"too-high day is constrained to highest value");
assert.throws(RangeError, function () {
date.with({ day: 31 }, { overflow: "reject" });
}, "too-high day rejects");
assert.throws(
RangeError,
() => date.with({ month: 5, monthCode: "M06" }),
"Conflicting month and monthCode rejects even with overflow constrain");

View File

@ -0,0 +1,14 @@
// 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.prototype.with
description: Plural units are not valid in the property bag
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const plainDate = new Temporal.PlainDate(1976, 11, 18);
const withPlural = plainDate.with({ months: 12, day: 15 });
TemporalHelpers.assertPlainDate(withPlural, 1976, 11, "M11", 15, "Plural units in the property bag should ignored");