Skip to content

Commit 687cf88

Browse files
authored
Temporal: Add tests for PlainMonthDay.from with month and invalid monthCode (#4597)
1 parent a6f910b commit 687cf88

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/built-ins/Temporal/PlainMonthDay/from/monthcode-invalid.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,29 @@ features: [Temporal]
99

1010
["m1", "M1", "m01"].forEach((monthCode) => {
1111
assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ monthCode, day: 17 }),
12-
`monthCode '${monthCode}' is not well-formed`);
12+
`monthCode '${monthCode}' is not well-formed (without numeric month)`);
13+
assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ month: 1, monthCode, day: 17 }),
14+
`monthCode '${monthCode}' is not well-formed (with numeric month)`);
1315
});
1416

1517
assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ year: 2021, month: 12, monthCode: "M11", day: 17 }),
1618
"monthCode and month conflict");
1719

1820
["M00", "M19", "M99", "M13", "M00L", "M05L", "M13L"].forEach((monthCode) => {
1921
assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ monthCode, day: 17 }),
20-
`monthCode '${monthCode}' is not valid for ISO 8601 calendar`);
22+
`monthCode '${monthCode}' is not valid for ISO 8601 calendar (without numeric month)`);
23+
var monthNumber = Number(monthCode.slice(1, 3)) + (monthCode.length - 3);
24+
assert.throws(
25+
RangeError,
26+
() => Temporal.PlainMonthDay.from({ month: monthNumber, monthCode, day: 17 }),
27+
`monthCode '${monthCode}' is not valid for ISO 8601 calendar (with numeric month)`
28+
);
29+
var clampedMonthNumber = monthNumber < 1 ? 1 : monthNumber > 12 ? 12 : monthNumber;
30+
assert.throws(
31+
RangeError,
32+
() => Temporal.PlainMonthDay.from({ month: clampedMonthNumber, monthCode, day: 17 }),
33+
`monthCode '${monthCode}' is not valid for ISO 8601 calendar (with clamped numeric month)`
34+
);
2135
});
2236

2337
assert.throws(

0 commit comments

Comments
 (0)