mirror of https://github.com/tc39/test262.git
Temporal: Update tests to account for use of year in ToTemporalMonthDay
Ref https://github.com/tc39/proposal-temporal/issues/2863 Normative PR: https://github.com/tc39/proposal-temporal/pull/2940
This commit is contained in:
parent
dfece8cfc5
commit
de3a117f02
|
@ -10,22 +10,28 @@ features: [Temporal]
|
|||
|
||||
const result1 = Temporal.PlainMonthDay.from({ year: 2021, monthCode: "M02", day: 29, calendar: "gregory" });
|
||||
TemporalHelpers.assertPlainMonthDay(
|
||||
result1, "M02", 29,
|
||||
"year is ignored and reference year should be 1972 if monthCode is given",
|
||||
result1, "M02", 28,
|
||||
"year and monthCode determine if calendar date exists, but reference year should be 1972",
|
||||
1972
|
||||
);
|
||||
|
||||
const result2 = Temporal.PlainMonthDay.from({ year: 2021, month: 2, day: 29, calendar: "gregory" }, { overflow: "constrain" });
|
||||
TemporalHelpers.assertPlainMonthDay(
|
||||
result2, "M02", 28,
|
||||
"if monthCode is not given, year is used to determine if calendar date exists, but reference year should still be 1972",
|
||||
"year and month determine if calendar date exists, but reference year should be 1972",
|
||||
1972
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.PlainMonthDay.from({ year: 2021, monthCode: "M02", day: 29, calendar: "gregory" }, { overflow: "reject" }),
|
||||
"RangeError thrown if monthCode and day does not exist in given year and overflow is reject"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.PlainMonthDay.from({ year: 2021, month: 2, day: 29, calendar: "gregory" }, { overflow: "reject" }),
|
||||
"RangeError thrown if calendar date does not exist in given year and overflow is reject"
|
||||
"RangeError thrown if month and day does not exist in given year and overflow is reject"
|
||||
);
|
||||
|
||||
const result3 = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: "hebrew" });
|
||||
|
@ -44,28 +50,41 @@ TemporalHelpers.assertPlainMonthDay(
|
|||
|
||||
const result5 = Temporal.PlainMonthDay.from({ year: 5781, monthCode: "M02", day: 30, calendar: "hebrew" });
|
||||
TemporalHelpers.assertPlainMonthDay(
|
||||
result5, "M02", 30,
|
||||
"year is ignored if monthCode is given (Cheshvan 5781 has 29 days)",
|
||||
1971
|
||||
result5, "M02", 29,
|
||||
"year and monthCode determine if calendar date exists, and reference year must agree (Cheshvan 5781 has 29 days)",
|
||||
1972
|
||||
);
|
||||
|
||||
const result6 = Temporal.PlainMonthDay.from({ year: 5781, month: 2, day: 30, calendar: "hebrew" }, { overflow: "constrain" });
|
||||
TemporalHelpers.assertPlainMonthDay(
|
||||
result6, "M02", 29,
|
||||
"if monthCode is not given, year is used to determine if calendar date exists, but reference year still correct",
|
||||
"year and month determine if calendar date exists, and reference year must agree (Cheshvan 5781 has 29 days)",
|
||||
1972
|
||||
);
|
||||
|
||||
const result7 = Temporal.PlainMonthDay.from({ monthCode: "M02", day: 30, calendar: "hebrew" });
|
||||
TemporalHelpers.assertPlainMonthDay(
|
||||
result7, "M02", 30,
|
||||
"reference year must be the latest ISO year at or before 1972 that includes monthCode and day (Cheshvan 5781 has 29 days)",
|
||||
1971
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.PlainMonthDay.from({ year: 5781, monthCode: "M02", day: 30, calendar: "hebrew" }, { overflow: "reject" }),
|
||||
"RangeError thrown if monthCode and day does not exist in given year and overflow is reject"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.PlainMonthDay.from({ year: 5781, month: 2, day: 30, calendar: "hebrew" }, { overflow: "reject" }),
|
||||
"RangeError thrown if calendar date does not exist in given year and overflow is reject"
|
||||
"RangeError thrown if month and day does not exist in given year and overflow is reject"
|
||||
);
|
||||
|
||||
const result7 = Temporal.PlainMonthDay.from({ monthCode: "M04", day: 26, calendar: "hebrew" });
|
||||
const result8 = Temporal.PlainMonthDay.from({ monthCode: "M04", day: 26, calendar: "hebrew" });
|
||||
TemporalHelpers.assertPlainMonthDay(
|
||||
result7, "M04", 26,
|
||||
result8, "M04", 26,
|
||||
"reference date should be the later one, if two options exist in ISO year 1972",
|
||||
1972
|
||||
);
|
||||
assert.sameValue(result7.toString(), "1972-12-31[u-ca=hebrew]", "reference date");
|
||||
assert.sameValue(result8.toString(), "1972-12-31[u-ca=hebrew]", "reference date");
|
||||
|
|
Loading…
Reference in New Issue