Skip to content

Commit

Permalink
Add tests for Temporal.Calendar.p*.inLeapYear
Browse files Browse the repository at this point in the history
(Philip, March 2022: This was originally Frank's PR tc39#3056. I did some
reformatting, removed duplicate tests, and combined with some existing
tests.)
  • Loading branch information
FrankYFTang authored and rwaldron committed Apr 4, 2022
1 parent 16aefcc commit cdcf2a3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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);
17 changes: 13 additions & 4 deletions test/built-ins/Temporal/Calendar/prototype/inLeapYear/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
20 changes: 11 additions & 9 deletions test/built-ins/Temporal/Calendar/prototype/inLeapYear/branding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

0 comments on commit cdcf2a3

Please sign in to comment.