mirror of https://github.com/tc39/test262.git
Temporal: Test that Calendar#dateAdd is called with the correct arguments.
This commit is contained in:
parent
b2b6756044
commit
3ddfa0cd13
|
@ -0,0 +1,40 @@
|
|||
// 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.prototype.add
|
||||
description: Duration.prototype.add should call dateAdd with the appropriate values.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls = 0;
|
||||
const expected = [
|
||||
{
|
||||
plainDate: [1920, 5, "M05", 3],
|
||||
duration: [2, 0, 0, 4, 0, 0, 0, 0, 0, 0],
|
||||
},
|
||||
{
|
||||
plainDate: [1922, 5, "M05", 7],
|
||||
duration: [0, 10, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
},
|
||||
];
|
||||
class CustomCalendar extends Temporal.Calendar {
|
||||
constructor() {
|
||||
super("iso8601");
|
||||
}
|
||||
dateAdd(plainDate, duration, options) {
|
||||
TemporalHelpers.assertPlainDate(plainDate, ...expected[calls].plainDate,
|
||||
`plainDate argument ${calls}`);
|
||||
TemporalHelpers.assertDuration(duration, ...expected[calls].duration,
|
||||
`duration argument ${calls}`);
|
||||
assert.sameValue(options, undefined, "options argument");
|
||||
++calls;
|
||||
return super.dateAdd(plainDate, duration, options);
|
||||
}
|
||||
}
|
||||
const relativeTo = new Temporal.PlainDate(1920, 5, 3, new CustomCalendar());
|
||||
const duration = new Temporal.Duration(2, 0, 0, 4, 2);
|
||||
const result = duration.add({ months: 10, hours: 14 }, { relativeTo });
|
||||
TemporalHelpers.assertDuration(result, 2, 10, 0, 4, 16, 0, 0, 0, 0, 0, "result");
|
||||
assert.sameValue(calls, 2, "should have called dateAdd");
|
|
@ -0,0 +1,40 @@
|
|||
// 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.prototype.subtract
|
||||
description: Duration.prototype.subtract should call dateAdd with the appropriate values.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls = 0;
|
||||
const expected = [
|
||||
{
|
||||
plainDate: [1920, 5, "M05", 3],
|
||||
duration: [2, 0, 0, 4, 0, 0, 0, 0, 0, 0],
|
||||
},
|
||||
{
|
||||
plainDate: [1922, 5, "M05", 7],
|
||||
duration: [0, -10, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
},
|
||||
];
|
||||
class CustomCalendar extends Temporal.Calendar {
|
||||
constructor() {
|
||||
super("iso8601");
|
||||
}
|
||||
dateAdd(plainDate, duration, options) {
|
||||
TemporalHelpers.assertPlainDate(plainDate, ...expected[calls].plainDate,
|
||||
`plainDate argument ${calls}`);
|
||||
TemporalHelpers.assertDuration(duration, ...expected[calls].duration,
|
||||
`duration argument ${calls}`);
|
||||
assert.sameValue(options, undefined, "options argument");
|
||||
++calls;
|
||||
return super.dateAdd(plainDate, duration, options);
|
||||
}
|
||||
}
|
||||
const relativeTo = new Temporal.PlainDate(1920, 5, 3, new CustomCalendar());
|
||||
const duration = new Temporal.Duration(2, 0, 0, 4, 2);
|
||||
const result = duration.subtract({ months: 10, hours: 14 }, { relativeTo });
|
||||
TemporalHelpers.assertDuration(result, 1, 2, 0, 3, 12, 0, 0, 0, 0, 0, "result");
|
||||
assert.sameValue(calls, 2, "should have called dateAdd");
|
|
@ -0,0 +1,29 @@
|
|||
// 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.plaindatetime.prototype.add
|
||||
description: PlainDateTime.prototype.add should call dateAdd with the appropriate values.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls = 0;
|
||||
class CustomCalendar extends Temporal.Calendar {
|
||||
constructor() {
|
||||
super("iso8601");
|
||||
}
|
||||
dateAdd(plainDate, duration, options) {
|
||||
++calls;
|
||||
TemporalHelpers.assertPlainDate(plainDate, 2020, 3, "M03", 14, "plainDate argument");
|
||||
TemporalHelpers.assertDuration(duration, 0, 10, 0, 1, 0, 0, 0, 0, 0, 0, "duration argument");
|
||||
assert.sameValue(typeof options, "object", "options argument: type");
|
||||
assert.sameValue(Object.getPrototypeOf(options), null, "options argument: prototype");
|
||||
return super.dateAdd(plainDate, duration, options);
|
||||
}
|
||||
}
|
||||
|
||||
const plainDateTime = new Temporal.PlainDateTime(2020, 3, 14, 12, 34, 56, 987, 654, 321, new CustomCalendar());
|
||||
const result = plainDateTime.add({ months: 10, hours: 14 });
|
||||
TemporalHelpers.assertPlainDateTime(result, 2021, 1, "M01", 15, 2, 34, 56, 987, 654, 321);
|
||||
assert.sameValue(calls, 1, "should have called dateAdd");
|
29
test/built-ins/Temporal/PlainDateTime/prototype/subtract/calendar-dateadd.js
vendored
Normal file
29
test/built-ins/Temporal/PlainDateTime/prototype/subtract/calendar-dateadd.js
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
// 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.plaindatetime.prototype.subtract
|
||||
description: PlainDateTime.prototype.subtract should call dateAdd with the appropriate values.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls = 0;
|
||||
class CustomCalendar extends Temporal.Calendar {
|
||||
constructor() {
|
||||
super("iso8601");
|
||||
}
|
||||
dateAdd(plainDate, duration, options) {
|
||||
++calls;
|
||||
TemporalHelpers.assertPlainDate(plainDate, 2020, 3, "M03", 14, "plainDate argument");
|
||||
TemporalHelpers.assertDuration(duration, 0, -10, 0, -1, 0, 0, 0, 0, 0, 0, "duration argument");
|
||||
assert.sameValue(typeof options, "object", "options argument: type");
|
||||
assert.sameValue(Object.getPrototypeOf(options), null, "options argument: prototype");
|
||||
return super.dateAdd(plainDate, duration, options);
|
||||
}
|
||||
}
|
||||
|
||||
const plainDateTime = new Temporal.PlainDateTime(2020, 3, 14, 12, 34, 56, 987, 654, 321, new CustomCalendar());
|
||||
const result = plainDateTime.subtract({ months: 10, hours: 14 });
|
||||
TemporalHelpers.assertPlainDateTime(result, 2019, 5, "M05", 13, 22, 34, 56, 987, 654, 321);
|
||||
assert.sameValue(calls, 1, "should have called dateAdd");
|
|
@ -0,0 +1,29 @@
|
|||
// 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.plainyearmonth.prototype.add
|
||||
description: PlainYearMonth.prototype.add should call dateAdd with the appropriate values.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls = 0;
|
||||
class CustomCalendar extends Temporal.Calendar {
|
||||
constructor() {
|
||||
super("iso8601");
|
||||
}
|
||||
dateAdd(plainDate, duration, options) {
|
||||
++calls;
|
||||
TemporalHelpers.assertPlainDate(plainDate, 2000, 3, "M03", 1, "plainDate argument");
|
||||
TemporalHelpers.assertDuration(duration, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, "duration argument");
|
||||
assert.sameValue(typeof options, "object", "options argument: type");
|
||||
assert.sameValue(Object.getPrototypeOf(options), null, "options argument: prototype");
|
||||
return super.dateAdd(plainDate, duration, options);
|
||||
}
|
||||
}
|
||||
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(2000, 3, new CustomCalendar());
|
||||
const result = plainYearMonth.add({ months: 10 });
|
||||
TemporalHelpers.assertPlainYearMonth(result, 2001, 1, "M01");
|
||||
assert.sameValue(calls, 1, "should have called dateAdd");
|
29
test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd.js
vendored
Normal file
29
test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd.js
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
// 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.plainyearmonth.prototype.subtract
|
||||
description: PlainYearMonth.prototype.subtract should call dateAdd with the appropriate values.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls = 0;
|
||||
class CustomCalendar extends Temporal.Calendar {
|
||||
constructor() {
|
||||
super("iso8601");
|
||||
}
|
||||
dateAdd(plainDate, duration, options) {
|
||||
++calls;
|
||||
TemporalHelpers.assertPlainDate(plainDate, 2000, 3, "M03", 31, "plainDate argument");
|
||||
TemporalHelpers.assertDuration(duration, 0, -10, 0, 0, 0, 0, 0, 0, 0, 0, "duration argument");
|
||||
assert.sameValue(typeof options, "object", "options argument: type");
|
||||
assert.sameValue(Object.getPrototypeOf(options), null, "options argument: prototype");
|
||||
return super.dateAdd(plainDate, duration, options);
|
||||
}
|
||||
}
|
||||
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(2000, 3, new CustomCalendar());
|
||||
const result = plainYearMonth.subtract({ months: 10 });
|
||||
TemporalHelpers.assertPlainYearMonth(result, 1999, 5, "M05");
|
||||
assert.sameValue(calls, 1, "should have called dateAdd");
|
|
@ -0,0 +1,30 @@
|
|||
// 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.prototype.add
|
||||
description: ZonedDateTime.prototype.add should call dateAdd with the appropriate values.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls = 0;
|
||||
class CustomCalendar extends Temporal.Calendar {
|
||||
constructor() {
|
||||
super("iso8601");
|
||||
}
|
||||
dateAdd(plainDate, duration, options) {
|
||||
++calls;
|
||||
TemporalHelpers.assertPlainDate(plainDate, 2020, 3, "M03", 14, "plainDate argument");
|
||||
TemporalHelpers.assertDuration(duration, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, "duration argument");
|
||||
assert.sameValue(typeof options, "object", "options argument: type");
|
||||
assert.sameValue(Object.getPrototypeOf(options), null, "options argument: prototype");
|
||||
return super.dateAdd(plainDate, duration, options);
|
||||
}
|
||||
}
|
||||
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1584189296_987654321n,
|
||||
new Temporal.TimeZone("UTC"), new CustomCalendar());
|
||||
const result = zonedDateTime.add({ months: 10, hours: 14 });
|
||||
assert.sameValue(result.epochNanoseconds, 1610678096_987654321n);
|
||||
assert.sameValue(calls, 1, "should have called dateAdd");
|
30
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/calendar-dateadd.js
vendored
Normal file
30
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/calendar-dateadd.js
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// 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.prototype.subtract
|
||||
description: ZonedDateTime.prototype.subtract should call dateAdd with the appropriate values.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls = 0;
|
||||
class CustomCalendar extends Temporal.Calendar {
|
||||
constructor() {
|
||||
super("iso8601");
|
||||
}
|
||||
dateAdd(plainDate, duration, options) {
|
||||
++calls;
|
||||
TemporalHelpers.assertPlainDate(plainDate, 2020, 3, "M03", 14, "plainDate argument");
|
||||
TemporalHelpers.assertDuration(duration, 0, -10, 0, 0, 0, 0, 0, 0, 0, 0, "duration argument");
|
||||
assert.sameValue(typeof options, "object", "options argument: type");
|
||||
assert.sameValue(Object.getPrototypeOf(options), null, "options argument: prototype");
|
||||
return super.dateAdd(plainDate, duration, options);
|
||||
}
|
||||
}
|
||||
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1584189296_987654321n,
|
||||
new Temporal.TimeZone("UTC"), new CustomCalendar());
|
||||
const result = zonedDateTime.subtract({ months: 10, hours: 14 });
|
||||
assert.sameValue(result.epochNanoseconds, 1557786896_987654321n);
|
||||
assert.sameValue(calls, 1, "should have called dateAdd");
|
Loading…
Reference in New Issue