mirror of https://github.com/tc39/test262.git
Add basic tests converted from demitasse
This commit is contained in:
parent
ae9440df36
commit
da9d81a694
|
@ -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');
|
14
test/built-ins/Temporal/PlainYearMonth/prototype/since/arguments-missing-throws.js
vendored
Normal file
14
test/built-ins/Temporal/PlainYearMonth/prototype/since/arguments-missing-throws.js
vendored
Normal 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');
|
|
@ -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.')
|
|
@ -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');
|
21
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-as-expected.js
vendored
Normal file
21
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-as-expected.js
vendored
Normal 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');
|
|
@ -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');
|
Loading…
Reference in New Issue