-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Add more coverage for non-ISO PlainMonthDay underspecification
Built-in non-ISO calendars require either monthCode/day, or month/day plus some form of year specification. This adds test coverage for each of the categories listed in tc39/proposal-temporal#2664, of which some must currently reside in the test/intl402/ folders.
- Loading branch information
Showing
6 changed files
with
90 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/built-ins/Temporal/PlainMonthDay/from/calendar-monthdayfromfields-validates-fields.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plainmonthday.from | ||
description: > | ||
Calendar.monthDayFromFields method validates which fields must be present | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const calendar = new class extends Temporal.Calendar { | ||
fields(fields) { | ||
return fields.slice().concat("fnord"); | ||
} | ||
monthDayFromFields(fields) { | ||
// accept everything except fnord | ||
assert.sameValue(fields.fnord, undefined); | ||
return new Temporal.PlainMonthDay(1, 1, this, 1972); | ||
} | ||
}("iso8601"); | ||
|
||
// This would throw on any non-ISO builtin calendar | ||
const result = Temporal.PlainMonthDay.from({ month: 8, day: 16, calendar }); | ||
TemporalHelpers.assertPlainMonthDay(result, "M01", 1, "monthDayFromFields determines what fields are necessary") | ||
|
||
assert.throws( | ||
Test262Error, | ||
() => Temporal.PlainMonthDay.from({ monthCode: "M09", day: 19, fnord: "fnord", calendar }), | ||
"monthDayFromFields determines what fields are disallowed" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/intl402/Temporal/Calendar/prototype/monthDayFromFields/fields-underspecified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.monthdayfromfields | ||
description: Throw a RangeError if only one of era/eraYear fields is present | ||
features: [Temporal] | ||
---*/ | ||
|
||
const tests = [ | ||
["gregory", { year: 2000, month: 5, day: 2, era: "ce" }, "era present but not eraYear"], | ||
["gregory", { year: 2000, month: 5, day: 2, eraYear: 1 }, "eraYear present but not era"], | ||
["gregory", { month: 8, day: 1 }, "no monthCode or year specification, non-ISO Gregorian"], | ||
["hebrew", { month: 8, day: 1 }, "no monthCode or year specification, non-ISO non-Gregorian"], | ||
]; | ||
|
||
for (const [calendarId, arg, description] of tests) { | ||
const instance = new Temporal.Calendar(calendarId); | ||
assert.throws(TypeError, () => instance.monthDayFromFields(arg), description); | ||
} |
19 changes: 0 additions & 19 deletions
19
test/intl402/Temporal/Calendar/prototype/monthDayFromFields/one-of-era-erayear-undefined.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plainmonthday.from | ||
description: Basic tests for PlainMonthDay.from(object) with non-ISO calendar | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const okTests = [ | ||
[{ monthCode: "M08", day: 1, calendar: "gregory" }, "gregory", "monthCode and non-ISO Gregorian string calendar"], | ||
[{ monthCode: "M08", day: 1, calendar: "hebrew" }, "hebrew", "monthCode and non-ISO non-Gregorian string calendar"], | ||
[{ monthCode: "M08", day: 1, calendar: Temporal.Calendar.from("gregory") }, "gregory", "monthCode and non-ISO Gregorian object calendar"], | ||
[{ monthCode: "M08", day: 1, calendar: Temporal.Calendar.from("hebrew") }, "hebrew", "monthCode and non-ISO non-Gregorian object calendar"], | ||
]; | ||
|
||
for (const [argument, expectedCalendar, description] of okTests) { | ||
const plainMonthDay = Temporal.PlainMonthDay.from(argument); | ||
TemporalHelpers.assertPlainMonthDay(plainMonthDay, "M08", 1, description); | ||
assert.sameValue(plainMonthDay.calendarId, expectedCalendar, `resulting calendar is ${expectedCalendar}`); | ||
} | ||
|
||
const notOkTests = [ | ||
[{ month: 8, day: 1, calendar: "gregory" }, "month and non-ISO string calendar"], | ||
[{ month: 8, day: 1, calendar: "hebrew" }, "month and non-ISO non-Gregorian string calendar"], | ||
[{ month: 8, day: 1, calendar: Temporal.Calendar.from("gregory") }, "month and non-ISO Gregorian object calendar"], | ||
[{ month: 8, day: 1, calendar: Temporal.Calendar.from("hebrew") }, "month and non-ISO non-Gregorian object calendar"], | ||
]; | ||
|
||
for (const [argument, description] of notOkTests) { | ||
assert.throws(TypeError, () => Temporal.PlainMonthDay.from(argument), description); | ||
} |