From cdcf2a3f091a56fa6674877336ed537671e639bb Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 19 Jul 2021 11:50:58 -0700 Subject: [PATCH] Add tests for Temporal.Calendar.p*.inLeapYear (Philip, March 2022: This was originally Frank's PR #3056. I did some reformatting, removed duplicate tests, and combined with some existing tests.) --- .../prototype/inLeapYear/argument-string.js | 26 +++++++++++++++++++ .../Calendar/prototype/inLeapYear/basic.js | 17 +++++++++--- .../Calendar/prototype/inLeapYear/branding.js | 20 +++++++------- 3 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string.js diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string.js new file mode 100644 index 00000000000..1c4272fbd72 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string.js @@ -0,0 +1,26 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.inleapyear +description: An ISO 8601 date string should be converted as input +info: | + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). +features: [Temporal] +---*/ + +const cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(cal.inLeapYear("2019-03-18"), false); +assert.sameValue(cal.inLeapYear("2020-03-18"), true); + +assert.sameValue(cal.inLeapYear("+002023-03-18"), false); +assert.sameValue(cal.inLeapYear("+002024-03-18"), true); + +assert.sameValue(cal.inLeapYear("2019-03-18T13:00:00+00:00[UTC]"), false); +assert.sameValue(cal.inLeapYear("2020-12-31T23:59:59+00:00[UTC]"), true); + +assert.sameValue(cal.inLeapYear("+002023-03-18T13:00:00+00:00[UTC]"), false); +assert.sameValue(cal.inLeapYear("+002024-03-18T13:00:00+00:00[UTC]"), true); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/basic.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/basic.js index 4359c4c8d44..7e8d3cf048b 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/basic.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/basic.js @@ -8,10 +8,19 @@ features: [Temporal] ---*/ const iso = Temporal.Calendar.from("iso8601"); -const res = false; -assert.sameValue(iso.inLeapYear(Temporal.PlainDate.from("1994-11-05")), res, "PlainDate"); -assert.sameValue(iso.inLeapYear(Temporal.PlainDateTime.from("1994-11-05T08:15:30")), res, "PlainDateTime"); -assert.sameValue(iso.inLeapYear(Temporal.PlainYearMonth.from("1994-11")), res, "PlainYearMonth"); +let res = false; + +assert.sameValue(iso.inLeapYear(new Temporal.PlainDate(1994, 11, 5)), res, "PlainDate"); +assert.sameValue(iso.inLeapYear(new Temporal.PlainDateTime(1994, 11, 5, 8, 15, 30)), res, "PlainDateTime"); +assert.sameValue(iso.inLeapYear(new Temporal.PlainYearMonth(1994, 11)), res, "PlainYearMonth"); assert.sameValue(iso.inLeapYear({ year: 1994, month: 11, day: 5 }), res, "property bag"); assert.sameValue(iso.inLeapYear("1994-11-05"), res, "string"); + +res = true; +assert.sameValue(iso.inLeapYear(new Temporal.PlainDate(1996, 7, 15)), res, "PlainDate in leap year"); +assert.sameValue(iso.inLeapYear(new Temporal.PlainDateTime(1996, 7, 15, 5, 30, 13)), res, "PlainDateTime in leap year"); +assert.sameValue(iso.inLeapYear(new Temporal.PlainYearMonth(1996, 7)), res, "PlainYearMonth in leap year"); +assert.sameValue(iso.inLeapYear({ year: 1996, month: 7, day: 15 }), res, "property bag in leap year"); +assert.sameValue(iso.inLeapYear("1996-07-15"), res, "string in leap year"); + assert.throws(TypeError, () => iso.inLeapYear({ year: 2000 }), "property bag with missing properties"); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/branding.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/branding.js index 8b3e5de8a2f..003cf490ab0 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/branding.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/branding.js @@ -11,12 +11,14 @@ const inLeapYear = Temporal.Calendar.prototype.inLeapYear; assert.sameValue(typeof inLeapYear, "function"); -assert.throws(TypeError, () => inLeapYear.call(undefined), "undefined"); -assert.throws(TypeError, () => inLeapYear.call(null), "null"); -assert.throws(TypeError, () => inLeapYear.call(true), "true"); -assert.throws(TypeError, () => inLeapYear.call(""), "empty string"); -assert.throws(TypeError, () => inLeapYear.call(Symbol()), "symbol"); -assert.throws(TypeError, () => inLeapYear.call(1), "1"); -assert.throws(TypeError, () => inLeapYear.call({}), "plain object"); -assert.throws(TypeError, () => inLeapYear.call(Temporal.Calendar), "Temporal.Calendar"); -assert.throws(TypeError, () => inLeapYear.call(Temporal.Calendar.prototype), "Temporal.Calendar.prototype"); +const arg = new Temporal.PlainDate(2021, 3, 4); + +assert.throws(TypeError, () => inLeapYear.call(undefined, arg), "undefined"); +assert.throws(TypeError, () => inLeapYear.call(null, arg), "null"); +assert.throws(TypeError, () => inLeapYear.call(true, arg), "true"); +assert.throws(TypeError, () => inLeapYear.call("", arg), "empty string"); +assert.throws(TypeError, () => inLeapYear.call(Symbol(), arg), "symbol"); +assert.throws(TypeError, () => inLeapYear.call(1, arg), "1"); +assert.throws(TypeError, () => inLeapYear.call({}, arg), "plain object"); +assert.throws(TypeError, () => inLeapYear.call(Temporal.Calendar, arg), "Temporal.Calendar"); +assert.throws(TypeError, () => inLeapYear.call(Temporal.Calendar.prototype, arg), "Temporal.Calendar.prototype");