-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and expand tests for Duration constructor / from().
- Loading branch information
Showing
16 changed files
with
183 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.duration | ||
description: Basic constructor tests. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
TemporalHelpers.assertDuration(new Temporal.Duration(5, 5, 5, 5, 5, 5, 5, 5, 5, 0), | ||
5, 5, 5, 5, 5, 5, 5, 5, 5, 0, "positive"); | ||
TemporalHelpers.assertDuration(new Temporal.Duration(-5, -5, -5, -5, -5, -5, -5, -5, -5, 0), | ||
-5, -5, -5, -5, -5, -5, -5, -5, -5, 0, "negative"); | ||
TemporalHelpers.assertDuration(new Temporal.Duration(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0), | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "negative zero"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
test/built-ins/Temporal/Duration/from/argument-object-invalid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.duration.from | ||
description: Invalid object arguments. | ||
features: [Temporal] | ||
---*/ | ||
|
||
const tests = [ | ||
{ years: 0.5 }, | ||
{ months: 0.5 }, | ||
{ weeks: 0.5 }, | ||
{ days: 0.5 }, | ||
{ hours: 0.5, minutes: 20 }, | ||
{ hours: 0.5, seconds: 15 }, | ||
{ minutes: 10.7, nanoseconds: 400 }, | ||
{ hours: 1, minutes: -30 }, | ||
]; | ||
|
||
for (const input of tests) { | ||
assert.throws(RangeError, () => Temporal.Duration.from(input)); | ||
} | ||
|
||
assert.throws(TypeError, () => Temporal.Duration.from({})); | ||
assert.throws(TypeError, () => Temporal.Duration.from({ month: 12 })); |
32 changes: 32 additions & 0 deletions
32
test/built-ins/Temporal/Duration/from/argument-string-invalid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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.duration.from | ||
description: Invalid string arguments. | ||
features: [Temporal] | ||
---*/ | ||
|
||
const tests = [ | ||
"P1Y1M1W1DT1H1M1.123456789123S", | ||
"P0.5Y", | ||
"P1Y0,5M", | ||
"P1Y1M0.5W", | ||
"P1Y1M1W0,5D", | ||
"P1Y1M1W1DT0.5H5S", | ||
"P1Y1M1W1DT1.5H0,5M", | ||
"P1Y1M1W1DT1H0.5M0.5S", | ||
"P", | ||
"PT", | ||
"-P", | ||
"-PT", | ||
"+P", | ||
"+PT", | ||
"P1Y1M1W1DT1H1M1.01Sjunk", | ||
"P-1Y1M", | ||
"P1Y-1M" | ||
]; | ||
|
||
for (const input of tests) { | ||
assert.throws(RangeError, () => Temporal.Duration.from(input)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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.duration.from | ||
description: Basic string arguments. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1D"), | ||
0, 0, 0, 1, 0, 0, 0, 0, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("p1y1m1dt1h1m1s"), | ||
1, 1, 0, 1, 1, 1, 1, 0, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1.1S"), | ||
1, 1, 1, 1, 1, 1, 1, 100, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1.12S"), | ||
1, 1, 1, 1, 1, 1, 1, 120, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1.123S"), | ||
1, 1, 1, 1, 1, 1, 1, 123, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1.1234S"), | ||
1, 1, 1, 1, 1, 1, 1, 123, 400, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1.12345S"), | ||
1, 1, 1, 1, 1, 1, 1, 123, 450, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1.123456S"), | ||
1, 1, 1, 1, 1, 1, 1, 123, 456, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1.1234567S"), | ||
1, 1, 1, 1, 1, 1, 1, 123, 456, 700); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1.12345678S"), | ||
1, 1, 1, 1, 1, 1, 1, 123, 456, 780); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1.123456789S"), | ||
1, 1, 1, 1, 1, 1, 1, 123, 456, 789); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1Y1M1W1DT1H1M1,12S"), | ||
1, 1, 1, 1, 1, 1, 1, 120, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1DT0.5M"), | ||
0, 0, 0, 1, 0, 0, 30, 0, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("P1DT0,5H"), | ||
0, 0, 0, 1, 0, 30, 0, 0, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("+P1D"), | ||
0, 0, 0, 1, 0, 0, 0, 0, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("-P1D"), | ||
0, 0, 0, -1, 0, 0, 0, 0, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("\u2212P1D"), | ||
0, 0, 0, -1, 0, 0, 0, 0, 0, 0); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("-P1Y1M1W1DT1H1M1.123456789S"), | ||
-1, -1, -1, -1, -1, -1, -1, -123, -456, -789); | ||
TemporalHelpers.assertDuration(Temporal.Duration.from("PT100M"), | ||
0, 0, 0, 0, 0, 100, 0, 0, 0, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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.duration | ||
description: Constructor with mixed signs. | ||
features: [Temporal] | ||
---*/ | ||
|
||
assert.throws(RangeError, () => new Temporal.Duration(-1, 1, 1, 1, 1, 1, 1, 1, 1, 1)); | ||
assert.throws(RangeError, () => new Temporal.Duration(1, -1, 1, 1, 1, 1, 1, 1, 1, 1)); | ||
assert.throws(RangeError, () => new Temporal.Duration(1, 1, -1, 1, 1, 1, 1, 1, 1, 1)); | ||
assert.throws(RangeError, () => new Temporal.Duration(1, 1, 1, -1, 1, 1, 1, 1, 1, 1)); | ||
assert.throws(RangeError, () => new Temporal.Duration(1, 1, 1, 1, -1, 1, 1, 1, 1, 1)); | ||
assert.throws(RangeError, () => new Temporal.Duration(1, 1, 1, 1, 1, -1, 1, 1, 1, 1)); | ||
assert.throws(RangeError, () => new Temporal.Duration(1, 1, 1, 1, 1, 1, -1, 1, 1, 1)); | ||
assert.throws(RangeError, () => new Temporal.Duration(1, 1, 1, 1, 1, 1, 1, -1, 1, 1)); | ||
assert.throws(RangeError, () => new Temporal.Duration(1, 1, 1, 1, 1, 1, 1, 1, -1, 1)); | ||
assert.throws(RangeError, () => new Temporal.Duration(1, 1, 1, 1, 1, 1, 1, 1, 1, -1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters