mirror of https://github.com/tc39/test262.git
Temporal: Port Demitasse tests for `PlainDateTime`'s `toString`
This commit is contained in:
parent
28b31c0bf1
commit
dcd25e616d
16
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js
vendored
Normal file
16
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// 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.prototype.tostring
|
||||
description: Show ISO calendar if calendar name is "always"
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23);
|
||||
|
||||
assert.sameValue(
|
||||
dt.toString({ calendarName: "always" }),
|
||||
"1976-11-18T15:23:00[u-ca=iso8601]",
|
||||
"shows ISO calendar if calendarName = always"
|
||||
);
|
35
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js
vendored
Normal file
35
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
// 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.prototype.tostring
|
||||
description: Possibly display calendar when calendarName is "auto"
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
||||
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"
|
||||
);
|
|
@ -15,4 +15,11 @@ features: [Temporal]
|
|||
---*/
|
||||
|
||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||
assert.throws(RangeError, () => datetime.toString({ calendarName: "other string" }));
|
||||
const invalidCals = ["other string", "ALWAYS", "sometimes", "auto\0"];
|
||||
|
||||
invalidCals.forEach((cal) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => datetime.toString({ calendarName: cal }),
|
||||
`invalid calendar (${cal})`);
|
||||
});
|
||||
|
|
26
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js
vendored
Normal file
26
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
// 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.prototype.tostring
|
||||
description: Do not show calendar if calendar name option is "never"
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23);
|
||||
const cal = {
|
||||
toString() { return "bogus"; }
|
||||
};
|
||||
const expected = "1976-11-18T15:23:00";
|
||||
|
||||
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"
|
||||
);
|
16
test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js
vendored
Normal file
16
test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// 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.prototype.tostring
|
||||
description: Show calendar when calendarName is "always"
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, "gregory");
|
||||
|
||||
assert.sameValue(
|
||||
dt.toString({ calendarName: "always" }),
|
||||
"1976-11-18T15:23:00[u-ca=gregory]",
|
||||
"shows non-ISO calendar if calendarName = always"
|
||||
);
|
|
@ -0,0 +1,14 @@
|
|||
// 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.prototype.tostring
|
||||
description: Possibly display calendar when calendarName is "auto"
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, "gregory");
|
||||
const expected = "1976-11-18T15:23:00[u-ca=gregory]";
|
||||
|
||||
assert.sameValue(dt.toString(), expected, "shows non-ISO calendar by default (no arguments)");
|
||||
assert.sameValue(dt.toString({ calendarName: "auto" }), expected, "shows only non-ISO calendar if calendarName = auto");
|
16
test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js
vendored
Normal file
16
test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// 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.prototype.tostring
|
||||
description: Do not show calendar (even non-ISO calendars) if calendarName = "never"
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23);
|
||||
|
||||
assert.sameValue(
|
||||
dt.withCalendar("gregory").toString({ calendarName: "never" }),
|
||||
"1976-11-18T15:23:00",
|
||||
"omits non-ISO calendar if calendarName = never"
|
||||
);
|
Loading…
Reference in New Issue