mirror of https://github.com/tc39/test262.git
Temporal: Extend tests for PlainDate#toString.
This commit is contained in:
parent
194f7426f9
commit
3812a1fe92
|
@ -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.plaindate.protoype.tostring
|
||||||
|
description: Should always call 'toString' on the calendar once.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let calls;
|
||||||
|
const customCalendar = {
|
||||||
|
toString() {
|
||||||
|
++calls;
|
||||||
|
return "custom";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
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]) => {
|
||||||
|
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'`);
|
||||||
|
});
|
|
@ -7,15 +7,16 @@ description: always value for calendarName option
|
||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const calendar = {
|
const customCalendar = {
|
||||||
toString() { return "custom"; }
|
toString() { return "custom"; }
|
||||||
};
|
};
|
||||||
const date1 = new Temporal.PlainDate(2000, 5, 2);
|
const customISOCalendar = {
|
||||||
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
|
toString() { return "iso8601"; }
|
||||||
|
};
|
||||||
[
|
[
|
||||||
[date1, "2000-05-02[u-ca=iso8601]"],
|
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02[u-ca=iso8601]"],
|
||||||
[date2, "2000-05-02[u-ca=custom]"],
|
[new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02[u-ca=custom]"],
|
||||||
|
[new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02[u-ca=iso8601]"],
|
||||||
].forEach(([date, expected]) => {
|
].forEach(([date, expected]) => {
|
||||||
const result = date.toString({ calendarName: "always" });
|
const result = date.toString({ calendarName: "always" });
|
||||||
assert.sameValue(result, expected, "expected " + expected);
|
assert.sameValue(result, expected, "expected " + expected);
|
||||||
|
|
|
@ -7,15 +7,16 @@ description: auto value for calendarName option
|
||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const calendar = {
|
const customCalendar = {
|
||||||
toString() { return "custom"; }
|
toString() { return "custom"; }
|
||||||
};
|
};
|
||||||
const date1 = new Temporal.PlainDate(2000, 5, 2);
|
const customISOCalendar = {
|
||||||
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
|
toString() { return "iso8601"; }
|
||||||
|
};
|
||||||
[
|
[
|
||||||
[date1, "2000-05-02"],
|
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02"],
|
||||||
[date2, "2000-05-02[u-ca=custom]"],
|
[new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02[u-ca=custom]"],
|
||||||
|
[new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02"],
|
||||||
].forEach(([date, expected]) => {
|
].forEach(([date, expected]) => {
|
||||||
const result = date.toString({ calendarName: "auto" });
|
const result = date.toString({ calendarName: "auto" });
|
||||||
assert.sameValue(result, expected, "expected " + expected);
|
assert.sameValue(result, expected, "expected " + expected);
|
||||||
|
|
|
@ -15,7 +15,7 @@ features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const date = new Temporal.PlainDate(2000, 5, 2);
|
const date = new Temporal.PlainDate(2000, 5, 2);
|
||||||
const values = ["ALWAYS", "sometimes", "other string"];
|
const values = ["ALWAYS", "sometimes", "other string", "auto\0"];
|
||||||
|
|
||||||
for (const calendarName of values) {
|
for (const calendarName of values) {
|
||||||
assert.throws(RangeError, () => date.toString({ calendarName }));
|
assert.throws(RangeError, () => date.toString({ calendarName }));
|
||||||
|
|
|
@ -7,15 +7,16 @@ description: never value for calendarName option
|
||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const calendar = {
|
const customCalendar = {
|
||||||
toString() { return "custom"; }
|
toString() { return "custom"; }
|
||||||
};
|
};
|
||||||
const date1 = new Temporal.PlainDate(2000, 5, 2);
|
const customISOCalendar = {
|
||||||
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
|
toString() { return "iso8601"; }
|
||||||
|
};
|
||||||
[
|
[
|
||||||
[date1, "2000-05-02"],
|
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02"],
|
||||||
[date2, "2000-05-02"],
|
[new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02"],
|
||||||
|
[new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02"],
|
||||||
].forEach(([date, expected]) => {
|
].forEach(([date, expected]) => {
|
||||||
const result = date.toString({ calendarName: "never" });
|
const result = date.toString({ calendarName: "never" });
|
||||||
assert.sameValue(result, expected, "expected " + expected);
|
assert.sameValue(result, expected, "expected " + expected);
|
||||||
|
|
|
@ -14,15 +14,16 @@ info: |
|
||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const calendar = {
|
const customCalendar = {
|
||||||
toString() { return "custom"; }
|
toString() { return "custom"; }
|
||||||
};
|
};
|
||||||
const date1 = new Temporal.PlainDate(2000, 5, 2);
|
const customISOCalendar = {
|
||||||
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
|
toString() { return "iso8601"; }
|
||||||
|
};
|
||||||
[
|
[
|
||||||
[date1, "2000-05-02"],
|
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02"],
|
||||||
[date2, "2000-05-02[u-ca=custom]"],
|
[new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02[u-ca=custom]"],
|
||||||
|
[new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02"],
|
||||||
].forEach(([date, expected]) => {
|
].forEach(([date, expected]) => {
|
||||||
const explicit = date.toString({ calendarName: undefined });
|
const explicit = date.toString({ calendarName: undefined });
|
||||||
assert.sameValue(explicit, expected, "default calendarName option is auto");
|
assert.sameValue(explicit, expected, "default calendarName option is auto");
|
||||||
|
|
Loading…
Reference in New Issue