-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Adapt existing custom calendar getter tests, and expand
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
Showing
45 changed files
with
815 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/built-ins/Temporal/PlainDate/prototype/month/custom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
test/built-ins/Temporal/PlainDate/prototype/monthCode/custom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/built-ins/Temporal/PlainDate/prototype/year/custom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
test/built-ins/Temporal/PlainDateTime/prototype/day/custom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/built-ins/Temporal/PlainDateTime/prototype/month/custom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
Oops, something went wrong.