From d156a5a63f2a20ef36b1da0a69e5548e9d355d18 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Mon, 25 Apr 2022 11:03:57 +0200 Subject: [PATCH] Temporal: Port `PlainDateTime`'s Demitasse `withCalendar` tests Co-authored-by: Philip Chimento --- .../prototype/withCalendar/argument-string.js | 37 +++++++++++++++++++ .../prototype/withCalendar/basic.js | 22 +++++++++++ 2 files changed, 59 insertions(+) create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/basic.js diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js new file mode 100644 index 0000000000..b75ace828f --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js @@ -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" +); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/basic.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/basic.js new file mode 100644 index 0000000000..318f552ab5 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/basic.js @@ -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");