mirror of https://github.com/tc39/test262.git
Regularize Temporal.*.from() object cloning tests
Each from() method except Calendar and TimeZone should test that when you pass an instance of that type, the return value is a clone of that instance, and a distinct object. These tests existed already for some types; regularize them and add the ones that didn't exist yet. In order to test the referenceISODay of a PlainYearMonth we add an argument to TemporalHelpers.assertPlainYearMonth.
This commit is contained in:
parent
b649e6b22a
commit
27f0104bc6
|
@ -151,20 +151,21 @@ var TemporalHelpers = {
|
|||
},
|
||||
|
||||
/*
|
||||
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear]]):
|
||||
* assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]):
|
||||
*
|
||||
* 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) {
|
||||
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
|
||||
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`);
|
||||
assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`);
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.duration.from
|
||||
description: A Duration object is copied, not returned directly
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const orig = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321);
|
||||
const result = Temporal.Duration.from(orig);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
result,
|
||||
1, 2, 3, 4, 5, 6, 7, 987, 654, 321,
|
||||
"Duration is copied"
|
||||
);
|
||||
|
||||
assert.notSameValue(
|
||||
result,
|
||||
orig,
|
||||
"When a Duration is given, the returned value is not the original Duration"
|
||||
);
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.instant.from
|
||||
description: A Instant object is copied, not returned directly
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const orig = new Temporal.Instant(217_175_010_123_456_789n);
|
||||
const result = Temporal.Instant.from(orig);
|
||||
|
||||
assert.sameValue(result.epochNanoseconds, 217_175_010_123_456_789n, "Instant is copied");
|
||||
|
||||
assert.notSameValue(
|
||||
result,
|
||||
orig,
|
||||
"When an Instant is given, the returned value is not the original Instant"
|
||||
);
|
|
@ -4,11 +4,21 @@
|
|||
/*---
|
||||
esid: sec-temporal.plaindate.from
|
||||
description: A PlainDate object is copied, not returned directly
|
||||
includes: [compareArray.js, temporalHelpers.js]
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainDate = new Temporal.PlainDate(2000, 5, 2);
|
||||
const result = Temporal.PlainDate.from(plainDate);
|
||||
assert.notSameValue(result, plainDate);
|
||||
TemporalHelpers.assertPlainDate(result, 2000, 5, "M05", 2);
|
||||
const orig = new Temporal.PlainDate(2000, 5, 2);
|
||||
const result = Temporal.PlainDate.from(orig);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
result,
|
||||
2000, 5, "M05", 2,
|
||||
"PlainDate is copied"
|
||||
);
|
||||
|
||||
assert.notSameValue(
|
||||
result,
|
||||
orig,
|
||||
"When a PlainDate is given, the returned value is not the original PlainDate"
|
||||
);
|
||||
|
|
|
@ -3,21 +3,22 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.from
|
||||
description: A Temporal PlainDateTime object is an acceptable argument
|
||||
features: [Temporal]
|
||||
description: A PlainDateTime object is copied, not returned directly
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const orig = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 20, 123, 456, 789);
|
||||
const result = Temporal.PlainDateTime.from(orig);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
Temporal.PlainDateTime.from(orig),
|
||||
result,
|
||||
1976, 11, "M11", 18, 15, 23, 20, 123, 456, 789,
|
||||
"PlainDateTime is copied"
|
||||
);
|
||||
|
||||
assert.notSameValue(
|
||||
Temporal.PlainDateTime.from(orig),
|
||||
result,
|
||||
orig,
|
||||
"When a PlainDateTime is given, the returned value is not the original PlainDateTime"
|
||||
);
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2022 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: A PlainMonthDay object is copied, not returned directly
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const orig = new Temporal.PlainMonthDay(5, 2, undefined, 2000);
|
||||
const result = Temporal.PlainMonthDay.from(orig);
|
||||
|
||||
TemporalHelpers.assertPlainMonthDay(
|
||||
result,
|
||||
"M05", 2,
|
||||
"PlainMonthDay is copied",
|
||||
/* isoYear = */ 2000
|
||||
);
|
||||
|
||||
assert.notSameValue(
|
||||
result,
|
||||
orig,
|
||||
"When a PlainMonthDay is given, the returned value is not the original PlainMonthDay"
|
||||
);
|
|
@ -4,11 +4,21 @@
|
|||
/*---
|
||||
esid: sec-temporal.plaintime.from
|
||||
description: A PlainTime object is copied, not returned directly
|
||||
includes: [compareArray.js, temporalHelpers.js]
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainTime = Temporal.PlainTime.from("11:42:00");
|
||||
const result = Temporal.PlainTime.from(plainTime);
|
||||
assert.notSameValue(result, plainTime);
|
||||
TemporalHelpers.assertPlainTime(result, 11, 42, 0, 0, 0, 0);
|
||||
const orig = new Temporal.PlainTime(11, 42, 0, 0, 0, 0);
|
||||
const result = Temporal.PlainTime.from(orig);
|
||||
|
||||
TemporalHelpers.assertPlainTime(
|
||||
result,
|
||||
11, 42, 0, 0, 0, 0,
|
||||
"PlainTime is copied"
|
||||
);
|
||||
|
||||
assert.notSameValue(
|
||||
result,
|
||||
orig,
|
||||
"When a PlainTime is given, the returned value is not the original PlainTime"
|
||||
);
|
||||
|
|
|
@ -3,20 +3,23 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.from
|
||||
description: A PlainYearMonth argument is cloned
|
||||
description: A PlainYearMonth object is copied, not returned directly
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const original = new Temporal.PlainYearMonth(2019, 11, undefined, 7);
|
||||
const result = Temporal.PlainYearMonth.from(original);
|
||||
assert.notSameValue(result, original);
|
||||
const orig = new Temporal.PlainYearMonth(2000, 5, undefined, 7);
|
||||
const result = Temporal.PlainYearMonth.from(orig);
|
||||
|
||||
for (const plainYearMonth of [original, result]) {
|
||||
TemporalHelpers.assertPlainYearMonth(plainYearMonth, 2019, 11, "M11");
|
||||
const fields = plainYearMonth.getISOFields();
|
||||
assert.sameValue(fields.calendar.id, "iso8601");
|
||||
assert.sameValue(fields.isoDay, 7, "isoDay");
|
||||
assert.sameValue(fields.isoMonth, 11, "isoMonth");
|
||||
assert.sameValue(fields.isoYear, 2019, "isoYear");
|
||||
}
|
||||
TemporalHelpers.assertPlainYearMonth(
|
||||
result,
|
||||
2000, 5, "M05",
|
||||
"PlainYearMonth is copied",
|
||||
/* era = */ undefined, /* eraYear = */ undefined, /* isoDay = */ 7
|
||||
);
|
||||
|
||||
assert.notSameValue(
|
||||
result,
|
||||
orig,
|
||||
"When a PlainYearMonth is given, the returned value is not the original PlainYearMonth"
|
||||
);
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: A ZonedDateTime object is copied, not returned directly
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const orig = new Temporal.ZonedDateTime(946684800_000_000_010n, new Temporal.TimeZone("UTC"));
|
||||
const result = Temporal.ZonedDateTime.from(orig);
|
||||
|
||||
assert.sameValue(result.epochNanoseconds, 946684800_000_000_010n, "ZonedDateTime is copied");
|
||||
assert.sameValue(result.timeZone, orig.timeZone, "time zone is the same");
|
||||
assert.sameValue(result.calendar, orig.calendar, "calendar is the same");
|
||||
|
||||
assert.notSameValue(
|
||||
result,
|
||||
orig,
|
||||
"When a ZonedDateTime is given, the returned value is not the original ZonedDateTime"
|
||||
);
|
Loading…
Reference in New Issue