mirror of https://github.com/tc39/test262.git
Temporal: Improve coverage for PlainDate constructor and from().
This commit is contained in:
parent
1aeed72ab5
commit
ed5ada3e13
|
@ -0,0 +1,53 @@
|
|||
// 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.plaindate
|
||||
description: PlainDate constructor with non-integer arguments.
|
||||
includes: [compareArray.js, temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(2020.6, 11.7, 24.1),
|
||||
2020, 11, "M11", 24, "positive fractional");
|
||||
|
||||
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(-2020.6, 11.7, 24.1),
|
||||
-2020, 11, "M11", 24, "negative fractional");
|
||||
|
||||
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(undefined, 11, 24),
|
||||
0, 11, "M11", 24, "undefined");
|
||||
|
||||
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(null, 11, 24),
|
||||
0, 11, "M11", 24, "null");
|
||||
|
||||
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(true, 11, 24),
|
||||
1, 11, "M11", 24, "boolean");
|
||||
|
||||
TemporalHelpers.assertPlainDate(new Temporal.PlainDate("2020.6", "11.7", "24.1"),
|
||||
2020, 11, "M11", 24, "fractional strings");
|
||||
|
||||
TemporalHelpers.assertPlainDate(new Temporal.PlainDate("invalid", 11, 24),
|
||||
0, 11, "M11", 24, "invalid string");
|
||||
|
||||
for (const invalid of [Symbol(), 1n]) {
|
||||
assert.throws(TypeError, () => new Temporal.PlainDate(invalid, 11, 24), `year ${typeof invalid}`);
|
||||
assert.throws(TypeError, () => new Temporal.PlainDate(2020, invalid, 24), `month ${typeof invalid}`);
|
||||
assert.throws(TypeError, () => new Temporal.PlainDate(2020, 11, invalid), `day ${typeof invalid}`);
|
||||
}
|
||||
|
||||
const actual = [];
|
||||
const args = [
|
||||
TemporalHelpers.toPrimitiveObserver(actual, 2020, "year"),
|
||||
TemporalHelpers.toPrimitiveObserver(actual, 11, "month"),
|
||||
TemporalHelpers.toPrimitiveObserver(actual, 24, "day"),
|
||||
];
|
||||
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(...args),
|
||||
2020, 11, "M11", 24, "invalid string");
|
||||
assert.compareArray(actual, [
|
||||
"get year.valueOf",
|
||||
"call year.valueOf",
|
||||
"get month.valueOf",
|
||||
"call month.valueOf",
|
||||
"get day.valueOf",
|
||||
"call day.valueOf",
|
||||
]);
|
|
@ -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.plaindate
|
||||
description: PlainDate constructor with invalid iso dates
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[2020, 0, 24],
|
||||
[2020, 13, 24],
|
||||
[2020, -3, 24],
|
||||
[2020, 12, 32],
|
||||
[2020, 2, 30],
|
||||
[2019, 2, 29],
|
||||
[2019, 2, 0],
|
||||
[2019, 2, -20],
|
||||
];
|
||||
|
||||
for (const [year, month, day] of tests) {
|
||||
assert.throws(RangeError, () => new Temporal.PlainDate(year, month, day),
|
||||
`year=${year}, month=${month}, day=${day}`);
|
||||
}
|
|
@ -8,7 +8,8 @@ includes: [temporalHelpers.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const orig = new Temporal.PlainDate(2000, 5, 2);
|
||||
const calendar = new Temporal.Calendar("iso8601");
|
||||
const orig = new Temporal.PlainDate(2000, 5, 2, calendar);
|
||||
const result = Temporal.PlainDate.from(orig);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
|
@ -17,6 +18,12 @@ TemporalHelpers.assertPlainDate(
|
|||
"PlainDate is copied"
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
result.calendar,
|
||||
calendar,
|
||||
"Calendar is copied"
|
||||
);
|
||||
|
||||
assert.notSameValue(
|
||||
result,
|
||||
orig,
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
// 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.plaindate.from
|
||||
description: Property bag is correctly converted into PlainDate
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = new Temporal.Calendar("iso8601");
|
||||
const plainDate = Temporal.PlainDate.from({ year: 1976, month: 11, day: 18, calendar });
|
||||
TemporalHelpers.assertPlainDate(plainDate, 1976, 11, "M11", 18);
|
||||
assert.sameValue(plainDate.calendar, calendar);
|
|
@ -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.plaindate.from
|
||||
description: An exception from TimeZone#getOffsetNanosecondsFor() is propagated.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
class TZ extends Temporal.TimeZone {
|
||||
constructor() { super("UTC") }
|
||||
getOffsetNanosecondsFor() { throw new Test262Error() }
|
||||
}
|
||||
|
||||
const tz = new TZ();
|
||||
const arg = new Temporal.ZonedDateTime(0n, tz);
|
||||
const instance = new Temporal.PlainDate(1976, 11, 18);
|
||||
|
||||
assert.throws(Test262Error, () => Temporal.PlainDate.from(arg));
|
|
@ -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.plaindate.from
|
||||
description: A ZonedDateTime object is handled separately
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = new Temporal.Calendar("iso8601");
|
||||
const zdt = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", calendar);
|
||||
const result = Temporal.PlainDate.from(zdt);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
result,
|
||||
2001, 9, "M09", 9,
|
||||
"ZonedDateTime is converted"
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
result.calendar,
|
||||
calendar,
|
||||
"Calendar is copied"
|
||||
);
|
Loading…
Reference in New Issue