-
Notifications
You must be signed in to change notification settings - Fork 472
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.p*.inLeapYear #3056
Changes from 1 commit
13a6fe7
cafc0e4
c3651b8
3a65001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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: Temporal.Calendar.prototype.inLeapYear will take Temporal.PlainDateTime object | ||
and return true or false that year is leap year. | ||
and return Array of the same content. | ||
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 ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). | ||
features: [Temporal] | ||
---*/ | ||
let cal = new Temporal.Calendar("iso8601"); | ||
|
||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13))); | ||
assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13))); | ||
assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13))); | ||
assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13))); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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: Temporal.Calendar.prototype.inLeapYear will take Temporal.PlainDate object | ||
and return true or false that year is leap year. | ||
and return Array of the same content. | ||
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 ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). | ||
features: [Temporal] | ||
---*/ | ||
let cal = new Temporal.Calendar("iso8601"); | ||
|
||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1995, 7, 15))); | ||
assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDate(1996, 7, 15))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1997, 7, 15))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1998, 7, 15))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1999, 7, 15))); | ||
assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDate(2000, 7, 15))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2001, 7, 15))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2002, 7, 15))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2003, 7, 15))); | ||
assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDate(2004, 7, 15))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2005, 7, 15))); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// 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: Temporal.Calendar.prototype.inLeapYear will take an ISO8601 string | ||
and return true or false that year is leap year. | ||
and return Array of the same content. | ||
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 ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). | ||
features: [Temporal] | ||
---*/ | ||
let cal = new Temporal.Calendar("iso8601"); | ||
|
||
assert.sameValue(false, cal.inLeapYear("2019-03-18")); | ||
assert.sameValue(true, cal.inLeapYear("2020-03-18")); | ||
assert.sameValue(false, cal.inLeapYear("2021-03-18")); | ||
assert.sameValue(false, cal.inLeapYear("2022-03-18")); | ||
assert.sameValue(false, cal.inLeapYear("2023-03-18")); | ||
assert.sameValue(true, cal.inLeapYear("2024-03-18")); | ||
assert.sameValue(false, cal.inLeapYear("2025-03-18")); | ||
assert.sameValue(false, cal.inLeapYear("2026-03-18")); | ||
|
||
assert.sameValue(false, cal.inLeapYear("2019-03-18T13:00:00Z")); | ||
assert.sameValue(true, cal.inLeapYear("2020-12-31T23:59:59Z")); | ||
assert.sameValue(false, cal.inLeapYear("2021-03-18T13:00:00Z")); | ||
assert.sameValue(false, cal.inLeapYear("2022-03-18T13:00:00Z")); | ||
assert.sameValue(false, cal.inLeapYear("2023-03-18T13:00:00Z")); | ||
assert.sameValue(true, cal.inLeapYear("2024-03-18T13:00:00Z")); | ||
assert.sameValue(false, cal.inLeapYear("2025-01-01T00:00:00Z")); | ||
assert.sameValue(false, cal.inLeapYear("2026-03-18T13:00:00Z")); | ||
|
||
assert.sameValue(false, cal.inLeapYear("2019-03")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block isn't correct - these strings will fail ToTemporalDate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hum... interesting... so cal.inLeapYear will take PlainYearMonth but not year-month string.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PTAL |
||
assert.sameValue(true, cal.inLeapYear("2020-03")); | ||
assert.sameValue(false, cal.inLeapYear("2021-03")); | ||
assert.sameValue(false, cal.inLeapYear("2022-03")); | ||
assert.sameValue(false, cal.inLeapYear("2023-03")); | ||
assert.sameValue(true, cal.inLeapYear("2024-03")); | ||
assert.sameValue(false, cal.inLeapYear("2025-03")); | ||
assert.sameValue(false, cal.inLeapYear("2026-03")); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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: Temporal.Calendar.prototype.inLeapYear will take Temporal.PlainYearMonth object | ||
and return true or false that year is leap year. | ||
and return Array of the same content. | ||
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 ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). | ||
features: [Temporal] | ||
---*/ | ||
let cal = new Temporal.Calendar("iso8601"); | ||
|
||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1995, 7))); | ||
assert.sameValue(true, cal.inLeapYear(new Temporal.PlainYearMonth(1996, 2))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1997, 1))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1998, 7))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1999, 7))); | ||
assert.sameValue(true, cal.inLeapYear(new Temporal.PlainYearMonth(2000, 12))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2001, 3))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2002, 7))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2003, 12))); | ||
assert.sameValue(true, cal.inLeapYear(new Temporal.PlainYearMonth(2004, 7))); | ||
assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2005, 1))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these tests are only touching the surface of inLeapYear and there is so much that could be done with the date validations. One thing that is interesting is verifying some edgy variations of the year, like years that are not the common 4 digit (0, 1, or "0000", "0001" for parsed strings), etc.
There is also so many different types accepted as argument. This should include things such as a
new Date
, a regular object, with valid and invalid (true and false returns), and abrupt completions (toPrimitive operations, symbols), and just weird args such as an integer, undefined, null, etc.This would help guarantee the cross compatibility and avoid surprises.