Add basic tests converted from demitasse

This commit is contained in:
Sarah GHP 2021-11-17 18:15:11 +01:00 committed by rwaldron
parent ae9440df36
commit da9d81a694
6 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,16 @@
// Copyright (C) 2021 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: Calls to PYM.since cast arguments.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const nov94 = new Temporal.PlainYearMonth(1994, 11);
const jun13 = new Temporal.PlainYearMonth(2013, 6);
const diff = jun13.since(nov94);
TemporalHelpers.assertDurationsEqual(jun13.since({ year: 1994, month: 11 }), diff, 'Casts object argument');
TemporalHelpers.assertDurationsEqual(jun13.since('1994-11'), diff, 'Casts string argument');

View File

@ -0,0 +1,14 @@
// Copyright (C) 2021 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: Calls to PYM.since throw when missing required arguments.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const jun13 = new Temporal.PlainYearMonth(2013, 6);
assert.throws(TypeError, () => jun13.since({ year: 1994 }), 'Throws when missing required month');
assert.throws(TypeError, () => jun13.since({ month: 11 }), 'Throws when missing required year');

View File

@ -0,0 +1,20 @@
// Copyright (C) 2021 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: Basic calls to PYM.since.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const feb20 = new Temporal.PlainYearMonth(2020, 2);
const feb21 = new Temporal.PlainYearMonth(2021, 2);
const oneYear = Temporal.Duration.from('P1Y');
const twelveMonths = Temporal.Duration.from('P12M');
TemporalHelpers.assertDurationsEqual(feb21.since(feb20), oneYear, 'Returns year by default');
TemporalHelpers.assertDurationsEqual(feb21.since(feb20, { largestUnit: 'auto' }), oneYear, 'Returns year by default');
TemporalHelpers.assertDurationsEqual(feb21.since(feb20, { largestUnit: 'years' }), oneYear, 'Returns year explicitly');
TemporalHelpers.assertDurationsEqual(feb21.since(feb20, { largestUnit: 'months' }), twelveMonths, 'Returns months when requested.')

View File

@ -0,0 +1,15 @@
// Copyright (C) 2021 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: Since returns negative and positive values
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const nov94 = new Temporal.PlainYearMonth(1994, 11);
const jun13 = new Temporal.PlainYearMonth(2013, 6);
const diff = jun13.since(nov94);
TemporalHelpers.assertDurationsEqual(nov94.since(jun13), diff.negated(), 'Since is inverse of until');

View File

@ -0,0 +1,21 @@
// Copyright (C) 2021 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: Since 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 = later.since(earlier, { smallestUnit: 'years', roundingIncrement: 4, roundingMode: 'halfExpand' });
TemporalHelpers.assertDurationsEqual(laterSinceYear, Temporal.Duration.from('P4Y'), '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 laterSinceMonth = later.since(earlier, { largestUnit: 'months', smallestUnit: 'months', roundingIncrement: 10 });
TemporalHelpers.assertDurationsEqual(laterSinceMonth, Temporal.Duration.from('P30M'), 'rounds to an increment of pure months');

View File

@ -0,0 +1,15 @@
// Copyright (C) 2021 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: Since observes symmetry with until
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const nov94 = new Temporal.PlainYearMonth(1994, 11);
const jun13 = new Temporal.PlainYearMonth(2013, 6);
const diff = jun13.since(nov94);
TemporalHelpers.assertDurationsEqual(diff, nov94.until(jun13), 'Since is inverse of until');