Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Temporal.Calendar.prototype.(year|month*|day) #3050

Merged
merged 5 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/day/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.day
description: Temporal.Calendar.prototype.day will take different kind of objects.
and return the value of the day.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalMonthDay]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
5. Return ! ISODay(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

assert.sameValue(15, cal.day(new Temporal.PlainDate(2021, 7, 15)));
assert.sameValue(23, cal.day(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assert.sameValue(6, cal.day(new Temporal.PlainMonthDay(2, 6)));
assert.sameValue(18, cal.day("2019-03-18"));
23 changes: 23 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/month-code/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.monthcode
description: Temporal.Calendar.prototype.monthCode will take different kind of object and return
the value of the monthCode.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalMonthDay]], or [[InitializedTemporalYearMonth]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
5. Return ! ISOMonthCode(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

assert.sameValue("M07", cal.monthCode(new Temporal.PlainDate(2021, 7, 15)));
assert.sameValue("M08", cal.monthCode(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assert.sameValue("M06", cal.monthCode(new Temporal.PlainYearMonth(1999, 6)));
assert.sameValue("M02", cal.monthCode(new Temporal.PlainMonthDay(2, 6)));
assert.sameValue("M03", cal.monthCode("2019-03-15"));
24 changes: 24 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/month/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.month
description: Temporal.Calendar.prototype.month will take different kind of object and
return month value.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(temporalDateLike) is Object and temporalDateLike has an [[InitializedTemporalMonthDay]] internal slot, then
a. Throw a TypeError exception.
5. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
6. Return ! ISOMonth(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

assert.sameValue(7, cal.month(new Temporal.PlainDate(2021, 7, 15)));
assert.sameValue(8, cal.month(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assert.sameValue(6, cal.month(new Temporal.PlainYearMonth(1999, 6)));
assert.sameValue(3, cal.month("2019-03-15"));
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.month
description: Temporal.Calendar.prototype.month will throws TypeError while the input object
has an [[InitializedTemporalMonthDay]] internal slot.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(temporalDateLike) is Object and temporalDateLike has an [[InitializedTemporalMonthDay]] internal slot, then
a. Throw a TypeError exception.
5. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
6. Return ! ISOMonth(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

assert.throws(TypeError, () => cal.month(new Temporal.PlainMonthDay(3, 16)),
"invalid_argument");
22 changes: 22 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/year/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.year
description: Temporal.Calendar.prototype.year will take different kind of object and return
the value of the year.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
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 ! ISOYear(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

assert.sameValue(2021, cal.year(new Temporal.PlainDate(2021, 7, 15)));
assert.sameValue(1997, cal.year(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assert.sameValue(1999, cal.year(new Temporal.PlainYearMonth(1999, 6)));
assert.sameValue(2019, cal.year("2019-03-15"));