diff --git a/harness/temporalHelpers.js b/harness/temporalHelpers.js index 984902aa7b..dfbffd776e 100644 --- a/harness/temporalHelpers.js +++ b/harness/temporalHelpers.js @@ -8,6 +8,114 @@ features: [Symbol.species, Symbol.iterator, Temporal] ---*/ var TemporalHelpers = { + /* + * assertDuration(duration, years, ..., nanoseconds[, description]): + * + * Shorthand for asserting that each field of a Temporal.Duration is equal to + * an expected value. + */ + assertDuration(duration, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, description = "") { + assert(duration instanceof Temporal.Duration, `${description} instanceof`); + assert.sameValue(duration.years, years, `${description} years result`); + assert.sameValue(duration.months, months, `${description} months result`); + assert.sameValue(duration.weeks, weeks, `${description} weeks result`); + assert.sameValue(duration.days, days, `${description} days result`); + assert.sameValue(duration.hours, hours, `${description} hours result`); + assert.sameValue(duration.minutes, minutes, `${description} minutes result`); + assert.sameValue(duration.seconds, seconds, `${description} seconds result`); + assert.sameValue(duration.milliseconds, milliseconds, `${description} milliseconds result`); + assert.sameValue(duration.microseconds, microseconds, `${description} microseconds result`); + assert.sameValue(duration.nanoseconds, nanoseconds, `${description} nanoseconds result`); + }, + + /* + * assertPlainDate(date, year, ..., nanosecond[, description[, era, eraYear]]): + * + * Shorthand for asserting that each field of a Temporal.PlainDate is equal to + * an expected value. (Except the `calendar` property, since callers may want + * to assert either object equality with an object they put in there, or the + * result of date.calendar.toString().) + */ + assertPlainDate(date, year, month, monthCode, day, description = "", era = undefined, eraYear = undefined) { + assert(date instanceof Temporal.PlainDate, `${description} instanceof`); + assert.sameValue(date.era, era, `${description} era result`); + assert.sameValue(date.eraYear, eraYear, `${description} eraYear result`); + assert.sameValue(date.year, year, `${description} year result`); + assert.sameValue(date.month, month, `${description} month result`); + assert.sameValue(date.monthCode, monthCode, `${description} monthCode result`); + assert.sameValue(date.day, day, `${description} day result`); + }, + + /* + * assertPlainDateTime(datetime, year, ..., nanosecond[, description[, era, eraYear]]): + * + * Shorthand for asserting that each field of a Temporal.PlainDateTime is + * equal to an expected value. (Except the `calendar` property, since callers + * may want to assert either object equality with an object they put in there, + * or the result of datetime.calendar.toString().) + */ + assertPlainDateTime(datetime, year, month, monthCode, day, hour, minute, second, millisecond, microsecond, nanosecond, description = "", era = undefined, eraYear = undefined) { + assert(datetime instanceof Temporal.PlainDateTime, `${description} instanceof`); + assert.sameValue(datetime.era, era, `${description} era result`); + assert.sameValue(datetime.eraYear, eraYear, `${description} eraYear result`); + assert.sameValue(datetime.year, year, `${description} year result`); + assert.sameValue(datetime.month, month, `${description} month result`); + assert.sameValue(datetime.monthCode, monthCode, `${description} monthCode result`); + assert.sameValue(datetime.day, day, `${description} day result`); + assert.sameValue(datetime.hour, hour, `${description} hour result`); + assert.sameValue(datetime.minute, minute, `${description} minute result`); + assert.sameValue(datetime.second, second, `${description} second result`); + assert.sameValue(datetime.millisecond, millisecond, `${description} millisecond result`); + assert.sameValue(datetime.microsecond, microsecond, `${description} microsecond result`); + assert.sameValue(datetime.nanosecond, nanosecond, `${description} nanosecond result`); + }, + + /* + * assertPlainMonthDay(monthDay, monthCode, day[, description]): + * + * Shorthand for asserting that each field of a Temporal.PlainMonthDay is + * equal to an expected value. (Except the `calendar` property, since callers + * may want to assert either object equality with an object they put in there, + * or the result of monthDay.calendar.toString().) + */ + assertPlainMonthDay(monthDay, monthCode, day, description = "") { + assert(monthDay instanceof Temporal.PlainMonthDay, `${description} instanceof`); + assert.sameValue(monthDay.monthCode, monthCode, `${description} monthCode result`); + assert.sameValue(monthDay.day, day, `${description} day result`); + }, + + /* + * assertPlainTime(time, hour, ..., nanosecond[, description]): + * + * Shorthand for asserting that each field of a Temporal.PlainTime is equal to + * an expected value. + */ + assertPlainTime(time, hour, minute, second, millisecond, microsecond, nanosecond, description = "") { + assert(time instanceof Temporal.PlainTime, `${description} instanceof`); + assert.sameValue(time.hour, hour, `${description} hour result`); + assert.sameValue(time.minute, minute, `${description} minute result`); + assert.sameValue(time.second, second, `${description} second result`); + assert.sameValue(time.millisecond, millisecond, `${description} millisecond result`); + assert.sameValue(time.microsecond, microsecond, `${description} microsecond result`); + assert.sameValue(time.nanosecond, nanosecond, `${description} nanosecond result`); + }, + + /* + * assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]): + * + * Shorthand for asserting that each field of a Temporal.PlainYearMonth is + * equal to an expected value. (Except the `calendar` property, since callers + * may want to assert either object equality with an object they put in there, + * or the result of yearMonth.calendar.toString().) + */ + assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined) { + assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`); + assert.sameValue(yearMonth.era, era, `${description} era result`); + assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`); + assert.sameValue(yearMonth.year, year, `${description} year result`); + assert.sameValue(yearMonth.month, month, `${description} month result`); + assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`); + }, /* * Check that any calendar-carrying Temporal object has its [[Calendar]] * internal slot read by ToTemporalCalendar, and does not fetch the calendar