Temporal: Don't pass custom calendar in helper tests

This is no longer necessary if there are no calendar objects.
This commit is contained in:
Philip Chimento 2024-06-04 12:49:30 +02:00 committed by Ms2ger
parent 9c6734f39b
commit 372527e572
21 changed files with 37 additions and 70 deletions

View File

@ -332,11 +332,9 @@ var TemporalHelpers = {
* Temporal.PlainDateTime instance, convert to the desired type by reading the
* PlainDateTime's internal slots, rather than calling any getters.
*
* func(datetime, calendar) is the actual operation to test, that must
* func(datetime) is the actual operation to test, that must
* internally call the abstract operation ToTemporalDate or ToTemporalTime.
* It is passed a Temporal.PlainDateTime instance, as well as the instance's
* calendar object (so that it doesn't have to call the calendar getter itself
* if it wants to make any assertions about the calendar.)
* It is passed a Temporal.PlainDateTime instance.
*/
checkPlainDateTimeConversionFastPath(func, message = "checkPlainDateTimeConversionFastPath") {
const actual = [];
@ -370,7 +368,7 @@ var TemporalHelpers = {
},
});
func(datetime, calendar);
func(datetime);
assert.compareArray(actual, expected, `${message}: property getters not called`);
},
@ -888,42 +886,13 @@ var TemporalHelpers = {
* Check that any calendar-carrying Temporal object has its [[Calendar]]
* internal slot read by ToTemporalCalendar, and does not fetch the calendar
* by calling getters.
* The custom calendar object is passed in to func() so that it can do its
* own additional assertions involving the calendar if necessary. (Sometimes
* there is nothing to assert as the calendar isn't stored anywhere that can
* be asserted about.)
*/
checkToTemporalCalendarFastPath(func) {
class CalendarFastPathCheck extends Temporal.Calendar {
constructor() {
super("iso8601");
}
dateFromFields(...args) {
return super.dateFromFields(...args).withCalendar(this);
}
monthDayFromFields(...args) {
const { isoYear, isoMonth, isoDay } = super.monthDayFromFields(...args).getISOFields();
return new Temporal.PlainMonthDay(isoMonth, isoDay, this, isoYear);
}
yearMonthFromFields(...args) {
const { isoYear, isoMonth, isoDay } = super.yearMonthFromFields(...args).getISOFields();
return new Temporal.PlainYearMonth(isoYear, isoMonth, this, isoDay);
}
toString() {
return "fast-path-check";
}
}
const calendar = new CalendarFastPathCheck();
const plainDate = new Temporal.PlainDate(2000, 5, 2, calendar);
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
const plainMonthDay = new Temporal.PlainMonthDay(5, 2, calendar);
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5, calendar);
const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
const plainDate = new Temporal.PlainDate(2000, 5, 2, "iso8601");
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601");
const plainMonthDay = new Temporal.PlainMonthDay(5, 2, "iso8601");
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5, "iso8601");
const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
[plainDate, plainDateTime, plainMonthDay, plainYearMonth, zonedDateTime].forEach((temporalObject) => {
const actual = [];
@ -936,7 +905,7 @@ var TemporalHelpers = {
},
});
func(temporalObject, calendar);
func(temporalObject);
assert.compareArray(actual, expected, "calendar getter not called");
});
},
@ -986,11 +955,11 @@ var TemporalHelpers = {
Object.defineProperty(date, "calendar", {
get() {
actual.push("get calendar");
return calendar;
return "iso8601";
},
});
func(date, calendar);
func(date);
assert.compareArray(actual, expected, "property getters not called");
},

View File

@ -14,8 +14,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime, calendar) => {
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const result = Temporal.PlainDate.from(datetime);
TemporalHelpers.assertPlainDate(result, 2000, 5, "M05", 2);
assert.sameValue(result.getISOFields().calendar, calendar, "calendar result");
});

View File

@ -20,7 +20,6 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject, calendar) => {
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const result = Temporal.PlainDate.from({ year: 2000, month: 5, day: 2, calendar: temporalObject });
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const date = new Temporal.PlainDate(2000, 5, 2, temporalObject);
const date = new Temporal.PlainDate(2000, 5, 2, "iso8601");
date.equals({ year: 2005, month: 6, day: 2, calendar: temporalObject });
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const date = new Temporal.PlainDate(2000, 5, 2, temporalObject);
const date = new Temporal.PlainDate(2000, 5, 2);
date.since({ year: 2005, month: 6, day: 2, calendar: temporalObject });
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const date = new Temporal.PlainDate(2000, 5, 2, temporalObject);
const date = new Temporal.PlainDate(2000, 5, 2, "iso8601");
date.until({ year: 2005, month: 6, day: 2, calendar: temporalObject });
});

View File

@ -14,8 +14,8 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkToTemporalPlainDateTimeFastPath((date, calendar) => {
TemporalHelpers.checkToTemporalPlainDateTimeFastPath((date) => {
const result = Temporal.PlainDateTime.from(date);
TemporalHelpers.assertPlainDateTime(result, 2000, 5, "M05", 2, 0, 0, 0, 0, 0, 0, "midnight is assumed");
assert.sameValue(result.getISOFields().calendar, calendar, "calendar result");
assert.sameValue(result.getISOFields().calendar, "iso8601", "calendar result");
});

View File

@ -20,7 +20,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject, calendar) => {
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const result = Temporal.PlainDateTime.from({ year: 2000, month: 5, day: 2, calendar: temporalObject });
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.getISOFields().calendar, "iso8601", "Temporal object coerced to calendar");
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, temporalObject);
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
datetime.equals({ year: 2005, month: 6, day: 2, calendar: temporalObject });
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, temporalObject);
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
datetime.since({ year: 2005, month: 6, day: 2, calendar: temporalObject });
});

View File

@ -14,8 +14,8 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkToTemporalPlainDateTimeFastPath((date, calendar) => {
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 0, 0, 0, 987, 654, 321, calendar);
TemporalHelpers.checkToTemporalPlainDateTimeFastPath((date) => {
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 0, 0, 0, 987, 654, 321, "iso8601");
const result = datetime.until(date);
assert.sameValue(result.total({ unit: "nanoseconds" }), -987654321, "PlainDate is converted to midnight");
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const date = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, temporalObject);
const date = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
date.until({ year: 2005, month: 6, day: 2, calendar: temporalObject });
});

View File

@ -20,7 +20,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject, calendar) => {
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const result = Temporal.PlainMonthDay.from({ monthCode: "M05", day: 2, calendar: temporalObject });
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.getISOFields().calendar, "iso8601", "Temporal object coerced to calendar");
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const monthday = new Temporal.PlainMonthDay(5, 2, temporalObject);
const monthday = new Temporal.PlainMonthDay(5, 2);
monthday.equals({ monthCode: "M06", day: 2, calendar: temporalObject });
});

View File

@ -20,7 +20,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject, calendar) => {
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const result = Temporal.PlainYearMonth.from({ year: 2000, month: 5, calendar: temporalObject });
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.getISOFields().calendar, "iso8601", "Temporal object coerced to calendar");
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const yearmonth = new Temporal.PlainYearMonth(2000, 5, temporalObject);
const yearmonth = new Temporal.PlainYearMonth(2000, 5);
yearmonth.equals({ year: 2005, month: 6, calendar: temporalObject });
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const yearmonth = new Temporal.PlainYearMonth(2000, 5, temporalObject);
const yearmonth = new Temporal.PlainYearMonth(2000, 5);
yearmonth.since({ year: 2005, month: 6, calendar: temporalObject });
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const yearmonth = new Temporal.PlainYearMonth(2000, 5, temporalObject);
const yearmonth = new Temporal.PlainYearMonth(2000, 5);
yearmonth.until({ year: 2005, month: 6, calendar: temporalObject });
});

View File

@ -20,7 +20,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject, calendar) => {
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const result = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone: "UTC", calendar: temporalObject });
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.getISOFields().calendar, "iso8601", "Temporal object coerced to calendar");
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const datetime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", temporalObject);
const datetime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
datetime.since({ year: 2005, month: 6, day: 2, timeZone: "UTC", calendar: temporalObject });
});

View File

@ -21,6 +21,6 @@ features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const datetime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", temporalObject);
const datetime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
datetime.until({ year: 2005, month: 6, day: 2, timeZone: "UTC", calendar: temporalObject });
});