Skip to content

Commit 10a5c4f

Browse files
ptomatoMs2ger
authored andcommitted
Temporal: Adjust and expand tests for observable calls to ToString(calendar)
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.
1 parent 1587af3 commit 10a5c4f

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

test/built-ins/Temporal/PlainDate/prototype/toString/calendar-tostring.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/*---
55
esid: sec-temporal.plaindate.protoype.tostring
6-
description: Should always call 'toString' on the calendar once.
6+
description: Should call 'toString' on the calendar once unless calendarName == 'never'.
77
features: [Temporal]
88
---*/
99

@@ -16,13 +16,13 @@ const customCalendar = {
1616
};
1717
const date = new Temporal.PlainDate(2000, 5, 2, customCalendar);
1818
[
19-
["always", "2000-05-02[u-ca=custom]"],
20-
["auto", "2000-05-02[u-ca=custom]"],
21-
["never", "2000-05-02"],
22-
[undefined, "2000-05-02[u-ca=custom]"],
23-
].forEach(([calendarName, expected]) => {
19+
["always", "2000-05-02[u-ca=custom]", 1],
20+
["auto", "2000-05-02[u-ca=custom]", 1],
21+
["never", "2000-05-02", 0],
22+
[undefined, "2000-05-02[u-ca=custom]", 1],
23+
].forEach(([calendarName, expectedResult, expectedCalls]) => {
2424
calls = 0;
2525
const result = date.toString({ calendarName });
26-
assert.sameValue(result, expected, `calendarName = ${calendarName}: expected ${expected}`);
27-
assert.sameValue(calls, 1, `calendarName = ${calendarName}: expected one call to 'toString'`);
26+
assert.sameValue(result, expectedResult, `calendarName = ${calendarName}: expected ${expectedResult}`);
27+
assert.sameValue(calls, expectedCalls, `calendarName = ${calendarName}: expected ${expectedCalls} call(s) to 'toString'`);
2828
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindatetime.protoype.tostring
6+
description: Should call 'toString' on the calendar once unless calendarName == 'never'.
7+
features: [Temporal]
8+
---*/
9+
10+
let calls;
11+
const customCalendar = {
12+
toString() {
13+
++calls;
14+
return "custom";
15+
}
16+
};
17+
const date = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, customCalendar);
18+
[
19+
["always", "2000-05-02T12:34:56.987654321[u-ca=custom]", 1],
20+
["auto", "2000-05-02T12:34:56.987654321[u-ca=custom]", 1],
21+
["never", "2000-05-02T12:34:56.987654321", 0],
22+
[undefined, "2000-05-02T12:34:56.987654321[u-ca=custom]", 1],
23+
].forEach(([calendarName, expectedResult, expectedCalls]) => {
24+
calls = 0;
25+
const result = date.toString({ calendarName });
26+
assert.sameValue(result, expectedResult, `calendarName = ${calendarName}: expected ${expectedResult}`);
27+
assert.sameValue(calls, expectedCalls, `calendarName = ${calendarName}: expected ${expectedCalls} call(s) to 'toString'`);
28+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.protoype.tostring
6+
description: Should call 'toString' on the calendar once unless calendarName == 'never'.
7+
features: [Temporal]
8+
---*/
9+
10+
let calls;
11+
const customCalendar = {
12+
toString() {
13+
++calls;
14+
return "custom";
15+
}
16+
};
17+
const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", customCalendar);
18+
[
19+
["always", "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", 1],
20+
["auto", "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", 1],
21+
["never", "1970-01-01T01:01:01.987654321+00:00[UTC]", 0],
22+
[undefined, "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", 1],
23+
].forEach(([calendarName, expectedResult, expectedCalls]) => {
24+
calls = 0;
25+
const result = date.toString({ calendarName });
26+
assert.sameValue(result, expectedResult, `calendarName = ${calendarName}: expected ${expectedResult}`);
27+
assert.sameValue(calls, expectedCalls, `calendarName = ${calendarName}: expected ${expectedCalls} call(s) to 'toString'`);
28+
});

0 commit comments

Comments
 (0)