From 50090b22829346badc752da85e152062e2a01056 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 19 Jul 2021 13:45:21 -0700 Subject: [PATCH 1/4] Add tests for Temporal.Calendar.p*.monthsInYear --- .../Calendar/prototype/monthsInYear/simple.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js new file mode 100644 index 00000000000..d2e517eae3d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js @@ -0,0 +1,31 @@ +// 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: Temporal.Calendar.prototype.monthsInYear will take Temporal.PlainDate, + PlainYearMonth, PlainDateTime object or ISO8601 string and return the number 12 for ISO8601 calendar. + 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. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDate(2021, 7, 15))); +assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDate(1234, 7, 15))); +assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); +assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDateTime(1234, 8, 23, 5, 30, 13))); +assert.sameValue(12, cal.monthsInYear(new Temporal.PlainYearMonth(1, 1))); +assert.sameValue(12, cal.monthsInYear(new Temporal.PlainYearMonth(9834, 12))); +assert.sameValue(12, cal.monthsInYear("3456-12-20")); +assert.sameValue(12, cal.monthsInYear("+000998-01-28")); +assert.sameValue(12, cal.monthsInYear("3456-12-20T03:04:05Z")); +assert.sameValue(12, cal.monthsInYear("+000998-01-28T03:04:05Z")); +assert.sameValue(12, cal.monthsInYear("3456-12")); +assert.sameValue(12, cal.monthsInYear("+000998-01")); From bcea556014e40dd31e071dfdc8d75da3ffcec92b Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Tue, 20 Jul 2021 01:59:41 -0700 Subject: [PATCH 2/4] Fix iso string expectation --- .../Calendar/prototype/monthsInYear/simple.js | 9 +------- .../monthsInYear/string-throw-range-error.js | 21 ++++++++++++++++++ .../Calendar/prototype/monthsInYear/string.js | 22 +++++++++++++++++++ 3 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js index d2e517eae3d..f28c9028e74 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js @@ -4,8 +4,7 @@ /*--- esid: sec-temporal.calendar.prototype.monthsinyear description: Temporal.Calendar.prototype.monthsInYear will take Temporal.PlainDate, - PlainYearMonth, PlainDateTime object or ISO8601 string and return the number 12 for ISO8601 calendar. - and return Array of the same content. + PlainYearMonth, PlainDateTime object and return the number 12 for ISO8601 calendar. info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). @@ -23,9 +22,3 @@ assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDateTime(1997, 8, 23, 5, assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDateTime(1234, 8, 23, 5, 30, 13))); assert.sameValue(12, cal.monthsInYear(new Temporal.PlainYearMonth(1, 1))); assert.sameValue(12, cal.monthsInYear(new Temporal.PlainYearMonth(9834, 12))); -assert.sameValue(12, cal.monthsInYear("3456-12-20")); -assert.sameValue(12, cal.monthsInYear("+000998-01-28")); -assert.sameValue(12, cal.monthsInYear("3456-12-20T03:04:05Z")); -assert.sameValue(12, cal.monthsInYear("+000998-01-28T03:04:05Z")); -assert.sameValue(12, cal.monthsInYear("3456-12")); -assert.sameValue(12, cal.monthsInYear("+000998-01")); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js new file mode 100644 index 00000000000..36070a6881a --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js @@ -0,0 +1,21 @@ +// 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: Temporal.Calendar.prototype.monthsInYear will throw RangeError with incorrect ISO8601 string. +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. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, () => cal.monthsInYear("2021-01"), "Invalid time value"); +assert.throws(RangeError, () => cal.monthsInYear("2019-12"), "Invalid time value"); +assert.throws(RangeError, () => cal.monthsInYear("P1Y"), "Invalid time value"); +assert.throws(RangeError, () => cal.monthsInYear("-P12Y"), "Invalid time value"); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js new file mode 100644 index 00000000000..dac64b68085 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js @@ -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.monthsinyear +description: Temporal.Calendar.prototype.monthsInYear will take ISO8601 string + and return the number 12 for ISO8601 calendar. +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. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(12, cal.monthsInYear("3456-12-20")); +assert.sameValue(12, cal.monthsInYear("+000998-01-28")); +assert.sameValue(12, cal.monthsInYear("3456-12-20T03:04:05Z")); +assert.sameValue(12, cal.monthsInYear("+000998-01-28T03:04:05Z")); From 0c7c74092c5f527c569d844cfeca4f17d9494825 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Thu, 5 Aug 2021 17:21:43 -0700 Subject: [PATCH 3/4] update tests --- .../prototype/monthsInYear/date-time.js | 18 ++++++++++++++++++ .../Calendar/prototype/monthsInYear/date.js | 18 ++++++++++++++++++ .../monthsInYear/string-throw-range-error.js | 12 ++++-------- .../Calendar/prototype/monthsInYear/string.js | 13 ++++--------- .../throw-range-error-ToTemporalDate.js | 17 +++++++++++++++++ .../throw-type-error-RequireInternalSlot.js | 15 +++++++++++++++ .../prototype/monthsInYear/year-month.js | 18 ++++++++++++++++++ 7 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/date-time.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/date.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-range-error-ToTemporalDate.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-type-error-RequireInternalSlot.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/year-month.js diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date-time.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date-time.js new file mode 100644 index 00000000000..e45fd322426 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date-time.js @@ -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: Temporal.Calendar.prototype.monthsInYear will take Temporal.PlainDateTime + object and return the number 12 for ISO8601 calendar. +info: | + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); +assert.sameValue(cal.monthsInYear(dt), 12); +dt = new Temporal.PlainDateTime(1221, 8, 23, 5, 30, 13); +assert.sameValue(cal.monthsInYear(dt), 12); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date.js new file mode 100644 index 00000000000..af4a0988fec --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date.js @@ -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: Temporal.Calendar.prototype.monthsInYear will take Temporal.PlainDate + and return the number 12 for ISO8601 calendar. +info: | + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let d = new Temporal.PlainDate(2021, 7, 15); +assert.sameValue(12, cal.monthsInYear(d), 12); +d = new Temporal.PlainDate(1234, 12, 3); +assert.sameValue(12, cal.monthsInYear(d), 12); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js index 36070a6881a..8aaa2702a8e 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js @@ -1,13 +1,9 @@ // 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: Temporal.Calendar.prototype.monthsInYear will throw RangeError with incorrect ISO8601 string. 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. Perform ? ToTemporalDate(temporalDateLike). 5. Return 12𝔽. @@ -15,7 +11,7 @@ features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.throws(RangeError, () => cal.monthsInYear("2021-01"), "Invalid time value"); -assert.throws(RangeError, () => cal.monthsInYear("2019-12"), "Invalid time value"); -assert.throws(RangeError, () => cal.monthsInYear("P1Y"), "Invalid time value"); -assert.throws(RangeError, () => cal.monthsInYear("-P12Y"), "Invalid time value"); +assert.throws(RangeError, () => cal.monthsInYear("2021-01"), "Missing day"); +assert.throws(RangeError, () => cal.monthsInYear("2019-12"), "Missing day"); +assert.throws(RangeError, () => cal.monthsInYear("P1Y"), "Duration is not acceptable"); +assert.throws(RangeError, () => cal.monthsInYear("-P12Y"), "Duration is not acceptable"); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js index dac64b68085..e4d5e9570e5 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js @@ -1,22 +1,17 @@ // 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: Temporal.Calendar.prototype.monthsInYear will take ISO8601 string and return the number 12 for ISO8601 calendar. 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. Perform ? ToTemporalDate(temporalDateLike). 5. Return 12𝔽. features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(12, cal.monthsInYear("3456-12-20")); -assert.sameValue(12, cal.monthsInYear("+000998-01-28")); -assert.sameValue(12, cal.monthsInYear("3456-12-20T03:04:05Z")); -assert.sameValue(12, cal.monthsInYear("+000998-01-28T03:04:05Z")); +assert.sameValue(cal.monthsInYear("3456-12-20"), 12); +assert.sameValue(cal.monthsInYear("+000998-01-28"), 12); +assert.sameValue(cal.monthsInYear("3456-12-20T03:04:05Z"), 12); +assert.sameValue(cal.monthsInYear("+000998-01-28T03:04:05Z"), 12); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-range-error-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-range-error-ToTemporalDate.js new file mode 100644 index 00000000000..cdad67fc7bc --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-range-error-ToTemporalDate.js @@ -0,0 +1,17 @@ +// 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: Temporal.Calendar.prototype.monthsInYear throws RangeError on + ToTemporalDate when temporalDateLike is invalid string. +info: | + 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). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, () => cal.monthsInYear("invalid string"), + "Throw RangeError if temporalDateLike is invalid"); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-type-error-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-type-error-RequireInternalSlot.js new file mode 100644 index 00000000000..ac3ce1e5f92 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-type-error-RequireInternalSlot.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.monthsinyear +description: Temporal.Calendar.prototype.monthsInYear throws TypeError on + RequireInternalSlot if object has no internal slot. +info: | + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let badCal = { monthsInYear: cal.monthsInYear } +assert.throws(TypeError, () => badCal.monthsInYear("2021-03-04"), + "Throw TypeError if there are no internal slot"); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/year-month.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/year-month.js new file mode 100644 index 00000000000..884e5e4b811 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/year-month.js @@ -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: Temporal.Calendar.prototype.monthsInYear will take + PlainYearMonth object and return the number 12 for ISO8601 calendar. +info: | + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let ym = new Temporal.PlainYearMonth(1, 1); +assert.sameValue(cal.monthsInYear(ym), 12); +ym = new Temporal.PlainYearMonth(9384, 3); +assert.sameValue(cal.monthsInYear(ym), 12); From 55e4ef670c71728833da2c9a7df251d5cb2d11e1 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Thu, 5 Aug 2021 17:23:08 -0700 Subject: [PATCH 4/4] remove simple --- .../Calendar/prototype/monthsInYear/simple.js | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js deleted file mode 100644 index f28c9028e74..00000000000 --- a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/simple.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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: Temporal.Calendar.prototype.monthsInYear will take Temporal.PlainDate, - PlainYearMonth, PlainDateTime object and return the number 12 for ISO8601 calendar. -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. Perform ? ToTemporalDate(temporalDateLike). - 5. Return 12𝔽. -features: [Temporal] ----*/ -let cal = new Temporal.Calendar("iso8601"); - -assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDate(2021, 7, 15))); -assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDate(1234, 7, 15))); -assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); -assert.sameValue(12, cal.monthsInYear(new Temporal.PlainDateTime(1234, 8, 23, 5, 30, 13))); -assert.sameValue(12, cal.monthsInYear(new Temporal.PlainYearMonth(1, 1))); -assert.sameValue(12, cal.monthsInYear(new Temporal.PlainYearMonth(9834, 12)));