Skip to content

Commit

Permalink
Add tests for Temporal.Calendar.p*.monthsInYear
Browse files Browse the repository at this point in the history
(Philip, March 2022: This was originally Frank's PR tc39#3059. I did some
reformatting, removed duplicate tests, and combined with some existing
tests.)
  • Loading branch information
FrankYFTang authored and jessealama committed Apr 13, 2022
1 parent 48c1c9e commit c3cc1c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.monthsinyear
description: An ISO 8601 date string should be converted as input
info: |
a. Perform ? ToTemporalDate(temporalDateLike).
5. Return 12𝔽.
features: [Temporal]
---*/

let cal = new Temporal.Calendar("iso8601");

assert.sameValue(cal.monthsInYear("3456-12-20"), 12);
assert.sameValue(cal.monthsInYear("+000998-01-28"), 12);
assert.sameValue(cal.monthsInYear("3456-12-20T03:04:05+00:00[UTC]"), 12);
assert.sameValue(cal.monthsInYear("+000998-01-28T03:04:05+00:00[UTC]"), 12);
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ features: [Temporal]

const iso = Temporal.Calendar.from("iso8601");
const res = 12;
assert.sameValue(iso.monthsInYear(Temporal.PlainDate.from("1994-11-05")), res, "PlainDate");
assert.sameValue(iso.monthsInYear(Temporal.PlainDateTime.from("1994-11-05T08:15:30")), res, "PlainDateTime");
assert.sameValue(iso.monthsInYear(Temporal.PlainYearMonth.from("1994-11")), res, "PlainYearMonth");
assert.sameValue(iso.monthsInYear(new Temporal.PlainDate(1994, 11, 5)), res, "PlainDate");
assert.sameValue(iso.monthsInYear(new Temporal.PlainDateTime(1994, 11, 5, 8, 15, 30)), res, "PlainDateTime");
assert.sameValue(iso.monthsInYear(new Temporal.PlainYearMonth(1994, 11)), res, "PlainYearMonth");
assert.sameValue(iso.monthsInYear({ year: 1994, month: 11, day: 5 }), res, "property bag");
assert.sameValue(iso.monthsInYear("1994-11-05"), res, "string");
assert.throws(TypeError, () => iso.monthsInYear({ year: 2000 }), "property bag with missing properties");
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ const monthsInYear = Temporal.Calendar.prototype.monthsInYear;

assert.sameValue(typeof monthsInYear, "function");

assert.throws(TypeError, () => monthsInYear.call(undefined), "undefined");
assert.throws(TypeError, () => monthsInYear.call(null), "null");
assert.throws(TypeError, () => monthsInYear.call(true), "true");
assert.throws(TypeError, () => monthsInYear.call(""), "empty string");
assert.throws(TypeError, () => monthsInYear.call(Symbol()), "symbol");
assert.throws(TypeError, () => monthsInYear.call(1), "1");
assert.throws(TypeError, () => monthsInYear.call({}), "plain object");
assert.throws(TypeError, () => monthsInYear.call(Temporal.Calendar), "Temporal.Calendar");
assert.throws(TypeError, () => monthsInYear.call(Temporal.Calendar.prototype), "Temporal.Calendar.prototype");
const arg = new Temporal.PlainDate(2021, 3, 4);

assert.throws(TypeError, () => monthsInYear.call(undefined, arg), "undefined");
assert.throws(TypeError, () => monthsInYear.call(null, arg), "null");
assert.throws(TypeError, () => monthsInYear.call(true, arg), "true");
assert.throws(TypeError, () => monthsInYear.call("", arg), "empty string");
assert.throws(TypeError, () => monthsInYear.call(Symbol(), arg), "symbol");
assert.throws(TypeError, () => monthsInYear.call(1, arg), "1");
assert.throws(TypeError, () => monthsInYear.call({}, arg), "plain object");
assert.throws(TypeError, () => monthsInYear.call(Temporal.Calendar, arg), "Temporal.Calendar");
assert.throws(TypeError, () => monthsInYear.call(Temporal.Calendar.prototype, arg), "Temporal.Calendar.prototype");

0 comments on commit c3cc1c8

Please sign in to comment.