Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port the Temporal asserts to temporalHelpers.js #3072

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions harness/temporalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down