-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Port Demitasse tests for
PlainDateTime
's toString
- Loading branch information
1 parent
28b31c0
commit dcd25e6
Showing
7 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 35 additions & 0 deletions
35
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 16 additions & 0 deletions
16
test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
); |
14 changes: 14 additions & 0 deletions
14
test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 16 additions & 0 deletions
16
test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
); |