mirror of https://github.com/tc39/test262.git
Temporal: Expand and regularize existing calendarName option tests
Since we are going to be adding a new test for calendarName: "critical", take the existing tests for various values of the calendarName option, and regularize them. Previously, depending on which type's toString() method was under test, the tests had various degrees of thoroughness, and some were only present in staging.
This commit is contained in:
parent
6bfb4441d3
commit
0c18f7045b
|
@ -3,7 +3,7 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.protoype.tostring
|
||||
description: Should call 'toString' on the calendar once unless calendarName == 'never'.
|
||||
description: Number of observable 'toString' calls on the calendar for each value of calendarName
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -23,6 +23,6 @@ const date = new Temporal.PlainDate(2000, 5, 2, customCalendar);
|
|||
].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'`);
|
||||
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
|
||||
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
|
||||
});
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// 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: always value for calendarName option
|
||||
esid: sec-temporal.plaindate.prototype.tostring
|
||||
description: If calendarName is "always", the calendar ID should be included.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const customCalendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const customISOCalendar = {
|
||||
toString() { return "iso8601"; }
|
||||
};
|
||||
[
|
||||
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02[u-ca=iso8601]"],
|
||||
[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]) => {
|
||||
const tests = [
|
||||
[[], "2000-05-02[u-ca=iso8601]", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "2000-05-02[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "2000-05-02[u-ca=iso8601]", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "2000-05-02[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.PlainDate(2000, 5, 2, ...args);
|
||||
const result = date.toString({ calendarName: "always" });
|
||||
assert.sameValue(result, expected, "expected " + expected);
|
||||
});
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = always`);
|
||||
}
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// 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: auto value for calendarName option
|
||||
esid: sec-temporal.plaindate.prototype.tostring
|
||||
description: If calendarName is "auto", "iso8601" should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const customCalendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const customISOCalendar = {
|
||||
toString() { return "iso8601"; }
|
||||
};
|
||||
[
|
||||
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02"],
|
||||
[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]) => {
|
||||
const tests = [
|
||||
[[], "2000-05-02", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "2000-05-02[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "2000-05-02", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "2000-05-02[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.PlainDate(2000, 5, 2, ...args);
|
||||
const result = date.toString({ calendarName: "auto" });
|
||||
assert.sameValue(result, expected, "expected " + expected);
|
||||
});
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = auto`);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,12 @@ features: [Temporal]
|
|||
---*/
|
||||
|
||||
const date = new Temporal.PlainDate(2000, 5, 2);
|
||||
const values = ["ALWAYS", "sometimes", "other string", "auto\0"];
|
||||
const invalidValues = ["ALWAYS", "sometimes", "other string", "auto\0"];
|
||||
|
||||
for (const calendarName of values) {
|
||||
assert.throws(RangeError, () => date.toString({ calendarName }));
|
||||
for (const calendarName of invalidValues) {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => date.toString({ calendarName }),
|
||||
`${calendarName} is an invalid value for calendarName option`
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// 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: never value for calendarName option
|
||||
esid: sec-temporal.plaindate.prototype.tostring
|
||||
description: If calendarName is "never", the calendar ID should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const customCalendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const customISOCalendar = {
|
||||
toString() { return "iso8601"; }
|
||||
};
|
||||
[
|
||||
[new Temporal.PlainDate(2000, 5, 2), "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]) => {
|
||||
const tests = [
|
||||
[[], "2000-05-02", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "2000-05-02", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "2000-05-02", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "2000-05-02", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "2000-05-02", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.PlainDate(2000, 5, 2, ...args);
|
||||
const result = date.toString({ calendarName: "never" });
|
||||
assert.sameValue(result, expected, "expected " + expected);
|
||||
});
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = never`);
|
||||
}
|
||||
|
|
|
@ -14,20 +14,17 @@ info: |
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const customCalendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const customISOCalendar = {
|
||||
toString() { return "iso8601"; }
|
||||
};
|
||||
[
|
||||
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02"],
|
||||
[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]) => {
|
||||
const explicit = date.toString({ calendarName: undefined });
|
||||
assert.sameValue(explicit, expected, "default calendarName option is auto");
|
||||
const tests = [
|
||||
[[], "2000-05-02", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "2000-05-02[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "2000-05-02", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "2000-05-02[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
const implicit = date.toString({});
|
||||
assert.sameValue(implicit, expected, "default calendarName option is auto");
|
||||
});
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.PlainDate(2000, 5, 2, ...args);
|
||||
const result = date.toString({ calendarName: undefined });
|
||||
assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`);
|
||||
// See options-object.js for {} and options-undefined.js for absent options arg
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.protoype.tostring
|
||||
description: Should call 'toString' on the calendar once unless calendarName == 'never'.
|
||||
description: Number of observable 'toString' calls on the calendar for each value of calendarName
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -23,6 +23,6 @@ const date = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, c
|
|||
].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'`);
|
||||
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
|
||||
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
|
||||
});
|
||||
|
|
|
@ -3,14 +3,20 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.tostring
|
||||
description: Show ISO calendar if calendar name is "always"
|
||||
description: If calendarName is "always", the calendar ID should be included.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23);
|
||||
const tests = [
|
||||
[[], "1976-11-18T15:23:00[u-ca=iso8601]", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1976-11-18T15:23:00[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00[u-ca=iso8601]", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
assert.sameValue(
|
||||
dt.toString({ calendarName: "always" }),
|
||||
"1976-11-18T15:23:00[u-ca=iso8601]",
|
||||
"shows ISO calendar if calendarName = always"
|
||||
);
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args);
|
||||
const result = date.toString({ calendarName: "always" });
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = always`);
|
||||
}
|
||||
|
|
|
@ -3,33 +3,20 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.tostring
|
||||
description: Possibly display calendar when calendarName is "auto"
|
||||
description: If calendarName is "auto", "iso8601" should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[[], "1976-11-18T15:23:00", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1976-11-18T15:23:00[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23);
|
||||
const customCal = {
|
||||
toString() { return "bogus"; }
|
||||
};
|
||||
const fakeISO8601Cal = {
|
||||
toString() { return "iso8601"; }
|
||||
};
|
||||
const expected = "1976-11-18T15:23:00";
|
||||
|
||||
assert.sameValue(dt.toString(), expected, "default is calendar = auto (zero arguments)");
|
||||
assert.sameValue(dt.toString({ calendarName: "auto" }), expected, "shows only non-ISO calendar if calendarName = auto");
|
||||
|
||||
assert.sameValue(
|
||||
dt.withCalendar(fakeISO8601Cal).toString({ calendarName: "auto" }),
|
||||
expected,
|
||||
"Don't show ISO calendar even if calendarName = auto"
|
||||
);
|
||||
|
||||
const dt2 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, customCal);
|
||||
|
||||
assert.sameValue(
|
||||
dt2.toString({ calendarName: "auto" }),
|
||||
"1976-11-18T15:23:00[u-ca=bogus]",
|
||||
"Don't show calendar if calendarName = auto & PlainDateTime has non-ISO calendar"
|
||||
);
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args);
|
||||
const result = date.toString({ calendarName: "auto" });
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = auto`);
|
||||
}
|
||||
|
|
|
@ -15,11 +15,12 @@ features: [Temporal]
|
|||
---*/
|
||||
|
||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||
const invalidCals = ["other string", "ALWAYS", "sometimes", "auto\0"];
|
||||
const invalidValues = ["ALWAYS", "sometimes", "other string", "auto\0"];
|
||||
|
||||
invalidCals.forEach((cal) => {
|
||||
for (const calendarName of invalidValues) {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => datetime.toString({ calendarName: cal }),
|
||||
`invalid calendar (${cal})`);
|
||||
});
|
||||
() => datetime.toString({ calendarName }),
|
||||
`${calendarName} is an invalid value for calendarName option`
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3,24 +3,20 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.tostring
|
||||
description: Do not show calendar if calendar name option is "never"
|
||||
description: If calendarName is "never", the calendar ID should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23);
|
||||
const cal = {
|
||||
toString() { return "bogus"; }
|
||||
};
|
||||
const expected = "1976-11-18T15:23:00";
|
||||
const tests = [
|
||||
[[], "1976-11-18T15:23:00", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1976-11-18T15:23:00", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
assert.sameValue(
|
||||
dt.toString({ calendarName: "never" }),
|
||||
expected,
|
||||
"Do not show calendar if calendarName = never"
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
dt.withCalendar(cal).toString({ calendarName: "never" }),
|
||||
expected,
|
||||
"Do not show calendar when calendarName = never, even if non-ISO calendar is used"
|
||||
);
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args);
|
||||
const result = date.toString({ calendarName: "never" });
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = never`);
|
||||
}
|
||||
|
|
|
@ -14,18 +14,17 @@ info: |
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const datetime1 = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||
const datetime2 = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
|
||||
const tests = [
|
||||
[[], "1976-11-18T15:23:00", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1976-11-18T15:23:00[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
[
|
||||
[datetime1, "2000-05-02T12:34:56.987654321"],
|
||||
[datetime2, "2000-05-02T12:34:56.987654321[u-ca=custom]"],
|
||||
].forEach(([datetime, expected]) => {
|
||||
const explicit = datetime.toString({ calendarName: undefined });
|
||||
assert.sameValue(explicit, expected, "default calendarName option is auto");
|
||||
|
||||
// See options-undefined.js for {}
|
||||
});
|
||||
for (const [args, expected, description] of tests) {
|
||||
const datetime = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args);
|
||||
const result = datetime.toString({ calendarName: undefined });
|
||||
assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`);
|
||||
// See options-object.js for {} and options-undefined.js for absent options arg
|
||||
}
|
||||
|
|
28
test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendar-tostring.js
vendored
Normal file
28
test/built-ins/Temporal/PlainMonthDay/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.plainmonthday.protoype.tostring
|
||||
description: Number of observable 'toString' calls on the calendar for each value of calendarName
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls;
|
||||
const customCalendar = {
|
||||
toString() {
|
||||
++calls;
|
||||
return "custom";
|
||||
}
|
||||
};
|
||||
const monthday = new Temporal.PlainMonthDay(5, 2, customCalendar);
|
||||
[
|
||||
["always", "1972-05-02[u-ca=custom]", 1],
|
||||
["auto", "1972-05-02[u-ca=custom]", 1],
|
||||
["never", "1972-05-02", 1],
|
||||
[undefined, "1972-05-02[u-ca=custom]", 1],
|
||||
].forEach(([calendarName, expectedResult, expectedCalls]) => {
|
||||
calls = 0;
|
||||
const result = monthday.toString({ calendarName });
|
||||
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
|
||||
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
|
||||
});
|
|
@ -1,22 +1,22 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// 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.plainmonthday.protoype.tostring
|
||||
esid: sec-temporal.plainmonthday.prototype.tostring
|
||||
description: If calendarName is "always", the calendar ID should be included.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[[], "1972-05-02[u-ca=iso8601]"],
|
||||
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]"],
|
||||
[[{ toString() { return "iso8601"; } }], "1972-05-02[u-ca=iso8601]"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]"], // dotless i
|
||||
[[], "1972-05-02[u-ca=iso8601]", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "1972-05-02[u-ca=iso8601]", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected] of tests) {
|
||||
for (const [args, expected, description] of tests) {
|
||||
const monthday = new Temporal.PlainMonthDay(5, 2, ...args);
|
||||
const result = monthday.toString({ calendarName: "always" });
|
||||
assert.sameValue(result, expected);
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = always`);
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// 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.plainmonthday.protoype.tostring
|
||||
esid: sec-temporal.plainmonthday.prototype.tostring
|
||||
description: If calendarName is "auto", "iso8601" should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[[], "05-02"],
|
||||
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]"],
|
||||
[[{ toString() { return "iso8601"; } }], "05-02"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]"], // dotless i
|
||||
[[], "05-02", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "05-02", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected] of tests) {
|
||||
for (const [args, expected, description] of tests) {
|
||||
const monthday = new Temporal.PlainMonthDay(5, 2, ...args);
|
||||
const result = monthday.toString({ calendarName: "auto" });
|
||||
assert.sameValue(result, expected);
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = auto`);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,12 @@ features: [Temporal]
|
|||
---*/
|
||||
|
||||
const monthday = new Temporal.PlainMonthDay(5, 2);
|
||||
for (const calendarName of ["ALWAYS", "sometimes", "other string"]) {
|
||||
assert.throws(RangeError, () => monthday.toString({ calendarName }));
|
||||
const invalidValues = ["ALWAYS", "sometimes", "other string", "auto\0"];
|
||||
|
||||
for (const calendarName of invalidValues) {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => monthday.toString({ calendarName }),
|
||||
`${calendarName} is an invalid value for calendarName option`
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// 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.plainmonthday.protoype.tostring
|
||||
esid: sec-temporal.plainmonthday.prototype.tostring
|
||||
description: If calendarName is "never", the calendar ID should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[[], "05-02"],
|
||||
[[{ toString() { return "custom"; } }], "1972-05-02"],
|
||||
[[{ toString() { return "iso8601"; } }], "05-02"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1972-05-02"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02"], // dotless i
|
||||
[[], "05-02", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1972-05-02", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "05-02", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1972-05-02", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected] of tests) {
|
||||
for (const [args, expected, description] of tests) {
|
||||
const monthday = new Temporal.PlainMonthDay(5, 2, ...args);
|
||||
const result = monthday.toString({ calendarName: "never" });
|
||||
assert.sameValue(result, expected);
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = never`);
|
||||
}
|
||||
|
|
|
@ -15,18 +15,16 @@ features: [Temporal]
|
|||
---*/
|
||||
|
||||
const tests = [
|
||||
[[], "05-02"],
|
||||
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]"],
|
||||
[[{ toString() { return "iso8601"; } }], "05-02"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]"], // dotless i
|
||||
[[], "05-02", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "05-02", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected] of tests) {
|
||||
for (const [args, expected, description] of tests) {
|
||||
const monthday = new Temporal.PlainMonthDay(5, 2, ...args);
|
||||
const explicit = monthday.toString({ calendarName: undefined });
|
||||
assert.sameValue(explicit, expected, "default calendarName option is auto");
|
||||
|
||||
const implicit = monthday.toString({});
|
||||
assert.sameValue(implicit, expected, "default calendarName option is auto");
|
||||
const result = monthday.toString({ calendarName: undefined });
|
||||
assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`);
|
||||
// See options-object.js for {} and options-undefined.js for absent options arg
|
||||
}
|
||||
|
|
28
test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendar-tostring.js
vendored
Normal file
28
test/built-ins/Temporal/PlainYearMonth/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.plainyearmonth.protoype.tostring
|
||||
description: Number of observable 'toString' calls on the calendar for each value of calendarName
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let calls;
|
||||
const customCalendar = {
|
||||
toString() {
|
||||
++calls;
|
||||
return "custom";
|
||||
}
|
||||
};
|
||||
const yearmonth = new Temporal.PlainYearMonth(2000, 5, customCalendar);
|
||||
[
|
||||
["always", "2000-05-01[u-ca=custom]", 1],
|
||||
["auto", "2000-05-01[u-ca=custom]", 1],
|
||||
["never", "2000-05-01", 1],
|
||||
[undefined, "2000-05-01[u-ca=custom]", 1],
|
||||
].forEach(([calendarName, expectedResult, expectedCalls]) => {
|
||||
calls = 0;
|
||||
const result = yearmonth.toString({ calendarName });
|
||||
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
|
||||
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
|
||||
});
|
|
@ -2,21 +2,21 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.protoype.tostring
|
||||
description: always value for calendarName option
|
||||
esid: sec-temporal.plainyearmonth.prototype.tostring
|
||||
description: If calendarName is "always", the calendar ID should be included.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const yearmonth1 = new Temporal.PlainYearMonth(2000, 5);
|
||||
const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, calendar);
|
||||
const tests = [
|
||||
[[], "2000-05-01[u-ca=iso8601]", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "2000-05-01[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "2000-05-01[u-ca=iso8601]", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "2000-05-01[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
[
|
||||
[yearmonth1, "2000-05-01[u-ca=iso8601]"], // fallback day 1 used
|
||||
[yearmonth2, "2000-05-01[u-ca=custom]"],
|
||||
].forEach(([yearmonth, expected]) => {
|
||||
for (const [args, expected, description] of tests) {
|
||||
const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args);
|
||||
const result = yearmonth.toString({ calendarName: "always" });
|
||||
assert.sameValue(result, expected, "calendarName is always");
|
||||
});
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = always`);
|
||||
}
|
||||
|
|
|
@ -2,21 +2,21 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.protoype.tostring
|
||||
description: auto value for calendarName option
|
||||
esid: sec-temporal.plainyearmonth.prototype.tostring
|
||||
description: If calendarName is "auto", "iso8601" should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const yearmonth1 = new Temporal.PlainYearMonth(2000, 5);
|
||||
const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, calendar);
|
||||
const tests = [
|
||||
[[], "2000-05", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "2000-05-01[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "2000-05", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "2000-05-01[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
[
|
||||
[yearmonth1, "2000-05"],
|
||||
[yearmonth2, "2000-05-01[u-ca=custom]"],
|
||||
].forEach(([yearmonth, expected]) => {
|
||||
for (const [args, expected, description] of tests) {
|
||||
const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args);
|
||||
const result = yearmonth.toString({ calendarName: "auto" });
|
||||
assert.sameValue(result, expected, "calendarName is auto");
|
||||
});
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = auto`);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,12 @@ features: [Temporal]
|
|||
---*/
|
||||
|
||||
const yearmonth = new Temporal.PlainYearMonth(2000, 5);
|
||||
for (const calendarName of ["ALWAYS", "sometimes", "other string"]) {
|
||||
assert.throws(RangeError, () => yearmonth.toString({ calendarName }));
|
||||
const invalidValues = ["ALWAYS", "sometimes", "other string", "auto\0"];
|
||||
|
||||
for (const calendarName of invalidValues) {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => yearmonth.toString({ calendarName }),
|
||||
`${calendarName} is an invalid value for calendarName option`
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,21 +2,21 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.protoype.tostring
|
||||
description: never value for calendarName option
|
||||
esid: sec-temporal.plainyearmonth.prototype.tostring
|
||||
description: If calendarName is "never", the calendar ID should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const yearmonth1 = new Temporal.PlainYearMonth(2000, 5);
|
||||
const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, calendar);
|
||||
const tests = [
|
||||
[[], "2000-05", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "2000-05-01", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "2000-05", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "2000-05-01", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "2000-05-01", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
[
|
||||
[yearmonth1, "2000-05"],
|
||||
[yearmonth2, "2000-05-01"],
|
||||
].forEach(([yearmonth, expected]) => {
|
||||
for (const [args, expected, description] of tests) {
|
||||
const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args);
|
||||
const result = yearmonth.toString({ calendarName: "never" });
|
||||
assert.sameValue(result, expected, "calendarName is never");
|
||||
});
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = never`);
|
||||
}
|
||||
|
|
|
@ -14,19 +14,17 @@ info: |
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const yearmonth1 = new Temporal.PlainYearMonth(2000, 5);
|
||||
const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, calendar);
|
||||
const tests = [
|
||||
[[], "2000-05", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "2000-05-01[u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "2000-05", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "2000-05-01[u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
[
|
||||
[yearmonth1, "2000-05"],
|
||||
[yearmonth2, "2000-05-01[u-ca=custom]"],
|
||||
].forEach(([yearmonth, expected]) => {
|
||||
const explicit = yearmonth.toString({ calendarName: undefined });
|
||||
assert.sameValue(explicit, expected, "default calendarName option is auto");
|
||||
|
||||
const implicit = yearmonth.toString({});
|
||||
assert.sameValue(implicit, expected, "default calendarName option is auto");
|
||||
});
|
||||
for (const [args, expected, description] of tests) {
|
||||
const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args);
|
||||
const result = yearmonth.toString({ calendarName: undefined });
|
||||
assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`);
|
||||
// See options-object.js for {} and options-undefined.js for absent options arg
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.protoype.tostring
|
||||
description: Should call 'toString' on the calendar once unless calendarName == 'never'.
|
||||
description: Number of observable 'toString' calls on the calendar for each value of calendarName
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -14,15 +14,15 @@ const customCalendar = {
|
|||
return "custom";
|
||||
}
|
||||
};
|
||||
const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", customCalendar);
|
||||
const date = new Temporal.ZonedDateTime(1_000_000_000_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],
|
||||
["always", "2001-09-09T01:46:40.987654321+00:00[UTC][u-ca=custom]", 1],
|
||||
["auto", "2001-09-09T01:46:40.987654321+00:00[UTC][u-ca=custom]", 1],
|
||||
["never", "2001-09-09T01:46:40.987654321+00:00[UTC]", 0],
|
||||
[undefined, "2001-09-09T01:46:40.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'`);
|
||||
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
|
||||
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
|
||||
});
|
||||
|
|
22
test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-always.js
vendored
Normal file
22
test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-always.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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.prototype.tostring
|
||||
description: If calendarName is "always", the calendar ID should be included.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[[], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=iso8601]", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=iso8601]", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args);
|
||||
const result = date.toString({ calendarName: "always" });
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = always`);
|
||||
}
|
22
test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-auto.js
vendored
Normal file
22
test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-auto.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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.prototype.tostring
|
||||
description: If calendarName is "auto", "iso8601" should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args);
|
||||
const result = date.toString({ calendarName: "auto" });
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = auto`);
|
||||
}
|
|
@ -14,5 +14,13 @@ info: |
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_64_321n, "UTC");
|
||||
assert.throws(RangeError, () => datetime.toString({ calendarName: "other string" }));
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
|
||||
const invalidValues = ["ALWAYS", "sometimes", "other string", "auto\0"];
|
||||
|
||||
for (const calendarName of invalidValues) {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => datetime.toString({ calendarName }),
|
||||
`${calendarName} is an invalid value for calendarName option`
|
||||
);
|
||||
}
|
||||
|
|
22
test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-never.js
vendored
Normal file
22
test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-never.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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.prototype.tostring
|
||||
description: If calendarName is "never", the calendar ID should be omitted.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected, description] of tests) {
|
||||
const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args);
|
||||
const result = date.toString({ calendarName: "never" });
|
||||
assert.sameValue(result, expected, `${description} calendar for calendarName = never`);
|
||||
}
|
|
@ -14,19 +14,17 @@ info: |
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = {
|
||||
toString() { return "custom"; }
|
||||
};
|
||||
const datetime1 = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
|
||||
const datetime2 = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", calendar);
|
||||
|
||||
[
|
||||
[datetime1, "2001-09-09T01:46:40.987654321+00:00[UTC]"],
|
||||
[datetime2, "2001-09-09T01:46:40.987654321+00:00[UTC][u-ca=custom]"],
|
||||
].forEach(([datetime, expected]) => {
|
||||
const explicit = datetime.toString({ calendarName: undefined });
|
||||
assert.sameValue(explicit, expected, "default calendarName option is auto");
|
||||
|
||||
// See options-undefined.js for {}
|
||||
});
|
||||
const tests = [
|
||||
[[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"],
|
||||
[[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"],
|
||||
[[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 toString"],
|
||||
[[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps toString"],
|
||||
[[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i toString"],
|
||||
];
|
||||
|
||||
for (const [args, expected, description] of tests) {
|
||||
const datetime = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args);
|
||||
const result = datetime.toString({ calendarName: undefined });
|
||||
assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`);
|
||||
// See options-object.js for {} and options-undefined.js for absent options arg
|
||||
}
|
||||
|
|
|
@ -11,25 +11,6 @@ features: [Temporal]
|
|||
var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23+00:00[UTC]");
|
||||
var fakeGregorian = { toString() { return "gregory" }};
|
||||
|
||||
// shows only non-ISO calendar if calendarName = auto
|
||||
assert.sameValue(zdt1.toString({ calendarName: "auto" }), "1976-11-18T15:23:00+00:00[UTC]");
|
||||
assert.sameValue(zdt1.withCalendar(fakeGregorian).toString({ calendarName: "auto" }), "1976-11-18T15:23:00+00:00[UTC][u-ca=gregory]");
|
||||
|
||||
// shows ISO calendar if calendarName = always
|
||||
assert.sameValue(zdt1.toString({ calendarName: "always" }), "1976-11-18T15:23:00+00:00[UTC][u-ca=iso8601]");
|
||||
|
||||
// omits non-ISO calendar if calendarName = never
|
||||
assert.sameValue(zdt1.withCalendar(fakeGregorian).toString({ calendarName: "never" }), "1976-11-18T15:23:00+00:00[UTC]");
|
||||
|
||||
// throws on invalid calendar
|
||||
[
|
||||
"ALWAYS",
|
||||
"sometimes",
|
||||
false,
|
||||
].forEach(calendarName => {
|
||||
assert.throws(RangeError, () => zdt1.toString({ calendarName }));
|
||||
});
|
||||
|
||||
// shows time zone if timeZoneName = auto
|
||||
assert.sameValue(zdt1.toString({ timeZoneName: "auto" }), "1976-11-18T15:23:00+00:00[UTC]");
|
||||
|
||||
|
|
Loading…
Reference in New Issue