From f98a00bc69109a30b7fad8e03d79824d42c5b87c Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 3 Feb 2022 18:01:01 +0100 Subject: [PATCH] Port tests for PlainYearMonth#{since,until}. --- ...guments-casting.js => argument-casting.js} | 0 .../prototype/since/largestunit-undefined.js | 5 ++++ .../since/roundingincrement-as-expected.js | 15 ++++++----- .../prototype/since/roundingmode-ceil.js | 26 +++++++++++++++++++ .../prototype/since/roundingmode-floor.js | 26 +++++++++++++++++++ .../since/roundingmode-halfExpand.js | 26 +++++++++++++++++++ .../prototype/since/roundingmode-trunc.js | 26 +++++++++++++++++++ .../prototype/until/argument-casting.js | 16 ++++++++++++ .../until/arguments-missing-throws.js | 13 ++++++++++ .../until/largestunit-disallowed-units.js | 25 ++++++++++++++++++ .../prototype/until/largestunit-undefined.js | 5 ++++ .../prototype/until/mixed-calendar-invalid.js | 23 ++++++++++++++++ .../prototype/until/options-invalid.js | 22 ++++++++++++++++ .../until/roundingincrement-as-expected.js | 24 +++++++++++++++++ .../prototype/until/roundingmode-ceil.js | 26 +++++++++++++++++++ .../prototype/until/roundingmode-floor.js | 26 +++++++++++++++++++ .../until/roundingmode-halfExpand.js | 26 +++++++++++++++++++ .../prototype/until/roundingmode-trunc.js | 26 +++++++++++++++++++ 18 files changed, 350 insertions(+), 6 deletions(-) rename test/built-ins/Temporal/PlainYearMonth/prototype/since/{arguments-casting.js => argument-casting.js} (100%) create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-ceil.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-floor.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfExpand.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-trunc.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-casting.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/arguments-missing-throws.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/largestunit-disallowed-units.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/mixed-calendar-invalid.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/options-invalid.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-as-expected.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-ceil.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-floor.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfExpand.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-trunc.js diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/arguments-casting.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-casting.js similarity index 100% rename from test/built-ins/Temporal/PlainYearMonth/prototype/since/arguments-casting.js rename to test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-casting.js diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-undefined.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-undefined.js index 29d5bc6cbd..0fc4865558 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-undefined.js @@ -20,3 +20,8 @@ TemporalHelpers.assertDuration(later.since(earlier, {}), 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "default largestUnit is year (implicit, pos)"); TemporalHelpers.assertDuration(earlier.since(later, {}), -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, "default largestUnit is year (implicit, neg)"); + +TemporalHelpers.assertDuration(later.since(earlier, () => {}), + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "default largestUnit is year (arrow function, pos)"); +TemporalHelpers.assertDuration(earlier.since(later, () => {}), + -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, "default largestUnit is year (arrow function, neg)"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-as-expected.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-as-expected.js index 0bbb13c9c4..a0b4e5636a 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-as-expected.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-as-expected.js @@ -11,11 +11,14 @@ features: [Temporal] const earlier = new Temporal.PlainYearMonth(2019, 1); const later = new Temporal.PlainYearMonth(2021, 9); -const laterSinceYear = later.since(earlier, { smallestUnit: 'years', roundingIncrement: 4, roundingMode: 'halfExpand' }); -TemporalHelpers.assertDurationsEqual(laterSinceYear, Temporal.Duration.from('P4Y'), 'rounds to an increment of years'); +const laterSinceYear = later.since(earlier, { smallestUnit: "years", roundingIncrement: 4, roundingMode: "halfExpand" }); +TemporalHelpers.assertDuration(laterSinceYear, + /* years = */ 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, "rounds to an increment of years"); -const laterSinceMixed = later.since(earlier, { smallestUnit: 'months', roundingIncrement: 5 }); -TemporalHelpers.assertDurationsEqual(laterSinceMixed, Temporal.Duration.from('P2Y5M'), 'rounds to an increment of months mixed with years'); +const laterSinceMixed = later.since(earlier, { smallestUnit: "months", roundingIncrement: 5 }); +TemporalHelpers.assertDuration(laterSinceMixed, + /* years = */ 2, /* months = */ 5, 0, 0, 0, 0, 0, 0, 0, 0, "rounds to an increment of months mixed with years"); -const laterSinceMonth = later.since(earlier, { largestUnit: 'months', smallestUnit: 'months', roundingIncrement: 10 }); -TemporalHelpers.assertDurationsEqual(laterSinceMonth, Temporal.Duration.from('P30M'), 'rounds to an increment of pure months'); +const laterSinceMonth = later.since(earlier, { largestUnit: "months", smallestUnit: "months", roundingIncrement: 10 }); +TemporalHelpers.assertDuration(laterSinceMonth, + 0, /* months = */ 30, 0, 0, 0, 0, 0, 0, 0, 0, "rounds to an increment of pure months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-ceil.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-ceil.js new file mode 100644 index 0000000000..5b6264cd78 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-ceil.js @@ -0,0 +1,26 @@ +// 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.prototype.since +description: Tests calculations with roundingMode "ceil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainYearMonth.from("2019-01"); +const later = Temporal.PlainYearMonth.from("2021-09"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "years", roundingMode: "ceil" }), + /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit: "years", roundingMode: "ceil" }), + /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "months", roundingMode: "ceil" }), + /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit: "months", roundingMode: "ceil" }), + /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-floor.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-floor.js new file mode 100644 index 0000000000..f11231fd0b --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-floor.js @@ -0,0 +1,26 @@ +// 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.prototype.since +description: Tests calculations with roundingMode "floor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainYearMonth.from("2019-01"); +const later = Temporal.PlainYearMonth.from("2021-09"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "years", roundingMode: "floor" }), + /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit: "years", roundingMode: "floor" }), + /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "months", roundingMode: "floor" }), + /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit: "months", roundingMode: "floor" }), + /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfExpand.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfExpand.js new file mode 100644 index 0000000000..e17a39e7c7 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfExpand.js @@ -0,0 +1,26 @@ +// 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.prototype.since +description: Tests calculations with roundingMode "halfExpand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainYearMonth.from("2019-01"); +const later = Temporal.PlainYearMonth.from("2021-09"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }), + /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit: "years", roundingMode: "halfExpand" }), + /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }), + /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit: "months", roundingMode: "halfExpand" }), + /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-trunc.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-trunc.js new file mode 100644 index 0000000000..98f2dc030e --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-trunc.js @@ -0,0 +1,26 @@ +// 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.prototype.since +description: Tests calculations with roundingMode "trunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainYearMonth.from("2019-01"); +const later = Temporal.PlainYearMonth.from("2021-09"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "years", roundingMode: "trunc" }), + /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit: "years", roundingMode: "trunc" }), + /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "months", roundingMode: "trunc" }), + /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit: "months", roundingMode: "trunc" }), + /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-casting.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-casting.js new file mode 100644 index 0000000000..317d5a7d87 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-casting.js @@ -0,0 +1,16 @@ +// 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.prototype.until +description: Calls to PYM.until cast arguments. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const nov94 = new Temporal.PlainYearMonth(1994, 11); +const jun13 = new Temporal.PlainYearMonth(2013, 6); +const diff = nov94.until(jun13); + +TemporalHelpers.assertDurationsEqual(nov94.until({ year: 2013, month: 6 }), diff, "Casts object argument"); +TemporalHelpers.assertDurationsEqual(nov94.until("2013-06"), diff, "Casts string argument"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/arguments-missing-throws.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/arguments-missing-throws.js new file mode 100644 index 0000000000..13d12576f8 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/arguments-missing-throws.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.prototype.until +description: Calls to PYM.until throw when missing required arguments. +features: [Temporal] +---*/ + +const jun13 = new Temporal.PlainYearMonth(2013, 6); + +assert.throws(TypeError, () => jun13.until({ year: 1994 }), 'Throws when missing required month'); +assert.throws(TypeError, () => jun13.until({ month: 11 }), 'Throws when missing required year'); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/largestunit-disallowed-units.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/largestunit-disallowed-units.js new file mode 100644 index 0000000000..f292b8ca33 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/largestunit-disallowed-units.js @@ -0,0 +1,25 @@ +// 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.prototype.until +description: Until throws on to0-small largestUnit +features: [Temporal, arrow-function] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +[ + "weeks", + "days", + "hours", + "minutes", + "seconds", + "milliseconds", + "microseconds", + "nanoseconds" +].forEach((largestUnit) => { + assert.throws(RangeError, () => earlier.until(later, { largestUnit }), + `throws on disallowed or invalid largestUnit: ${largestUnit}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/largestunit-undefined.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/largestunit-undefined.js index f7de1b004c..a4317ab2f4 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/largestunit-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/largestunit-undefined.js @@ -20,3 +20,8 @@ TemporalHelpers.assertDuration(earlier.until(later, {}), 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "default largestUnit is year (implicit, pos)"); TemporalHelpers.assertDuration(later.until(earlier, {}), -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, "default largestUnit is year (implicit, neg)"); + +TemporalHelpers.assertDuration(earlier.until(later, () => {}), + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "default largestUnit is year (arrow function, pos)"); +TemporalHelpers.assertDuration(later.until(earlier, () => {}), + -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, "default largestUnit is year (arrow function, neg)"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/mixed-calendar-invalid.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/mixed-calendar-invalid.js new file mode 100644 index 0000000000..d971f9faf7 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/mixed-calendar-invalid.js @@ -0,0 +1,23 @@ +// 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.prototype.until +description: Mixed calendars throw as invalid +features: [Temporal] +---*/ + +class customCal extends Temporal.Calendar { + constructor () { + super('iso8601'); + } + + toString() { + return "I am a secret cal."; + } +} + +const ym1 = new Temporal.PlainYearMonth(2000, 1); +const ym2 = new Temporal.PlainYearMonth(2000, 1, new customCal()); + +assert.throws(RangeError, () => ym1.until(ym2), 'until throws with different calendars'); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/options-invalid.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/options-invalid.js new file mode 100644 index 0000000000..312c733b64 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/options-invalid.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.prototype.until +description: Verify that invalid options are handled correctly. +features: [Temporal] +---*/ + +const feb20 = new Temporal.PlainYearMonth(2020, 2); +const feb21 = new Temporal.PlainYearMonth(2021, 2); + +[ + null, + 1, + "hello", + true, + Symbol("foo"), + 1n +].forEach((badOption) => + assert.throws(TypeError, () => feb20.until(feb21, badOption), `${String(badOption)} throws TypeError`) +); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-as-expected.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-as-expected.js new file mode 100644 index 0000000000..f736432c69 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-as-expected.js @@ -0,0 +1,24 @@ +// 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.prototype.until +description: Until rounding increments work as expected +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const laterSinceYear = earlier.until(later, { smallestUnit: "years", roundingIncrement: 4, roundingMode: "halfExpand" }); +TemporalHelpers.assertDuration(laterSinceYear, + /* years = */ 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, "rounds to an increment of years"); + +const laterSinceMixed = earlier.until(later, { smallestUnit: "months", roundingIncrement: 5 }); +TemporalHelpers.assertDuration(laterSinceMixed, + /* years = */ 2, /* months = */ 5, 0, 0, 0, 0, 0, 0, 0, 0, "rounds to an increment of months mixed with years"); + +const laterSinceMonth = earlier.until(later, { largestUnit: "months", smallestUnit: "months", roundingIncrement: 10 }); +TemporalHelpers.assertDuration(laterSinceMonth, + 0, /* months = */ 30, 0, 0, 0, 0, 0, 0, 0, 0, "rounds to an increment of pure months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-ceil.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-ceil.js new file mode 100644 index 0000000000..550223b1be --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-ceil.js @@ -0,0 +1,26 @@ +// 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.prototype.until +description: Tests calculations with roundingMode "ceil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainYearMonth.from("2019-01"); +const later = Temporal.PlainYearMonth.from("2021-09"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "years", roundingMode: "ceil" }), + /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit: "years", roundingMode: "ceil" }), + /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "months", roundingMode: "ceil" }), + /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit: "months", roundingMode: "ceil" }), + /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-floor.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-floor.js new file mode 100644 index 0000000000..26b5359ca9 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-floor.js @@ -0,0 +1,26 @@ +// 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.prototype.until +description: Tests calculations with roundingMode "floor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainYearMonth.from("2019-01"); +const later = Temporal.PlainYearMonth.from("2021-09"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "years", roundingMode: "floor" }), + /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit: "years", roundingMode: "floor" }), + /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "months", roundingMode: "floor" }), + /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit: "months", roundingMode: "floor" }), + /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfExpand.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfExpand.js new file mode 100644 index 0000000000..9f52de0975 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfExpand.js @@ -0,0 +1,26 @@ +// 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.prototype.until +description: Tests calculations with roundingMode "halfExpand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainYearMonth.from("2019-01"); +const later = Temporal.PlainYearMonth.from("2021-09"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "years", roundingMode: "halfExpand" }), + /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }), + /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "months", roundingMode: "halfExpand" }), + /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }), + /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-trunc.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-trunc.js new file mode 100644 index 0000000000..25a2b9f808 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-trunc.js @@ -0,0 +1,26 @@ +// 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.prototype.until +description: Tests calculations with roundingMode "trunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainYearMonth.from("2019-01"); +const later = Temporal.PlainYearMonth.from("2021-09"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "years", roundingMode: "trunc" }), + /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit: "years", roundingMode: "trunc" }), + /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "months", roundingMode: "trunc" }), + /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit: "months", roundingMode: "trunc" }), + /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months");