mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 05:24:38 +02:00
Temporal: Extend PlainDate#{since,until} coverage. (#3581)
This commit is contained in:
parent
d5b2c706cf
commit
65e75e4eed
36
test/built-ins/Temporal/PlainDate/prototype/since/calendar-invalid-return.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/since/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.since
|
||||||
|
description: Throw when the returned value from the calendar's dateUntil method is not a Duration.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class CustomCalendar extends Temporal.Calendar {
|
||||||
|
constructor(value) {
|
||||||
|
super("iso8601");
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
dateUntil() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
[undefined],
|
||||||
|
[null, "null"],
|
||||||
|
[true],
|
||||||
|
["2000-05"],
|
||||||
|
[Symbol()],
|
||||||
|
[200005],
|
||||||
|
[200005n],
|
||||||
|
[{}, "plain object"],
|
||||||
|
[() => {}, "lambda"],
|
||||||
|
[Temporal.Duration, "Temporal.Duration"],
|
||||||
|
[Temporal.Duration.prototype, "Temporal.Duration.prototype"],
|
||||||
|
];
|
||||||
|
for (const [test, description = typeof test] of tests) {
|
||||||
|
const plainDate = new Temporal.PlainDate(2000, 5, 2, new CustomCalendar(test));
|
||||||
|
assert.throws(TypeError, () => plainDate.since("2022-06-20"), `Expected error with ${description}`);
|
||||||
|
}
|
32
test/built-ins/Temporal/PlainDate/prototype/since/custom.js
vendored
Normal file
32
test/built-ins/Temporal/PlainDate/prototype/since/custom.js
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// 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.since
|
||||||
|
description: Basic tests with custom calendar
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const result = new Temporal.Duration(1, 3, 5, 7, 9);
|
||||||
|
const options = {};
|
||||||
|
let calls = 0;
|
||||||
|
class CustomCalendar extends Temporal.Calendar {
|
||||||
|
constructor() {
|
||||||
|
super("iso8601");
|
||||||
|
}
|
||||||
|
dateUntil(...args) {
|
||||||
|
++calls;
|
||||||
|
assert.sameValue(args.length, 3, "Three arguments");
|
||||||
|
assert.sameValue(args[0], plainDate, "First argument");
|
||||||
|
assert.sameValue(args[1], other, "Second argument");
|
||||||
|
assert.sameValue(args[2].largestUnit, "day", "Third argument: largestUnit");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const calendar = new CustomCalendar();
|
||||||
|
const plainDate = new Temporal.PlainDate(1976, 11, 18, calendar);
|
||||||
|
const other = new Temporal.PlainDate(2022, 6, 20, calendar);
|
||||||
|
TemporalHelpers.assertDuration(plainDate.since(other, options),
|
||||||
|
-1, -3, -5, -7, 0, 0, 0, 0, 0, 0, "result");
|
||||||
|
assert.sameValue(calls, 1);
|
36
test/built-ins/Temporal/PlainDate/prototype/until/calendar-invalid-return.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/until/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.until
|
||||||
|
description: Throw when the returned value from the calendar's dateUntil method is not a Duration.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class CustomCalendar extends Temporal.Calendar {
|
||||||
|
constructor(value) {
|
||||||
|
super("iso8601");
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
dateUntil() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
[undefined],
|
||||||
|
[null, "null"],
|
||||||
|
[true],
|
||||||
|
["2000-05"],
|
||||||
|
[Symbol()],
|
||||||
|
[200005],
|
||||||
|
[200005n],
|
||||||
|
[{}, "plain object"],
|
||||||
|
[() => {}, "lambda"],
|
||||||
|
[Temporal.Duration, "Temporal.Duration"],
|
||||||
|
[Temporal.Duration.prototype, "Temporal.Duration.prototype"],
|
||||||
|
];
|
||||||
|
for (const [test, description = typeof test] of tests) {
|
||||||
|
const plainDate = new Temporal.PlainDate(2000, 5, 2, new CustomCalendar(test));
|
||||||
|
assert.throws(TypeError, () => plainDate.until("2022-06-20"), `Expected error with ${description}`);
|
||||||
|
}
|
32
test/built-ins/Temporal/PlainDate/prototype/until/custom.js
vendored
Normal file
32
test/built-ins/Temporal/PlainDate/prototype/until/custom.js
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// 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.until
|
||||||
|
description: Basic tests with custom calendar
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const result = new Temporal.Duration(1, 3, 5, 7, 9);
|
||||||
|
const options = {};
|
||||||
|
let calls = 0;
|
||||||
|
class CustomCalendar extends Temporal.Calendar {
|
||||||
|
constructor() {
|
||||||
|
super("iso8601");
|
||||||
|
}
|
||||||
|
dateUntil(...args) {
|
||||||
|
++calls;
|
||||||
|
assert.sameValue(args.length, 3, "Three arguments");
|
||||||
|
assert.sameValue(args[0], plainDate, "First argument");
|
||||||
|
assert.sameValue(args[1], other, "Second argument");
|
||||||
|
assert.sameValue(args[2].largestUnit, "day", "Third argument: largestUnit");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const calendar = new CustomCalendar();
|
||||||
|
const plainDate = new Temporal.PlainDate(1976, 11, 18, calendar);
|
||||||
|
const other = new Temporal.PlainDate(2022, 6, 20, calendar);
|
||||||
|
TemporalHelpers.assertDuration(plainDate.until(other, options),
|
||||||
|
1, 3, 5, 7, 0, 0, 0, 0, 0, 0, "result");
|
||||||
|
assert.sameValue(calls, 1);
|
Loading…
x
Reference in New Issue
Block a user