Skip to content

Commit

Permalink
Port tests for PlainTime.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger authored and rwaldron committed Feb 28, 2022
1 parent 18ce639 commit 2f592de
Show file tree
Hide file tree
Showing 32 changed files with 1,181 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/built-ins/Temporal/PlainTime/from/argument-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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.plaintime.from
description: Number argument is converted to string
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const result = Temporal.PlainTime.from(1523);
TemporalHelpers.assertPlainTime(result, 15, 23, 0, 0, 0, 0);
Original file line number Diff line number Diff line change
@@ -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.plaintime.from
description: Object argument handles leap seconds according to the overflow option.
includes: [temporalHelpers.js]
features: [Temporal]
---*/

for (const options of [undefined, {}, { overflow: "constrain" }]) {
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ hour: 23, minute: 59, second: 60 }, options),
23, 59, 59, 0, 0, 0);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ hour: 12, minute: 30, second: 60 }, options),
12, 30, 59, 0, 0, 0);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ hour: 23, minute: 59, second: 60, millisecond: 170 }, options),
23, 59, 59, 170, 0, 0);
}

const options = { overflow: "reject" };
assert.throws(RangeError, () => Temporal.PlainTime.from({ hour: 23, minute: 59, second: 60 }, options));
assert.throws(RangeError, () => Temporal.PlainTime.from({ hour: 12, minute: 30, second: 60 }, options));
assert.throws(RangeError, () => Temporal.PlainTime.from({ hour: 23, minute: 59, second: 60, millisecond: 170 }, options));
21 changes: 21 additions & 0 deletions test/built-ins/Temporal/PlainTime/from/argument-object.js
Original file line number Diff line number Diff line change
@@ -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.plaintime.from
description: Plain object argument is supported and ignores plural properties
includes: [temporalHelpers.js]
features: [Temporal]
---*/

TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ hour: 15, minute: 23 }),
15, 23, 0, 0, 0, 0);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ minute: 30, microsecond: 555 }),
0, 30, 0, 0, 555, 0);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ year: 2019, month: 10, day: 1, hour: 14, minute: 20, second: 36 }),
14, 20, 36, 0, 0, 0);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ hours: 2, minute: 30, microsecond: 555 }),
0, 30, 0, 0, 555, 0);

assert.throws(TypeError, () => Temporal.PlainTime.from({}));
assert.throws(TypeError, () => Temporal.PlainTime.from({ minutes: 12 }));
Original file line number Diff line number Diff line change
@@ -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.plaintime.from
description: Leap second is replaced by :59 in ISO strings.
includes: [temporalHelpers.js]
features: [Temporal]
---*/

for (const options of [undefined, {}, { overflow: "constrain" }, { overflow: "reject" }]) {
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from("23:59:60", options),
23, 59, 59, 0, 0, 0);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from("12:30:60", options),
12, 30, 59, 0, 0, 0);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from("23:59:60.170", options),
23, 59, 59, 170, 0, 0);
}
14 changes: 14 additions & 0 deletions test/built-ins/Temporal/PlainTime/from/overflow-constrain.js
Original file line number Diff line number Diff line change
@@ -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.plaintime.from
description: constrain value for overflow option
includes: [temporalHelpers.js]
features: [Temporal]
---*/

TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ hour: 26 }, { overflow: "constrain" }),
23, 0, 0, 0, 0, 0);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ hour: 22 }, { overflow: "constrain" }),
22, 0, 0, 0, 0, 0);
13 changes: 13 additions & 0 deletions test/built-ins/Temporal/PlainTime/from/overflow-reject.js
Original file line number Diff line number Diff line change
@@ -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.plaintime.from
description: reject value for overflow option
includes: [temporalHelpers.js]
features: [Temporal]
---*/

assert.throws(RangeError, () => Temporal.PlainTime.from({ hour: 26 }, { overflow: "reject" }));
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from({ hour: 22 }, { overflow: "reject" }),
22, 0, 0, 0, 0, 0);
12 changes: 12 additions & 0 deletions test/built-ins/Temporal/PlainTime/negative-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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.plaintime
description: Negative zero arguments are treated as zero.
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const plainTime = new Temporal.PlainTime(-0, -0, -0, -0, -0, -0);
TemporalHelpers.assertPlainTime(plainTime, 0, 0, 0, 0, 0, 0);
Original file line number Diff line number Diff line change
@@ -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.plaintime.prototype.add
description: Duration arguments are supported.
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const plainTime = new Temporal.PlainTime(15, 23, 30, 123, 456, 789);
const duration = Temporal.Duration.from("PT16H");
TemporalHelpers.assertPlainTime(plainTime.add(duration),
7, 23, 30, 123, 456, 789);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.plaintime.prototype.add
description: Higher units are ignored.
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const plainTime = new Temporal.PlainTime(15, 23, 30, 123, 456, 789);
const values = [
new Temporal.Duration(0, 0, 0, 1),
new Temporal.Duration(0, 0, 1),
new Temporal.Duration(0, 1),
new Temporal.Duration(1),
{ days: 1 },
{ weeks: 1 },
{ months: 1 },
{ years: 1 },
"P1D",
"P1W",
"P1M",
"P1Y",
];
for (const value of values) {
TemporalHelpers.assertPlainTime(plainTime.add(value),
15, 23, 30, 123, 456, 789);
}
37 changes: 37 additions & 0 deletions test/built-ins/Temporal/PlainTime/prototype/add/argument-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.plaintime.prototype.add
description: Plain object arguments are supported.
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const plainTime = new Temporal.PlainTime(15, 23, 30, 123, 456, 789);
TemporalHelpers.assertPlainTime(plainTime.add({ hours: 16 }),
7, 23, 30, 123, 456, 789);
TemporalHelpers.assertPlainTime(plainTime.add({ minutes: 45 }),
16, 8, 30, 123, 456, 789);
TemporalHelpers.assertPlainTime(plainTime.add({ seconds: 800 }),
15, 36, 50, 123, 456, 789);
TemporalHelpers.assertPlainTime(plainTime.add({ milliseconds: 800 }),
15, 23, 30, 923, 456, 789);
TemporalHelpers.assertPlainTime(plainTime.add({ microseconds: 800 }),
15, 23, 30, 124, 256, 789);
TemporalHelpers.assertPlainTime(plainTime.add({ nanoseconds: 300 }),
15, 23, 30, 123, 457, 89);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from("07:23:30.123456789").add({ hours: -16 }),
15, 23, 30, 123, 456, 789);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from("16:08:30.123456789").add({ minutes: -45 }),
15, 23, 30, 123, 456, 789);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from("15:36:50.123456789").add({ seconds: -800 }),
15, 23, 30, 123, 456, 789);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from("15:23:30.923456789").add({ milliseconds: -800 }),
15, 23, 30, 123, 456, 789);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from("15:23:30.124256789").add({ microseconds: -800 }),
15, 23, 30, 123, 456, 789);
TemporalHelpers.assertPlainTime(Temporal.PlainTime.from("15:23:30.123457089").add({ nanoseconds: -300 }),
15, 23, 30, 123, 456, 789);
TemporalHelpers.assertPlainTime(plainTime.add({ minute: 1, hours: 1 }),
16, 23, 30, 123, 456, 789);
Original file line number Diff line number Diff line change
@@ -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.plaintime.prototype.round
description: Rounding can cross midnight
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const plainTime = Temporal.PlainTime.from("23:59:59.999999999");
for (const smallestUnit of ["hour", "minute", "second", "millisecond", "microsecond"]) {
TemporalHelpers.assertPlainTime(plainTime.round({ smallestUnit }), 0, 0, 0, 0, 0, 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.plaintime.prototype.round
description: Valid values for roundingIncrement option
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const plainTime = new Temporal.PlainTime(3, 34, 56, 987, 654, 321);

TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hours", roundingIncrement: 1 }),
4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hours", roundingIncrement: 2 }),
4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hours", roundingIncrement: 3 }),
3, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hours", roundingIncrement: 4 }),
4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hours", roundingIncrement: 6 }),
6, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hours", roundingIncrement: 8 }),
0, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hours", roundingIncrement: 12 }),
0, 0, 0, 0, 0, 0, "hours");
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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.plaintime.prototype.round
description: Valid values for roundingIncrement option
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const plainTime = new Temporal.PlainTime(3, 34, 56, 987, 654, 321);

TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 1 }),
3, 34, 56, 987, 654, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 2 }),
3, 34, 56, 987, 654, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 4 }),
3, 34, 56, 987, 656, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 5 }),
3, 34, 56, 987, 655, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 8 }),
3, 34, 56, 987, 656, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 10 }),
3, 34, 56, 987, 650, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 20 }),
3, 34, 56, 987, 660, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 25 }),
3, 34, 56, 987, 650, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 40 }),
3, 34, 56, 987, 640, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 50 }),
3, 34, 56, 987, 650, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 100 }),
3, 34, 56, 987, 700, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 125 }),
3, 34, 56, 987, 625, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 200 }),
3, 34, 56, 987, 600, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 250 }),
3, 34, 56, 987, 750, 0, "microseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 500 }),
3, 34, 56, 987, 500, 0, "microseconds");
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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.plaintime.prototype.round
description: Valid values for roundingIncrement option
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const plainTime = new Temporal.PlainTime(3, 34, 56, 987, 654, 321);

TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 1 }),
3, 34, 56, 988, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 2 }),
3, 34, 56, 988, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 4 }),
3, 34, 56, 988, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 5 }),
3, 34, 56, 990, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 8 }),
3, 34, 56, 984, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 10 }),
3, 34, 56, 990, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 20 }),
3, 34, 56, 980, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 25 }),
3, 34, 57, 0, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 40 }),
3, 34, 57, 0, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 50 }),
3, 34, 57, 0, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 100 }),
3, 34, 57, 0, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 125 }),
3, 34, 57, 0, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 200 }),
3, 34, 57, 0, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 250 }),
3, 34, 57, 0, 0, 0, "milliseconds");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 500 }),
3, 34, 57, 0, 0, 0, "milliseconds");

0 comments on commit 2f592de

Please sign in to comment.