mirror of https://github.com/tc39/test262.git
Temporal: Adjust and expand tests for observable calls to ToString(calendar)
This implements the normative change in https://github.com/tc39/proposal-temporal/pull/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.
This commit is contained in:
parent
1587af3936
commit
10a5c4f784
|
@ -3,7 +3,7 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.protoype.tostring
|
||||
description: Should always call 'toString' on the calendar once.
|
||||
description: Should call 'toString' on the calendar once unless calendarName == 'never'.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -16,13 +16,13 @@ const customCalendar = {
|
|||
};
|
||||
const date = new Temporal.PlainDate(2000, 5, 2, customCalendar);
|
||||
[
|
||||
["always", "2000-05-02[u-ca=custom]"],
|
||||
["auto", "2000-05-02[u-ca=custom]"],
|
||||
["never", "2000-05-02"],
|
||||
[undefined, "2000-05-02[u-ca=custom]"],
|
||||
].forEach(([calendarName, expected]) => {
|
||||
["always", "2000-05-02[u-ca=custom]", 1],
|
||||
["auto", "2000-05-02[u-ca=custom]", 1],
|
||||
["never", "2000-05-02", 0],
|
||||
[undefined, "2000-05-02[u-ca=custom]", 1],
|
||||
].forEach(([calendarName, expectedResult, expectedCalls]) => {
|
||||
calls = 0;
|
||||
const result = date.toString({ calendarName });
|
||||
assert.sameValue(result, expected, `calendarName = ${calendarName}: expected ${expected}`);
|
||||
assert.sameValue(calls, 1, `calendarName = ${calendarName}: expected one call to 'toString'`);
|
||||
assert.sameValue(result, expectedResult, `calendarName = ${calendarName}: expected ${expectedResult}`);
|
||||
assert.sameValue(calls, expectedCalls, `calendarName = ${calendarName}: expected ${expectedCalls} call(s) to 'toString'`);
|
||||
});
|
||||
|
|
28
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.js
vendored
Normal file
28
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.js
vendored
Normal file
|
@ -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
test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendar-tostring.js
vendored
Normal file
28
test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendar-tostring.js
vendored
Normal file
|
@ -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'`);
|
||||
});
|
Loading…
Reference in New Issue