forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Adjust and expand tests for observable calls to ToString(ca…
…lendar) This implements the normative change in tc39/proposal-temporal#2269 which reached consensus at the July 2022 TC39 meeting. There was already a test for PlainDate for this topic, which needs to be adjusted to accommodate the normative change. Tests for PlainDateTime and ZonedDateTime did not yet exist, so add new ones based on the PlainDate test.
- Loading branch information
Showing
3 changed files
with
64 additions
and
8 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
28 changes: 28 additions & 0 deletions
28
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.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,28 @@ | ||
// 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.protoype.tostring | ||
description: Should call 'toString' on the calendar once unless calendarName == 'never'. | ||
features: [Temporal] | ||
---*/ | ||
|
||
let calls; | ||
const customCalendar = { | ||
toString() { | ||
++calls; | ||
return "custom"; | ||
} | ||
}; | ||
const date = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, customCalendar); | ||
[ | ||
["always", "2000-05-02T12:34:56.987654321[u-ca=custom]", 1], | ||
["auto", "2000-05-02T12:34:56.987654321[u-ca=custom]", 1], | ||
["never", "2000-05-02T12:34:56.987654321", 0], | ||
[undefined, "2000-05-02T12:34:56.987654321[u-ca=custom]", 1], | ||
].forEach(([calendarName, expectedResult, expectedCalls]) => { | ||
calls = 0; | ||
const result = date.toString({ calendarName }); | ||
assert.sameValue(result, expectedResult, `calendarName = ${calendarName}: expected ${expectedResult}`); | ||
assert.sameValue(calls, expectedCalls, `calendarName = ${calendarName}: expected ${expectedCalls} call(s) to 'toString'`); | ||
}); |
28 changes: 28 additions & 0 deletions
28
test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendar-tostring.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,28 @@ | ||
// 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.protoype.tostring | ||
description: Should call 'toString' on the calendar once unless calendarName == 'never'. | ||
features: [Temporal] | ||
---*/ | ||
|
||
let calls; | ||
const customCalendar = { | ||
toString() { | ||
++calls; | ||
return "custom"; | ||
} | ||
}; | ||
const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", customCalendar); | ||
[ | ||
["always", "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", 1], | ||
["auto", "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", 1], | ||
["never", "1970-01-01T01:01:01.987654321+00:00[UTC]", 0], | ||
[undefined, "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", 1], | ||
].forEach(([calendarName, expectedResult, expectedCalls]) => { | ||
calls = 0; | ||
const result = date.toString({ calendarName }); | ||
assert.sameValue(result, expectedResult, `calendarName = ${calendarName}: expected ${expectedResult}`); | ||
assert.sameValue(calls, expectedCalls, `calendarName = ${calendarName}: expected ${expectedCalls} call(s) to 'toString'`); | ||
}); |