Skip to content

Commit

Permalink
Add tests for structured cloning of Temporal objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed Jun 21, 2024
1 parent a591743 commit cd51573
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions html/webappapis/structured-clone/structured-clone-battery-of-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,133 @@ structuredCloneBatteryOfTests.push({
);
}
});

check(
'Temporal.PlainDate',
() => {
return new Temporal.PlainDate(2024, 6, 21);
},
function(actual, _input) {
assert_true(actual instanceof Temporal.PlainDate, 'instanceof Temporal.PlainDate');
assert_equals(actual.year, 2024);
assert_equals(actual.monthCode, "M06");
assert_equals(actual.day, 21);
assert_equals(actual.calendarId, "iso8601");
assert_equals(actual.toString(), "2024-06-21");
});

check(
'Temporal.PlainTime',
() => {
return new Temporal.PlainTime(15, 0, 1, 2, 3, 4);
},
function(actual, _input) {
assert_true(actual instanceof Temporal.PlainTime, 'instanceof Temporal.PlainTime');
assert_equals(actual.hour, 15);
assert_equals(actual.minute, 0);
assert_equals(actual.second, 1);
assert_equals(actual.millisecond, 2);
assert_equals(actual.microsecond, 3);
assert_equals(actual.nanosecond, 4);
assert_equals(actual.toString(), "15:00:01.002003004");
});

check(
'Temporal.PlainDateTime',
() => {
return new Temporal.PlainDateTime(2024, 6, 21, 15, 0, 1, 2, 3, 4);
},
function(actual, _input) {
assert_true(actual instanceof Temporal.PlainDateTime, 'instanceof Temporal.PlainDateTime');
assert_equals(actual.year, 2024);
assert_equals(actual.monthCode, "M06");
assert_equals(actual.day, 21);
assert_equals(actual.hour, 15);
assert_equals(actual.minute, 0);
assert_equals(actual.second, 1);
assert_equals(actual.millisecond, 2);
assert_equals(actual.microsecond, 3);
assert_equals(actual.nanosecond, 4);
assert_equals(actual.calendarId, "iso8601");
assert_equals(actual.toString(), "2024-06-21T15:00:01.002003004");
});


check(
'Temporal.ZonedDateTime',
() => {
return new Temporal.ZonedDateTime(1718974801002003004n, "Europe/Brussels", "iso8601");
},
function(actual, _input) {
assert_true(actual instanceof Temporal.ZonedDateTime, 'instanceof Temporal.ZonedDateTime');
assert_equals(actual.year, 2024);
assert_equals(actual.monthCode, "M06");
assert_equals(actual.day, 21);
assert_equals(actual.hour, 15);
assert_equals(actual.minute, 0);
assert_equals(actual.second, 1);
assert_equals(actual.millisecond, 2);
assert_equals(actual.microsecond, 3);
assert_equals(actual.nanosecond, 4);
assert_equals(actual.timeZoneId, "Europe/Brussels");
assert_equals(actual.calendarId, "iso8601");
assert_equals(actual.toString(), "2024-06-21T15:00:01.002003004+02:00[Europe/Brussels]");
});


check(
'Temporal.Duration',
() => {
return new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321);
},
function(actual, _input) {
assert_true(actual instanceof Temporal.Duration, 'instanceof Temporal.Duration');
assert_equals(actual.toString(), "P1Y2M3W4DT5H6M7.987654321S");
assert_equals(actual.years, 1);
assert_equals(actual.months, 2);
assert_equals(actual.weeks, 3);
assert_equals(actual.days, 4);
assert_equals(actual.hours, 5);
assert_equals(actual.minutes, 6);
assert_equals(actual.seconds, 7);
assert_equals(actual.milliseconds, 987);
assert_equals(actual.microseconds, 654);
assert_equals(actual.nanoseconds, 321);
});

check(
'Temporal.Instant',
() => {
return new Temporal.Instant(1718974801002003004n);
},
function(actual, _input) {
assert_true(actual instanceof Temporal.Instant, 'instanceof Temporal.Instant');
assert_equals(actual.epochNanoseconds, 1718974801002003004n);
assert_equals(actual.toString(), "2024-06-21T13:00:01.002003004Z");
});

check(
'Temporal.PlainYearMonth',
() => {
return new Temporal.PlainYearMonth(2024, 6, "iso8601", 21);
},
function(actual, _input) {
assert_true(actual instanceof Temporal.PlainYearMonth, 'instanceof Temporal.PlainYearMonth');
assert_equals(actual.toString(), "2024-06");
assert_equals(actual.year, 2024);
assert_equals(actual.monthCode, "M06");
assert_equals(actual.calendarId, "iso8601");
});

check(
'Temporal.PlainMonthDay',
() => {
return new Temporal.PlainMonthDay(6, 21, "iso8601", 2024);
},
function(actual, _input) {
assert_true(actual instanceof Temporal.PlainMonthDay, 'instanceof Temporal.PlainMonthDay');
assert_equals(actual.toString(), "06-21");
assert_equals(actual.monthCode, "M06");
assert_equals(actual.day, 21);
assert_equals(actual.calendarId, "iso8601");
});

0 comments on commit cd51573

Please sign in to comment.