mirror of
https://github.com/tc39/test262.git
synced 2025-07-21 13:04:39 +02:00
Temporal: Extend PlainDate#with coverage.
This commit is contained in:
parent
9762bc991f
commit
1a9f64cda3
36
test/built-ins/Temporal/PlainDate/prototype/with/calendar-invalid-return.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/with/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.with
|
||||||
|
description: Throw when the returned value is not a PlainDate.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class CustomCalendar extends Temporal.Calendar {
|
||||||
|
constructor(value) {
|
||||||
|
super("iso8601");
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
dateFromFields() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
[undefined],
|
||||||
|
[null, "null"],
|
||||||
|
[true],
|
||||||
|
["2000-05"],
|
||||||
|
[Symbol()],
|
||||||
|
[200005],
|
||||||
|
[200005n],
|
||||||
|
[{}, "plain object"],
|
||||||
|
[() => {}, "lambda"],
|
||||||
|
[Temporal.PlainDate, "Temporal.PlainDate"],
|
||||||
|
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype"],
|
||||||
|
];
|
||||||
|
for (const [test, description = typeof test] of tests) {
|
||||||
|
const plainDate = new Temporal.PlainDate(2000, 5, 2, new CustomCalendar(test));
|
||||||
|
assert.throws(TypeError, () => plainDate.with({ year: 1 }), `Expected error with ${description}`);
|
||||||
|
}
|
33
test/built-ins/Temporal/PlainDate/prototype/with/custom.js
vendored
Normal file
33
test/built-ins/Temporal/PlainDate/prototype/with/custom.js
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// 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.with
|
||||||
|
description: Basic tests with custom calendar
|
||||||
|
includes: [compareArray.js,temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const result = new Temporal.PlainDate(1920, 5, 3);
|
||||||
|
const options = {};
|
||||||
|
let calls = 0;
|
||||||
|
class CustomCalendar extends Temporal.Calendar {
|
||||||
|
constructor() {
|
||||||
|
super("iso8601");
|
||||||
|
}
|
||||||
|
dateFromFields(...args) {
|
||||||
|
++calls;
|
||||||
|
assert.sameValue(args.length, 2, "Two arguments");
|
||||||
|
assert.sameValue(typeof args[0], "object", "First argument: type");
|
||||||
|
assert.sameValue(args[0].day, 18, "First argument: day");
|
||||||
|
assert.sameValue(args[0].month, 11, "First argument: month");
|
||||||
|
assert.sameValue(args[0].monthCode, "M11", "First argument: monthCode");
|
||||||
|
assert.sameValue(args[0].year, 43, "First argument: year");
|
||||||
|
assert.sameValue(args[1], options, "Second argument");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const calendar = new CustomCalendar();
|
||||||
|
const plainDate = new Temporal.PlainDate(1976, 11, 18, calendar);
|
||||||
|
assert.sameValue(plainDate.with({ year: 43 }, options), result);
|
||||||
|
assert.sameValue(calls, 1);
|
Loading…
x
Reference in New Issue
Block a user