mirror of https://github.com/tc39/test262.git
Temporal: Extend tests for PlainDate#toPlainYearMonth.
This commit is contained in:
parent
3812a1fe92
commit
e6b7323614
|
@ -0,0 +1,15 @@
|
||||||
|
// 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.prototype.toplainyearmonth
|
||||||
|
description: Basic toPlainYearMonth tests.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const calendar = new Temporal.Calendar("iso8601");
|
||||||
|
const pd = new Temporal.PlainDate(1970, 12, 24, calendar);
|
||||||
|
const pym = pd.toPlainYearMonth();
|
||||||
|
TemporalHelpers.assertPlainYearMonth(pym, 1970, 12, "M12");
|
||||||
|
assert.sameValue(pym.calendar, calendar);
|
36
test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/calendar-invalid-return.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/calendar-invalid-return.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// 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.prototype.toplainyearmonth
|
||||||
|
description: Throw when the returned value is not a PlainYearMonth.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class CustomCalendar extends Temporal.Calendar {
|
||||||
|
constructor(value) {
|
||||||
|
super("iso8601");
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
yearMonthFromFields() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
[undefined],
|
||||||
|
[null, "null"],
|
||||||
|
[true],
|
||||||
|
["2000-05"],
|
||||||
|
[Symbol()],
|
||||||
|
[200005],
|
||||||
|
[200005n],
|
||||||
|
[{}, "plain object"],
|
||||||
|
[() => {}, "lambda"],
|
||||||
|
[Temporal.PlainYearMonth, "Temporal.PlainYearMonth"],
|
||||||
|
[Temporal.PlainYearMonth.prototype, "Temporal.PlainYearMonth.prototype"],
|
||||||
|
];
|
||||||
|
for (const [test, description = typeof test] of tests) {
|
||||||
|
const plainDate = new Temporal.PlainDate(2000, 5, 2, new CustomCalendar(test));
|
||||||
|
assert.throws(TypeError, () => plainDate.toPlainYearMonth(), `Expected error with ${description}`);
|
||||||
|
}
|
Loading…
Reference in New Issue