add more tests

This commit is contained in:
Frank Tang 2021-08-05 15:01:19 -07:00 committed by Rick Waldron
parent d554db9438
commit a87f987e7f
10 changed files with 123 additions and 86 deletions

View File

@ -6,28 +6,16 @@ esid: sec-temporal.calendar.prototype.dayofweek
description: Temporal.Calendar.prototype.dayOfWeek will take Temporal.PlainDateTime objects
and return the day of week.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
5. Return 𝔽(! ToISODayOfWeek(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13)));
// leap year
assert.sameValue(5, cal.dayOfWeek(new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13)));
assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDateTime(2000, 2, 23, 5, 30, 13)));
// non leap year
assert.sameValue(7, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13)));
assert.sameValue(7, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13)));
assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 4, 23, 5, 30, 13)));
assert.sameValue(5, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 5, 23, 5, 30, 13)));
assert.sameValue(1, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13)));
assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 7, 23, 5, 30, 13)));
assert.sameValue(6, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assert.sameValue(2, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 9, 23, 5, 30, 13)));
assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 10, 23, 5, 30, 13)));
assert.sameValue(7, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 11, 23, 5, 30, 13)));
assert.sameValue(2, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 12, 23, 5, 30, 13)));
let dt = new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13);
assert.sameValue(4, cal.dayOfWeek(dt));
dt = new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13);
assert.sameValue(5, cal.dayOfWeek(dt));
dt = new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13);
assert.sameValue(7, cal.dayOfWeek(dt));
dt = new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13);
assert.sameValue(1, cal.dayOfWeek(dt));

View File

@ -6,31 +6,14 @@ esid: sec-temporal.calendar.prototype.dayofweek
description: Temporal.Calendar.prototype.dayOfWeek will take Temporal.PlainDate objects
and return the day of week.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
5. Return 𝔽(! ToISODayOfWeek(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDate(1970, 1, 1)));
assert.sameValue(6, cal.dayOfWeek(new Temporal.PlainDate(2000, 1, 1)));
assert.sameValue(5, cal.dayOfWeek(new Temporal.PlainDate(2021, 1, 15)));
// leap year
assert.sameValue(6, cal.dayOfWeek(new Temporal.PlainDate(2020, 2, 15)));
assert.sameValue(2, cal.dayOfWeek(new Temporal.PlainDate(2000, 2, 15)));
// non-leap year
assert.sameValue(1, cal.dayOfWeek(new Temporal.PlainDate(2021, 2, 15)));
assert.sameValue(1, cal.dayOfWeek(new Temporal.PlainDate(2021, 3, 15)));
assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDate(2021, 4, 15)));
assert.sameValue(6, cal.dayOfWeek(new Temporal.PlainDate(2021, 5, 15)));
assert.sameValue(2, cal.dayOfWeek(new Temporal.PlainDate(2021, 6, 15)));
assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDate(2021, 7, 15)));
assert.sameValue(7, cal.dayOfWeek(new Temporal.PlainDate(2021, 8, 15)));
assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDate(2021, 9, 15)));
assert.sameValue(5, cal.dayOfWeek(new Temporal.PlainDate(2021, 10, 15)));
assert.sameValue(1, cal.dayOfWeek(new Temporal.PlainDate(2021, 11, 15)));
assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDate(2021, 12, 15)));
let d = new Temporal.PlainDate(1970, 1, 1);
assert.sameValue(4, cal.dayOfWeek(d));
d = new Temporal.PlainDate(2021, 2, 15);
assert.sameValue(1, cal.dayOfWeek(d));
d = new Temporal.PlainDate(2021, 8, 15);
assert.sameValue(7, cal.dayOfWeek(d));

View File

@ -6,9 +6,6 @@ esid: sec-temporal.calendar.prototype.dayofweek
description: Temporal.Calendar.prototype.dayOfWeek will take ISO8601 string
and return the day of week.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
5. Return 𝔽(! ToISODayOfWeek(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
@ -16,17 +13,6 @@ features: [Temporal]
let cal = new Temporal.Calendar("iso8601");
assert.sameValue(5, cal.dayOfWeek("2019-01-18"));
// leap year
assert.sameValue(2, cal.dayOfWeek("2020-02-18"));
// non leap
assert.sameValue(1, cal.dayOfWeek("2019-02-18"));
assert.sameValue(1, cal.dayOfWeek("2019-03-18"));
assert.sameValue(4, cal.dayOfWeek("2019-04-18"));
assert.sameValue(6, cal.dayOfWeek("2019-05-18"));
assert.sameValue(2, cal.dayOfWeek("2019-06-18"));
assert.sameValue(4, cal.dayOfWeek("2019-07-18"));
assert.sameValue(7, cal.dayOfWeek("2019-08-18"));
assert.sameValue(3, cal.dayOfWeek("2019-09-18"));
assert.sameValue(5, cal.dayOfWeek("2019-10-18"));
assert.sameValue(1, cal.dayOfWeek("2019-11-18"));
assert.sameValue(3, cal.dayOfWeek("2019-12-18"));

View File

@ -0,0 +1,15 @@
// 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.dayOfWeek
description: Temporal.Calendar.prototype.dayOfWeek throws RangeError on
ToTemporalDate when temporalDateLike is invalid string.
info: |
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => cal.dayOfWeek("invalid string"),
"Throw RangeError if temporalDateLike is invalid");

View File

@ -0,0 +1,16 @@
// 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.dayOfWeek
description: Temporal.Calendar.prototype.dayOfWeek throws TypeError
when the internal lot is not presented.
info: |
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
let badCal = { dayOfWeek: cal.dayOfWeek }
assert.throws(TypeError, () => badCal.dayOfWeek("2021-03-04"),
"Throw TypeError if no internal slot");

View File

@ -4,20 +4,29 @@
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: Temporal.Calendar.prototype.dayOfYear will take PlainDateTime object and
return the day of year.
return the day of 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. Let temporalDate be ? ToTemporalDate(temporalDateLike).
5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.sameValue(23, cal.dayOfYear(new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13)));
assert.sameValue(54, cal.dayOfYear(new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13)));
assert.sameValue(83, cal.dayOfYear(new Temporal.PlainDateTime(1996, 3, 23, 5, 30, 13)));
assert.sameValue(82, cal.dayOfYear(new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13)));
assert.sameValue(365, cal.dayOfYear(new Temporal.PlainDateTime(1997, 12, 31, 5, 30, 13)));
assert.sameValue(366, cal.dayOfYear(new Temporal.PlainDateTime(1996, 12, 31, 5, 30, 13)));
let dt = new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13);
assert.sameValue(23, cal.dayOfYear(dt));
dt = new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13);
assert.sameValue(54, cal.dayOfYear(dt));
dt = new Temporal.PlainDateTime(1996, 3, 23, 5, 30, 13);
assert.sameValue(83, cal.dayOfYear(dt));
dt = new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13);
assert.sameValue(82, cal.dayOfYear(dt));
dt = new Temporal.PlainDateTime(1997, 12, 31, 5, 30, 13);
assert.sameValue(365, cal.dayOfYear(dt));
dt = new Temporal.PlainDateTime(1996, 12, 31, 5, 30, 13);
assert.sameValue(366, cal.dayOfYear(dt));

View File

@ -4,25 +4,36 @@
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: Temporal.Calendar.prototype.dayOfYear will take PlainDate object and
return the day of year.
return the day of 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. Let temporalDate be ? ToTemporalDate(temporalDateLike).
5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.sameValue(1, cal.dayOfYear(new Temporal.PlainDate(1970, 1, 1)));
assert.sameValue(1, cal.dayOfYear(new Temporal.PlainDate(2000, 1, 1)));
let d = new Temporal.PlainDate(1970, 1, 1);
assert.sameValue(1, cal.dayOfYear(d));
d = new Temporal.PlainDate(2000, 1, 1);
assert.sameValue(1, cal.dayOfYear(d));
assert.sameValue(15, cal.dayOfYear(new Temporal.PlainDate(2021, 1, 15)));
assert.sameValue(46, cal.dayOfYear(new Temporal.PlainDate(2020, 2, 15)));
assert.sameValue(46, cal.dayOfYear(new Temporal.PlainDate(2000, 2, 15)));
assert.sameValue(75, cal.dayOfYear(new Temporal.PlainDate(2020, 3, 15)));
assert.sameValue(75, cal.dayOfYear(new Temporal.PlainDate(2000, 3, 15)));
assert.sameValue(74, cal.dayOfYear(new Temporal.PlainDate(2001, 3, 15)));
assert.sameValue(366, cal.dayOfYear(new Temporal.PlainDate(2000, 12, 31)));
assert.sameValue(365, cal.dayOfYear(new Temporal.PlainDate(2001, 12, 31)));
d = new Temporal.PlainDate(2021, 1, 15);
assert.sameValue(15, cal.dayOfYear(d));
d = new Temporal.PlainDate(2020, 2, 15);
assert.sameValue(46, cal.dayOfYear(d));
d = new Temporal.PlainDate(2020, 3, 15);
assert.sameValue(75, cal.dayOfYear(d));
d = new Temporal.PlainDate(2000, 3, 15);
assert.sameValue(75, cal.dayOfYear(d));
d = new Temporal.PlainDate(2001, 3, 15);
assert.sameValue(74, cal.dayOfYear(d));
d = new Temporal.PlainDate(2000, 12, 31);
assert.sameValue(366, cal.dayOfYear(d));
d = new Temporal.PlainDate(2001, 12, 31);
assert.sameValue(365, cal.dayOfYear(d));

View File

@ -4,11 +4,9 @@
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: Temporal.Calendar.prototype.dayOfYear will take ISO8601 string and
return the day of year.
return the day of 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. Let temporalDate be ? ToTemporalDate(temporalDateLike).
5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]

View File

@ -0,0 +1,15 @@
// 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.dayOfYear
description: Temporal.Calendar.prototype.dayOfYear throws RangeError on
ToTemporalDate when temporalDateLike is invalid string.
info: |
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => cal.dayOfYear("invalid string"),
"Throw RangeError if temporalDateLike is invalid");

View File

@ -0,0 +1,16 @@
// 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.dayOfYear
description: Temporal.Calendar.prototype.dayOfYear throws TypeError
when the internal lot is not presented.
info: |
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
let badCal = { dayOfYear: cal.dayOfYear }
assert.throws(TypeError, () => badCal.dayOfYear("2021-03-04"),
"Throw TypeError if no internal slot");