Temporal: Update PlainMonthDay-related tests

As of https://github.com/tc39/proposal-temporal/pull/2500 ,
year is always optional for the ISO 8601 calendar.
This commit is contained in:
Richard Gibson 2023-08-21 17:20:34 -04:00
parent 6396ebde03
commit 5c629683f2
9 changed files with 154 additions and 169 deletions

View File

@ -9,6 +9,11 @@ features: [Symbol.species, Symbol.iterator, Temporal]
const ASCII_IDENTIFIER = /^[$_a-zA-Z][$_a-zA-Z0-9]*$/u;
let nonDefaultCalendarId = undefined;
try {
nonDefaultCalendarId = Temporal.Calendar.from("hebrew").id;
} catch (err) {}
function formatPropertyName(propertyKey, objectName = "") {
switch (typeof propertyKey) {
case "symbol":
@ -36,6 +41,26 @@ function formatPropertyName(propertyKey, objectName = "") {
const SKIP_SYMBOL = Symbol("Skip");
var TemporalHelpers = {
nonDefaultCalendarId,
/*
* Codes and maximum lengths of months in the ISO 8601 calendar.
*/
ISOMonths: [
{ month: 1, monthCode: "M01", daysInMonth: 31 },
{ month: 2, monthCode: "M02", daysInMonth: 29 },
{ month: 3, monthCode: "M03", daysInMonth: 31 },
{ month: 4, monthCode: "M04", daysInMonth: 30 },
{ month: 5, monthCode: "M05", daysInMonth: 31 },
{ month: 6, monthCode: "M06", daysInMonth: 30 },
{ month: 7, monthCode: "M07", daysInMonth: 31 },
{ month: 8, monthCode: "M08", daysInMonth: 31 },
{ month: 9, monthCode: "M09", daysInMonth: 30 },
{ month: 10, monthCode: "M10", daysInMonth: 31 },
{ month: 11, monthCode: "M11", daysInMonth: 30 },
{ month: 12, monthCode: "M12", daysInMonth: 31 }
],
/*
* assertDuration(duration, years, ..., nanoseconds[, description]):
*

View File

@ -10,31 +10,39 @@ info: |
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(fields) is not Object, throw a TypeError exception.
5. Set options to ? GetOptionsObject(options).
6. Let result be ? ISOMonthDayFromFields(fields, options).
7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]).
6. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
7. Let overflow be ? ToTemporalOverflow(options).
8. Perform ? ISOResolveMonth(fields).
9. Let result be ? ISOMonthDayFromFields(fields, overflow).
10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]).
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const cal = new Temporal.Calendar("iso8601");
let result = cal.monthDayFromFields({ year: 2021, month: 7, day: 3 });
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, "month 7, day 3, with year");
result = cal.monthDayFromFields({ year: 2021, month: 12, day: 31 });
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "month 12, day 31, with year");
result = cal.monthDayFromFields({ monthCode: "M07", day: 3 });
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, "monthCode M07, day 3");
result = cal.monthDayFromFields({ monthCode: "M12", day: 31 });
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "monthCode M12, day 31");
["constrain", "reject"].forEach(function (overflow) {
const opt = { overflow };
const options = [
{ overflow: "constrain" },
{ overflow: "reject" },
{},
undefined,
];
options.forEach((opt) => {
const optionsDesc = opt && JSON.stringify(opt);
result = cal.monthDayFromFields({ year: 2021, month: 7, day: 3 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, "month 7, day 3, with year");
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, `month 7, day 3, with year, options = ${optionsDesc}`);
result = cal.monthDayFromFields({ year: 2021, month: 12, day: 31 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "month 12, day 31, with year");
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, `month 12, day 31, with year, options = ${optionsDesc}`);
result = cal.monthDayFromFields({ monthCode: "M07", day: 3 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, "monthCode M07, day 3");
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, `monthCode M07, day 3, options = ${optionsDesc}`);
result = cal.monthDayFromFields({ monthCode: "M12", day: 31 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "monthCode M12, day 31");
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, `monthCode M12, day 31, options = ${optionsDesc}`);
});
TemporalHelpers.ISOMonths.forEach(({ month, monthCode, daysInMonth }) => {
result = cal.monthDayFromFields({ month, day: daysInMonth });
TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, `month ${month}, day ${daysInMonth}`);
result = cal.monthDayFromFields({ monthCode, day: daysInMonth });
TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, `monthCode ${monthCode}, day ${daysInMonth}`);
});

View File

@ -10,15 +10,19 @@ info: |
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(fields) is not Object, throw a TypeError exception.
5. Set options to ? GetOptionsObject(options).
6. Let result be ? ISOMonthDayFromFields(fields, options).
7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]).
6. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
7. Let overflow be ? ToTemporalOverflow(options).
8. Perform ? ISOResolveMonth(fields).
9. Let result be ? ISOMonthDayFromFields(fields, overflow).
10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601")
assert.throws(TypeError, () => cal.monthDayFromFields({}), "at least one correctly spelled property is required");
assert.throws(TypeError, () => cal.monthDayFromFields({ month: 12 }), "day is required with month");
assert.throws(TypeError, () => cal.monthDayFromFields({ monthCode: "M12" }), "day is required with monthCode");
assert.throws(TypeError, () => cal.monthDayFromFields({ year: 2021, month: 12 }), "day is required with year and month");
assert.throws(TypeError, () => cal.monthDayFromFields({ month: 1, day: 17 }), "year is required if month is present");
assert.throws(TypeError, () => cal.monthDayFromFields({ year: 2021, monthCode: "M12" }), "day is required with year and monthCode");
assert.throws(TypeError, () => cal.monthDayFromFields({ year: 2021, day: 17 }), "either month or monthCode is required");

View File

@ -4,7 +4,7 @@
/*---
esid: sec-temporal.calendar.prototype.monthdayfromfields
description: Errors due to missing properties on fields object are thrown in the correct order
includes: [temporalHelpers.js]
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
@ -23,20 +23,21 @@ const missingDay = {
};
assert.throws(TypeError, () => instance.monthDayFromFields(missingDay), "day should be checked before year and month");
let getMonthCode = false;
let getYear = false;
const monthWithoutYear = {
day: 1,
month: 5,
get monthCode() {
getMonthCode = true;
},
let got = [];
const fieldsSpy = {
get year() {
getYear = true;
got.push("year");
},
get month() {
got.push("month");
},
get monthCode() {
got.push("monthCode");
},
get day() {
got.push("day");
return 1;
},
};
assert.throws(TypeError, () => instance.monthDayFromFields(monthWithoutYear), "year/month should be checked after fetching but before resolving the month code");
assert(getMonthCode, "year/month is checked after fetching monthCode");
assert(getYear, "year/month is fetched after fetching month");
assert.throws(TypeError, () => instance.monthDayFromFields({ day: 1 }), "month should be resolved last");
assert.throws(TypeError, () => instance.monthDayFromFields(fieldsSpy), "incomplete fields should be rejected (but after reading all non-required fields)");
assert.compareArray(got, ["day", "month", "monthCode", "year"], "fields should be read in alphabetical order");

View File

@ -10,8 +10,11 @@ info: |
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(fields) is not Object, throw a TypeError exception.
5. Set options to ? GetOptionsObject(options).
6. Let result be ? ISOMonthDayFromFields(fields, options).
7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]).
6. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
7. Let overflow be ? ToTemporalOverflow(options).
8. Perform ? ISOResolveMonth(fields).
9. Let result be ? ISOMonthDayFromFields(fields, overflow).
10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]).
includes: [temporalHelpers.js]
features: [Temporal]
---*/
@ -19,73 +22,44 @@ features: [Temporal]
const cal = new Temporal.Calendar("iso8601");
const opt = { overflow: "constrain" };
let result = cal.monthDayFromFields({ year: 2021, month: 1, day: 133 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M01", 31, "day is constrained to 31 in month 1");
result = cal.monthDayFromFields({ year: 2021, month: 2, day: 133 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M02", 28, "day is constrained to 28 in month 2 (year 2021)");
result = cal.monthDayFromFields({ year: 2021, month: 3, day: 9033 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M03", 31, "day is constrained to 31 in month 3");
result = cal.monthDayFromFields({ year: 2021, month: 4, day: 50 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M04", 30, "day is constrained to 30 in month 4");
result = cal.monthDayFromFields({ year: 2021, month: 5, day: 77 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M05", 31, "day is constrained to 31 in month 5");
result = cal.monthDayFromFields({ year: 2021, month: 6, day: 33 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M06", 30, "day is constrained to 30 in month 6");
result = cal.monthDayFromFields({ year: 2021, month: 7, day: 33 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M07", 31, "day is constrained to 31 in month 7");
result = cal.monthDayFromFields({ year: 2021, month: 8, day: 300 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M08", 31, "day is constrained to 31 in month 8");
result = cal.monthDayFromFields({ year: 2021, month: 9, day: 400 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M09", 30, "day is constrained to 30 in month 9");
result = cal.monthDayFromFields({ year: 2021, month: 10, day: 400 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M10", 31, "day is constrained to 31 in month 10");
result = cal.monthDayFromFields({ year: 2021, month: 11, day: 400 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M11", 30, "day is constrained to 30 in month 11");
result = cal.monthDayFromFields({ year: 2021, month: 12, day: 500 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "day is constrained to 31 in month 12");
assert.throws(
RangeError,
() => cal.monthDayFromFields({ year: 2021, month: -99999, day: 1 }, opt),
"negative month -99999 is out of range even with overflow constrain"
)
assert.throws(
RangeError,
() => cal.monthDayFromFields({ year: 2021, month: -1, day: 1 }, opt),
"negative month -1 is out of range even with overflow constrain"
)
assert.throws(
RangeError,
() => cal.monthDayFromFields({ year: 2021, month: 0, day: 1 }, opt),
"month zero is out of range even with overflow constrain"
)
result = cal.monthDayFromFields({ year: 2021, month: 13, day: 1 }, opt);
let result = cal.monthDayFromFields({ year: 2021, month: 13, day: 1 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M12", 1, "month 13 is constrained to 12");
result = cal.monthDayFromFields({ year: 2021, month: 999999, day: 500 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "month 999999 is constrained to 12 and day constrained to 31");
result = cal.monthDayFromFields({ monthCode: "M01", day: 133 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M01", 31, "day is constrained to 31 in monthCode M01");
result = cal.monthDayFromFields({ monthCode: "M02", day: 133 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M02", 29, "day is constrained to 29 in monthCode M02");
result = cal.monthDayFromFields({ monthCode: "M03", day: 9033 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M03", 31, "day is constrained to 31 in monthCode M03");
result = cal.monthDayFromFields({ monthCode: "M04", day: 50 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M04", 30, "day is constrained to 30 in monthCode M04");
result = cal.monthDayFromFields({ monthCode: "M05", day: 77 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M05", 31, "day is constrained to 31 in monthCode M05");
result = cal.monthDayFromFields({ monthCode: "M06", day: 33 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M06", 30, "day is constrained to 30 in monthCode M06");
result = cal.monthDayFromFields({ monthCode: "M07", day: 33 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M07", 31, "day is constrained to 31 in monthCode M07");
result = cal.monthDayFromFields({ monthCode: "M08", day: 300 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M08", 31, "day is constrained to 31 in monthCode M08");
result = cal.monthDayFromFields({ monthCode: "M09", day: 400 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M09", 30, "day is constrained to 30 in monthCode M09");
result = cal.monthDayFromFields({ monthCode: "M10", day: 400 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M10", 31, "day is constrained to 31 in monthCode M10");
result = cal.monthDayFromFields({ monthCode: "M11", day: 400 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M11", 30, "day is constrained to 30 in monthCode M11");
result = cal.monthDayFromFields({ monthCode: "M12", day: 500 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "day is constrained to 31 in monthCode M12");
result = cal.monthDayFromFields({ year: 2021, month: 999999, day: 500 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "month 999999 is constrained to 12 and day 500 is constrained to 31");
[-99999, -1, 0].forEach((month) => {
assert.throws(
RangeError,
() => cal.monthDayFromFields({ year: 2021, month, day: 1 }, opt),
`Month ${month} is out of range for 2021 even with overflow: constrain`
);
});
TemporalHelpers.ISOMonths.forEach(({ month, monthCode, daysInMonth }) => {
const day = daysInMonth + 1;
result = cal.monthDayFromFields({ month, day }, opt);
TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth,
`day is constrained from ${day} to ${daysInMonth} in month ${month}`);
result = cal.monthDayFromFields({ month, day: 9001 }, opt);
TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth,
`day is constrained to ${daysInMonth} in month ${month}`);
result = cal.monthDayFromFields({ monthCode, day }, opt);
TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth,
`day is constrained from ${day} to ${daysInMonth} in monthCode ${monthCode}`);
result = cal.monthDayFromFields({ monthCode, day: 9001 }, opt);
TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth,
`day is constrained to ${daysInMonth} in monthCode ${monthCode}`);
});
[ ["month", 2], ["monthCode", "M02"] ].forEach(([ name, value ]) => {
result = cal.monthDayFromFields({ year: 2020, [name]: value, day: 30 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M02", 29, `${name} ${value} is constrained to 29 in leap year 2020`);
result = cal.monthDayFromFields({ year: 2021, [name]: value, day: 29 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M02", 28, `${name} ${value} is constrained to 28 in common year 2021`);
});

View File

@ -10,8 +10,12 @@ info: |
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(fields) is not Object, throw a TypeError exception.
5. Set options to ? GetOptionsObject(options).
6. Let result be ? ISOMonthDayFromFields(fields, options).
7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]).
6. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
7. Let overflow be ? ToTemporalOverflow(options).
8. Perform ? ISOResolveMonth(fields).
9. Let result be ? ISOMonthDayFromFields(fields, overflow).
10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]).
includes: [temporalHelpers.js]
features: [Temporal]
---*/
@ -38,27 +42,21 @@ const cal = new Temporal.Calendar("iso8601");
);
});
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M01", day: 32 }, { overflow: "reject" }), "Day 32 is out of range for monthCode M01");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M02", day: 30 }, { overflow: "reject" }), "Day 30 is out of range for monthCode M02");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M03", day: 32 }, { overflow: "reject" }), "Day 32 is out of range for monthCode M03");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M04", day: 31 }, { overflow: "reject" }), "Day 31 is out of range for monthCode M04");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M05", day: 32 }, { overflow: "reject" }), "Day 32 is out of range for monthCode M05");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M06", day: 31 }, { overflow: "reject" }), "Day 31 is out of range for monthCode M06");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M07", day: 32 }, { overflow: "reject" }), "Day 32 is out of range for monthCode M07");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M08", day: 32 }, { overflow: "reject" }), "Day 32 is out of range for monthCode M08");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M09", day: 31 }, { overflow: "reject" }), "Day 31 is out of range for monthCode M09");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M10", day: 32 }, { overflow: "reject" }), "Day 32 is out of range for monthCode M10");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M11", day: 31 }, { overflow: "reject" }), "Day 31 is out of range for monthCode M11");
assert.throws(RangeError, () => cal.monthDayFromFields(
{ monthCode: "M12", day: 32 }, { overflow: "reject" }), "Day 32 is out of range for monthCode M12");
TemporalHelpers.ISOMonths.forEach(({ month, monthCode, daysInMonth }) => {
const day = daysInMonth + 1;
assert.throws(RangeError,
() => cal.monthDayFromFields({ month, day }, { overflow: "reject" }),
`Day ${day} is out of range for month ${month} with overflow: reject`);
assert.throws(RangeError,
() => cal.monthDayFromFields({ monthCode, day }, { overflow: "reject" }),
`Day ${day} is out of range for monthCode ${monthCode} with overflow: reject`);
});
[ ["month", 2], ["monthCode", "M02"] ].forEach(([ name, value ]) => {
assert.throws(RangeError,
() => cal.monthDayFromFields({ year: 2020, [name]: value, day: 30 }, { overflow: "reject" }),
`Day 30 is out of range for ${name} ${value} in leap year 2020 with overflow: reject`);
assert.throws(RangeError,
() => cal.monthDayFromFields({ year: 2021, [name]: value, day: 29 }, { overflow: "reject" }),
`Day 29 is out of range for ${name} ${value} in common year 2021 with overflow: reject`);
});

View File

@ -1,35 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.monthdayfromfields
description: Use a leap year as the reference year if monthCode is given
info: |
sec-temporal-isomonthdayfromfields:
12. If _monthCode_ is *undefined*, then
a. Let _result_ be ? RegulateISODate(_year_, _month_, _day_, _overflow_).
13. Else,
a. Let _result_ be ? RegulateISODate(_referenceISOYear_, _month_, _day_, _overflow_).
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const cal = new Temporal.Calendar("iso8601");
let result = cal.monthDayFromFields({ year: 2021, monthCode: "M02", day: 29} , { overflow: "constrain" });
TemporalHelpers.assertPlainMonthDay(result, "M02", 28, "year should not be ignored when monthCode is given (overflow constrain");
assert.throws(
RangeError,
() => cal.monthDayFromFields({ year: 2021, monthCode: "M02", day: 29 }, {overflow: "reject"}),
"year should not be ignored when monthCode is given (overflow reject)"
);
result = cal.monthDayFromFields({ year: 2021, month: 2, day: 29 }, { overflow: "constrain" });
TemporalHelpers.assertPlainMonthDay(result, "M02", 28, "year should not be ignored if monthCode is not given (overflow constrain)");
assert.throws(
RangeError,
() => cal.monthDayFromFields({ year: 2021, month: 2, day: 29 }, { overflow: "reject" }),
"year should not be ignored if monthCode is not given (overflow reject)"
);

View File

@ -4,6 +4,7 @@
/*---
esid: sec-temporal.plainmonthday.from
description: Basic tests for PlainMonthDay.from(object) with missing properties.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
@ -12,4 +13,7 @@ assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ day: 15 }), "Only d
assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ monthCode: 'M12' }), "Only monthCode");
assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ monthCode: undefined, day: 15 }), "monthCode undefined");
assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ months: 12, day: 31 }), "months plural");
assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ month: 11, day: 18, calendar: "iso8601" }), "month, day with calendar");
if (TemporalHelpers.nonDefaultCalendarId) {
assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ month: 11, day: 18, calendar: TemporalHelpers.nonDefaultCalendarId }), "month, day with non-iso8601 calendar");
}

View File

@ -13,11 +13,12 @@ const md = Temporal.PlainMonthDay.from("01-15");
TemporalHelpers.assertPlainMonthDay(md.with({ day: 22 }),
"M01", 22, "with({day})");
TemporalHelpers.assertPlainMonthDay(md.with({ month: 12 }),
"M12", 15, "with({month})");
TemporalHelpers.assertPlainMonthDay(md.with({ monthCode: "M12" }),
"M12", 15, "with({monthCode})");
assert.throws(TypeError, () => md.with({ month: 12 }), "with({month})");
TemporalHelpers.assertPlainMonthDay(md.with({ month: 12, monthCode: "M12" }),
"M12", 15, "with({month, monthCode}) agree");
@ -38,3 +39,8 @@ assert.throws(TypeError, () => md.with({ months: 12 }), "with({months})");
TemporalHelpers.assertPlainMonthDay(md.with({ monthCode: "M12", days: 1 }),
"M12", 15, "with({monthCode, days})");
if (TemporalHelpers.nonDefaultCalendarId) {
const calendarMonthDay = Temporal.PlainMonthDay.from({ year: 2021, month: 1, day: 15, calendar: TemporalHelpers.nonDefaultCalendarId });
assert.throws(TypeError, () => calendarMonthDay.with({ month: 12 }), "nonIso8601MonthDay.with({month})");
}