Skip to content

Commit

Permalink
Temporal: Adapt existing custom calendar getter tests, and expand
Browse files Browse the repository at this point in the history
The existing tests would fail after making the normative change from
tc39/proposal-temporal#2265 because they rely on the getter directly
returning whatever value the calendar method returned. This is no longer
the case, because the value returned by the calendar is validated, so
adjust the assertions in these tests.

Also, no longer any need to return a value from the calendar method that
needs to be converted; we'll add separate tests for that.

Expand these tests to cover all of the PlainDate, PlainDateTime,
PlainMonthDay, PlainYearMonth, and ZonedDateTime property getters that
delegate to the calendar methods.
  • Loading branch information
ptomato authored and Ms2ger committed Oct 5, 2022
1 parent 89116e9 commit b83af50
Show file tree
Hide file tree
Showing 45 changed files with 815 additions and 32 deletions.
27 changes: 27 additions & 0 deletions test/built-ins/Temporal/PlainDate/prototype/day/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindate.prototype.day
description: Custom calendar tests for day().
includes: [compareArray.js]
features: [Temporal]
---*/

let calls = 0;
class CustomCalendar extends Temporal.Calendar {
constructor() {
super("iso8601");
}
day(...args) {
++calls;
assert.compareArray(args, [pd], "day arguments");
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.day;
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
dayOfWeek(...args) {
++calls;
assert.compareArray(args, [pd], "dayOfWeek arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.dayOfWeek;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
dayOfYear(...args) {
++calls;
assert.compareArray(args, [pd], "dayOfYear arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.dayOfYear;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
daysInMonth(...args) {
++calls;
assert.compareArray(args, [pd], "daysInMonth arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.daysInMonth;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
daysInWeek(...args) {
++calls;
assert.compareArray(args, [pd], "daysInWeek arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.daysInWeek;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
daysInYear(...args) {
++calls;
assert.compareArray(args, [pd], "daysInYear arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.daysInYear;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
inLeapYear(...args) {
++calls;
assert.compareArray(args, [pd], "inLeapYear arguments");
return "7";
return true;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.inLeapYear;
assert.sameValue(result, "7", "result");
assert.sameValue(result, true, "result");
assert.sameValue(calls, 1, "calls");
27 changes: 27 additions & 0 deletions test/built-ins/Temporal/PlainDate/prototype/month/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindate.prototype.month
description: Custom calendar tests for month().
includes: [compareArray.js]
features: [Temporal]
---*/

let calls = 0;
class CustomCalendar extends Temporal.Calendar {
constructor() {
super("iso8601");
}
month(...args) {
++calls;
assert.compareArray(args, [pd], "month arguments");
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.month;
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
27 changes: 27 additions & 0 deletions test/built-ins/Temporal/PlainDate/prototype/monthCode/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindate.prototype.monthcode
description: Custom calendar tests for monthCode().
includes: [compareArray.js]
features: [Temporal]
---*/

let calls = 0;
class CustomCalendar extends Temporal.Calendar {
constructor() {
super("iso8601");
}
monthCode(...args) {
++calls;
assert.compareArray(args, [pd], "monthCode arguments");
return "M01";
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.monthCode;
assert.sameValue(result, "M01", "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
monthsInYear(...args) {
++calls;
assert.compareArray(args, [pd], "monthsInYear arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.monthsInYear;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
weekOfYear(...args) {
++calls;
assert.compareArray(args, [pd], "weekOfYear arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.weekOfYear;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
27 changes: 27 additions & 0 deletions test/built-ins/Temporal/PlainDate/prototype/year/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindate.prototype.year
description: Custom calendar tests for year().
includes: [compareArray.js]
features: [Temporal]
---*/

let calls = 0;
class CustomCalendar extends Temporal.Calendar {
constructor() {
super("iso8601");
}
year(...args) {
++calls;
assert.compareArray(args, [pd], "year arguments");
return 7;
}
}

const calendar = new CustomCalendar();
const pd = new Temporal.PlainDate(1830, 8, 25, calendar);
const result = pd.year;
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
27 changes: 27 additions & 0 deletions test/built-ins/Temporal/PlainDateTime/prototype/day/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindatetime.prototype.day
description: Custom calendar tests for day().
includes: [compareArray.js]
features: [Temporal]
---*/

let calls = 0;
class CustomCalendar extends Temporal.Calendar {
constructor() {
super("iso8601");
}
day(...args) {
++calls;
assert.compareArray(args, [pdt], "day arguments");
return 7;
}
}

const calendar = new CustomCalendar();
const pdt = new Temporal.PlainDateTime(1830, 8, 25, 20, 0, 0, 0, 0, 0, calendar);
const result = pdt.day;
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
dayOfWeek(...args) {
++calls;
assert.compareArray(args, [pdt], "dayOfWeek arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pdt = new Temporal.PlainDateTime(1830, 8, 25, 20, 0, 0, 0, 0, 0, calendar);
const result = pdt.dayOfWeek;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
dayOfYear(...args) {
++calls;
assert.compareArray(args, [pdt], "dayOfYear arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pdt = new Temporal.PlainDateTime(1830, 8, 25, 20, 0, 0, 0, 0, 0, calendar);
const result = pdt.dayOfYear;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
daysInMonth(...args) {
++calls;
assert.compareArray(args, [pdt], "daysInMonth arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pdt = new Temporal.PlainDateTime(1830, 8, 25, 20, 0, 0, 0, 0, 0, calendar);
const result = pdt.daysInMonth;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
daysInWeek(...args) {
++calls;
assert.compareArray(args, [pdt], "daysInWeek arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pdt = new Temporal.PlainDateTime(1830, 8, 25, 20, 0, 0, 0, 0, 0, calendar);
const result = pdt.daysInWeek;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
daysInYear(...args) {
++calls;
assert.compareArray(args, [pdt], "daysInYear arguments");
return "7";
return 7;
}
}

const calendar = new CustomCalendar();
const pdt = new Temporal.PlainDateTime(1830, 8, 25, 20, 0, 0, 0, 0, 0, calendar);
const result = pdt.daysInYear;
assert.sameValue(result, "7", "result");
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class CustomCalendar extends Temporal.Calendar {
inLeapYear(...args) {
++calls;
assert.compareArray(args, [pdt], "inLeapYear arguments");
return "7";
return true;
}
}

const calendar = new CustomCalendar();
const pdt = new Temporal.PlainDateTime(1830, 8, 25, 20, 0, 0, 0, 0, 0, calendar);
const result = pdt.inLeapYear;
assert.sameValue(result, "7", "result");
assert.sameValue(result, true, "result");
assert.sameValue(calls, 1, "calls");
27 changes: 27 additions & 0 deletions test/built-ins/Temporal/PlainDateTime/prototype/month/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindatetime.prototype.month
description: Custom calendar tests for month().
includes: [compareArray.js]
features: [Temporal]
---*/

let calls = 0;
class CustomCalendar extends Temporal.Calendar {
constructor() {
super("iso8601");
}
month(...args) {
++calls;
assert.compareArray(args, [pdt], "month arguments");
return 7;
}
}

const calendar = new CustomCalendar();
const pdt = new Temporal.PlainDateTime(1830, 8, 25, 20, 0, 0, 0, 0, 0, calendar);
const result = pdt.month;
assert.sameValue(result, 7, "result");
assert.sameValue(calls, 1, "calls");
Loading

0 comments on commit b83af50

Please sign in to comment.