diff --git a/test/built-ins/Temporal/PlainYearMonth/basic.js b/test/built-ins/Temporal/PlainYearMonth/basic.js new file mode 100644 index 0000000000..e7fcbe6c23 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/basic.js @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth +description: PlainYearMonth constructor works +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const ym = new Temporal.PlainYearMonth(1976, 11); +assert.sameValue(typeof ym, "object"); +TemporalHelpers.assertPlainYearMonth(ym, 1976, 11, "M11"); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js new file mode 100644 index 0000000000..90a720fac0 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js @@ -0,0 +1,17 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: A number argument is stringified +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const plainYearMonth = Temporal.PlainYearMonth.from(201906); +TemporalHelpers.assertPlainYearMonth(plainYearMonth, 2019, 6, "M06"); +const fields = plainYearMonth.getISOFields(); +assert.sameValue(fields.calendar.id, "iso8601"); +assert.sameValue(fields.isoDay, 1, "isoDay"); +assert.sameValue(fields.isoMonth, 6, "isoMonth"); +assert.sameValue(fields.isoYear, 2019, "isoYear"); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-object.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-object.js new file mode 100644 index 0000000000..0def1d9ffb --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-object.js @@ -0,0 +1,47 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: An object argument +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from({ year: 2019, monthCode: "M11" }), + 2019, 11, "M11", "Only monthCode"); +TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from({ year: 2019, month: 11 }), + 2019, 11, "M11", "Only month"); +assert.throws(RangeError, + () => Temporal.PlainYearMonth.from({ year: 2019, month: 11, monthCode: "M12" }), + "Mismatch between month and monthCode"); + +const monthDayItem = { year: 2019, month: 11, get day() { throw new Test262Error("should not read the day property") } }; +TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from(monthDayItem), + 2019, 11, "M11", "month with day"); + +const monthCodeDayItem = { year: 2019, monthCode: "M11", get day() { throw new Test262Error("should not read the day property") } }; +TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from(monthCodeDayItem), + 2019, 11, "M11", "monthCode with day"); + +assert.throws(TypeError, + () => Temporal.PlainYearMonth.from({}), + "No properties"); +assert.throws(TypeError, + () => Temporal.PlainYearMonth.from({ year: 2019 }), + "Only year"); +assert.throws(TypeError, + () => Temporal.PlainYearMonth.from({ year: 2019, months: 6 }), + "Year and plural 'months'"); +assert.throws(TypeError, + () => Temporal.PlainYearMonth.from({ month: 6 }), + "Only month"); +assert.throws(TypeError, + () => Temporal.PlainYearMonth.from({ monthCode: "M06" }), + "Only monthCode"); +assert.throws(TypeError, + () => Temporal.PlainYearMonth.from({ year: undefined, month: 6 }), + "year explicit undefined"); + +TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from({ year: 1976, month: 11, months: 12 }), + 1976, 11, "M11", "Plural property ignored"); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-plaindate.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-plaindate.js new file mode 100644 index 0000000000..e423a148e8 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-plaindate.js @@ -0,0 +1,18 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: A PlainYearMonth argument is cloned +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const plainDate = Temporal.PlainDate.from("1976-11-18"); +const plainYearMonth = Temporal.PlainYearMonth.from(plainDate); +TemporalHelpers.assertPlainYearMonth(plainYearMonth, 1976, 11, "M11"); +const fields = plainYearMonth.getISOFields(); +assert.sameValue(fields.calendar.id, "iso8601"); +assert.sameValue(fields.isoDay, 1, "isoDay"); +assert.sameValue(fields.isoMonth, 11, "isoMonth"); +assert.sameValue(fields.isoYear, 1976, "isoYear"); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-plainyearmonth.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-plainyearmonth.js new file mode 100644 index 0000000000..a66b605c01 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-plainyearmonth.js @@ -0,0 +1,22 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: A PlainYearMonth argument is cloned +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const original = new Temporal.PlainYearMonth(2019, 11, undefined, 7); +const result = Temporal.PlainYearMonth.from(original); +assert.notSameValue(result, original); + +for (const plainYearMonth of [original, result]) { + TemporalHelpers.assertPlainYearMonth(plainYearMonth, 2019, 11, "M11"); + const fields = plainYearMonth.getISOFields(); + assert.sameValue(fields.calendar.id, "iso8601"); + assert.sameValue(fields.isoDay, 7, "isoDay"); + assert.sameValue(fields.isoMonth, 11, "isoMonth"); + assert.sameValue(fields.isoYear, 2019, "isoYear"); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-string-invalid.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-string-invalid.js new file mode 100644 index 0000000000..e99fd4efe5 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-string-invalid.js @@ -0,0 +1,11 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: An invalid ISO string is never supported +features: [Temporal] +---*/ + +assert.throws(RangeError, () => Temporal.PlainYearMonth.from("2020-13", { overflow: "reject" })); +assert.throws(RangeError, () => Temporal.PlainYearMonth.from("2020-13", { overflow: "constrain" })); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-string-trailing-junk.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-string-trailing-junk.js new file mode 100644 index 0000000000..b5c44677e1 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-string-trailing-junk.js @@ -0,0 +1,10 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: RangeError thrown if a string with trailing junk is used as a PlainYearMonth +features: [Temporal] +---*/ + +assert.throws(RangeError, () => Temporal.PlainYearMonth.from("1976-11junk")); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-string.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-string.js index b3a4885726..01a841c61e 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/argument-string.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-string.js @@ -8,10 +8,48 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const plainYearMonth = Temporal.PlainYearMonth.from("1970-12"); -TemporalHelpers.assertPlainYearMonth(plainYearMonth, 1970, 12, "M12"); +const inputs = [ + "1976-11", + "1976-11-10", + "1976-11-01T09:00:00+00:00", + "1976-11-01T00:00:00+05:00", + "197611", + "+00197611", + "1976-11-18T15:23:30.1\u221202:00", + "1976-11-18T152330.1+00:00", + "19761118T15:23:30.1+00:00", + "1976-11-18T15:23:30.1+0000", + "1976-11-18T152330.1+0000", + "19761118T15:23:30.1+0000", + "19761118T152330.1+00:00", + "19761118T152330.1+0000", + "+001976-11-18T152330.1+00:00", + "+0019761118T15:23:30.1+00:00", + "+001976-11-18T15:23:30.1+0000", + "+001976-11-18T152330.1+0000", + "+0019761118T15:23:30.1+0000", + "+0019761118T152330.1+00:00", + "+0019761118T152330.1+0000", + "1976-11-18T15:23", + "1976-11-18T15", + "1976-11-18", +]; + +for (const input of inputs) { + const plainYearMonth = Temporal.PlainYearMonth.from(input); + TemporalHelpers.assertPlainYearMonth(plainYearMonth, 1976, 11, "M11"); + const fields = plainYearMonth.getISOFields(); + assert.sameValue(fields.calendar.id, "iso8601"); + assert.sameValue(fields.isoDay, 1, "isoDay"); + assert.sameValue(fields.isoMonth, 11, "isoMonth"); + assert.sameValue(fields.isoYear, 1976, "isoYear"); +} + +const plainYearMonth = Temporal.PlainYearMonth.from("\u2212009999-11"); +TemporalHelpers.assertPlainYearMonth(plainYearMonth, -9999, 11, "M11"); const fields = plainYearMonth.getISOFields(); assert.sameValue(fields.calendar.id, "iso8601"); assert.sameValue(fields.isoDay, 1, "isoDay"); -assert.sameValue(fields.isoMonth, 12, "isoMonth"); -assert.sameValue(fields.isoYear, 1970, "isoYear"); +assert.sameValue(fields.isoMonth, 11, "isoMonth"); +assert.sameValue(fields.isoYear, -9999, "isoYear"); +assert.sameValue(plainYearMonth.toString(), "-009999-11"); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/options-invalid.js b/test/built-ins/Temporal/PlainYearMonth/from/options-invalid.js new file mode 100644 index 0000000000..6319d3343b --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/options-invalid.js @@ -0,0 +1,21 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: TypeError thrown when a primitive is passed as the options argument +features: [Temporal] +---*/ + +const items = [ + { year: 2000, month: 11 }, + "2000-11", + new Temporal.PlainYearMonth(2000, 11), +]; +const values = [null, true, "hello", Symbol("foo"), 1, 1n]; + +for (const item of items) { + for (const badOptions of values) { + assert.throws(TypeError, () => Temporal.PlainYearMonth.from(item, badOptions)); + } +} diff --git a/test/built-ins/Temporal/PlainYearMonth/from/overflow-constrain.js b/test/built-ins/Temporal/PlainYearMonth/from/overflow-constrain.js new file mode 100644 index 0000000000..c1cacdf619 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/overflow-constrain.js @@ -0,0 +1,14 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: Reject value for overflow option +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const propertyBag = { year: 2000, month: 13 }; +const plainYearMonth = Temporal.PlainYearMonth.from(propertyBag, { overflow: "constrain" }); +TemporalHelpers.assertPlainYearMonth(plainYearMonth, 2000, 12, "M12", "default overflow is constrain"); + diff --git a/test/built-ins/Temporal/PlainYearMonth/from/overflow-invalid-string.js b/test/built-ins/Temporal/PlainYearMonth/from/overflow-invalid-string.js index b0e4fb0931..3d5a3d8057 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/overflow-invalid-string.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/overflow-invalid-string.js @@ -28,5 +28,7 @@ const validValues = [ "2000-05", ]; validValues.forEach((value) => { - assert.throws(RangeError, () => Temporal.PlainYearMonth.from(value, { overflow: "other string" })); + ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", 3, null].forEach((overflow) => { + assert.throws(RangeError, () => Temporal.PlainYearMonth.from(value, { overflow })); + }); }); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/overflow-reject.js b/test/built-ins/Temporal/PlainYearMonth/from/overflow-reject.js new file mode 100644 index 0000000000..86e4151cd5 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/overflow-reject.js @@ -0,0 +1,11 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: Reject value for overflow option +features: [Temporal] +---*/ + +const bad = { year: 2019, month: 13 }; +assert.throws(RangeError, () => Temporal.PlainYearMonth.from(bad, { overflow: "reject" })); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/overflow-undefined.js b/test/built-ins/Temporal/PlainYearMonth/from/overflow-undefined.js index 1d906e3c27..c085b384b6 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/overflow-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/overflow-undefined.js @@ -32,6 +32,8 @@ validValues.forEach((value) => { TemporalHelpers.assertPlainYearMonth(explicit, 2000, 5, "M05", "overflow is ignored"); const implicit = Temporal.PlainYearMonth.from(value, {}); TemporalHelpers.assertPlainYearMonth(implicit, 2000, 5, "M05", "overflow is ignored"); + const lambda = Temporal.PlainYearMonth.from(value, () => {}); + TemporalHelpers.assertPlainYearMonth(lambda, 2000, 5, "M05", "overflow is ignored"); }); const propertyBag = { year: 2000, month: 13 }; @@ -39,3 +41,5 @@ const explicit = Temporal.PlainYearMonth.from(propertyBag, { overflow: undefined TemporalHelpers.assertPlainYearMonth(explicit, 2000, 12, "M12", "default overflow is constrain"); const implicit = Temporal.PlainYearMonth.from(propertyBag, {}); TemporalHelpers.assertPlainYearMonth(implicit, 2000, 12, "M12", "default overflow is constrain"); +const lambda = Temporal.PlainYearMonth.from(propertyBag, () => {}); +TemporalHelpers.assertPlainYearMonth(lambda, 2000, 12, "M12", "default overflow is constrain"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/daysInMonth/basic.js b/test/built-ins/Temporal/PlainYearMonth/prototype/daysInMonth/basic.js new file mode 100644 index 0000000000..94883e5868 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/daysInMonth/basic.js @@ -0,0 +1,11 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.plainyearmonth.prototype.daysinmonth +description: daysInMonth works +features: [Temporal] +---*/ + +const ym = new Temporal.PlainYearMonth(1976, 11); +assert.sameValue(ym.daysInMonth, 30); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/daysInYear/basic.js b/test/built-ins/Temporal/PlainYearMonth/prototype/daysInYear/basic.js new file mode 100644 index 0000000000..f17cde06c5 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/daysInYear/basic.js @@ -0,0 +1,11 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.plainyearmonth.prototype.daysinyear +description: daysInYear works +features: [Temporal] +---*/ + +const ym = new Temporal.PlainYearMonth(1976, 11); +assert.sameValue(ym.daysInYear, 366); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/monthsInYear/basic.js b/test/built-ins/Temporal/PlainYearMonth/prototype/monthsInYear/basic.js new file mode 100644 index 0000000000..8a2bfbc71e --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/monthsInYear/basic.js @@ -0,0 +1,11 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.plainyearmonth.prototype.monthsinyear +description: monthsInYear works +features: [Temporal] +---*/ + +const ym = new Temporal.PlainYearMonth(1976, 11); +assert.sameValue(ym.monthsInYear, 12); diff --git a/test/intl402/Temporal/PlainYearMonth/from/argument-object.js b/test/intl402/Temporal/PlainYearMonth/from/argument-object.js new file mode 100644 index 0000000000..5e0bd6f11b --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/from/argument-object.js @@ -0,0 +1,17 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: An object argument +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const monthDayItem = { calendar: "gregory", era: "ce", eraYear: 2019, month: 11, get day() { throw new Test262Error("should not read the day property") } }; +TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from(monthDayItem), + 2019, 11, "M11", "month with day", "ce", 2019); + +const monthCodeDayItem = { calendar: "gregory", era: "ce", eraYear: 2019, monthCode: "M11", get day() { throw new Test262Error("should not read the day property") } }; +TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from(monthCodeDayItem), + 2019, 11, "M11", "monthCode with day", "ce", 2019);