From a87f987e7f3b7d2679b41a56122e09276ce6af79 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Thu, 5 Aug 2021 15:01:19 -0700 Subject: [PATCH] add more tests --- .../prototype/dayOfWeek/plain-date-time.js | 28 ++++--------- .../prototype/dayOfWeek/plain-date.js | 29 +++---------- .../Calendar/prototype/dayOfWeek/string.js | 14 ------- .../throw-range-error-ToTemporalDate.js | 15 +++++++ .../throw-type-error-RequireInternalSlot.js | 16 ++++++++ .../prototype/dayOfYear/plain-date-time.js | 29 ++++++++----- .../prototype/dayOfYear/plain-date.js | 41 ++++++++++++------- .../Calendar/prototype/dayOfYear/string.js | 6 +-- .../throw-range-error-ToTemporalDate.js | 15 +++++++ .../throw-type-error-RequireInternalSlot.js | 16 ++++++++ 10 files changed, 123 insertions(+), 86 deletions(-) create mode 100644 test/built-ins/Temporal/Calendar/prototype/dayOfWeek/throw-range-error-ToTemporalDate.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dayOfWeek/throw-type-error-RequireInternalSlot.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dayOfYear/throw-range-error-ToTemporalDate.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dayOfYear/throw-type-error-RequireInternalSlot.js diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date-time.js index 38c27e827f..0fc49779a9 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date-time.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date-time.js @@ -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)); diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date.js index c94b757a6d..e63deb2955 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date.js @@ -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)); diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/string.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/string.js index 55353170d2..57652820d0 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/string.js @@ -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")); diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/throw-range-error-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/throw-range-error-ToTemporalDate.js new file mode 100644 index 0000000000..d390dd7d76 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/throw-range-error-ToTemporalDate.js @@ -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"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/throw-type-error-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/throw-type-error-RequireInternalSlot.js new file mode 100644 index 0000000000..3b0fc41f7d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/throw-type-error-RequireInternalSlot.js @@ -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"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date-time.js index 892085feb1..a811ba1e4e 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date-time.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date-time.js @@ -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)); diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date.js index 137d2ccb5a..51067063d5 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date.js @@ -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)); diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/string.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/string.js index e7276cc0f4..fac42af7e6 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/string.js @@ -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] diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/throw-range-error-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/throw-range-error-ToTemporalDate.js new file mode 100644 index 0000000000..ac8b2a9006 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/throw-range-error-ToTemporalDate.js @@ -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"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/throw-type-error-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/throw-type-error-RequireInternalSlot.js new file mode 100644 index 0000000000..9371310151 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/throw-type-error-RequireInternalSlot.js @@ -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");