mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 05:55:36 +02:00
Temporal: Port PlainDateTime
's Demitasse withCalendar
tests
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
This commit is contained in:
parent
8f5c7aed09
commit
d156a5a63f
37
test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js
vendored
Normal file
37
test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.withcalendar
|
||||
description: String argument, if it names a recognizable calendar, gets cast
|
||||
features: [Temporal]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = {
|
||||
toString() { return "something special"; }
|
||||
};
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar);
|
||||
const result = dt.withCalendar("iso8601");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
result,
|
||||
1976, 11, "M11", 18, 15, 23, 30, 123, 456, 789,
|
||||
"'iso8601' is a recognizable calendar"
|
||||
);
|
||||
|
||||
const resultCalendar = result.calendar;
|
||||
|
||||
assert.sameValue(
|
||||
resultCalendar instanceof Temporal.Calendar,
|
||||
true,
|
||||
"underlying calendar is no longer a plain object"
|
||||
);
|
||||
|
||||
assert.sameValue(resultCalendar.toString(), "iso8601", "underlying calendar has changed");
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => dt.withCalendar("this will fail"),
|
||||
"unknown calendar throws"
|
||||
);
|
22
test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/basic.js
vendored
Normal file
22
test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/basic.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.plaindatetime.prototype.withcalendar
|
||||
description: Non-throwing non-edge case
|
||||
features: [Temporal]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789);
|
||||
const calendar = new Temporal.Calendar("iso8601");
|
||||
|
||||
const result = dt.withCalendar(calendar);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
result,
|
||||
1976, 11, "M11", 18, 15, 23, 30, 123, 456, 789,
|
||||
"works"
|
||||
);
|
||||
|
||||
assert.sameValue(result.calendar, calendar, "underlying calendar is unchanged");
|
Loading…
x
Reference in New Issue
Block a user