forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Consistently test all string entry points for representable…
… range Remove the existing "instant-string-limits.js" that only applied to APIs where ToTemporalInstant was called. Add "argument-string-limits.js" tests everywhere ISO strings are converted. Related to tc39/proposal-temporal#2985
- Loading branch information
Showing
33 changed files
with
1,173 additions
and
220 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
test/built-ins/Temporal/Duration/compare/relativeto-string-limits.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,48 @@ | ||
// Copyright (C) 2024 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.compare | ||
description: ISO strings at the edges of the representable range | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(); | ||
|
||
const validStrings = [ | ||
"-271821-04-20T00:00Z[UTC]", | ||
"+275760-09-13T00:00Z[UTC]", | ||
"+275760-09-13T01:00+01:00[+01:00]", | ||
"+275760-09-13T23:59+23:59[+23:59]", | ||
"-271821-04-19", | ||
"-271821-04-19T01:00", | ||
"+275760-09-13", | ||
"+275760-09-13T23:00", | ||
]; | ||
|
||
for (const relativeTo of validStrings) { | ||
Temporal.Duration.compare(instance, instance, { relativeTo }); | ||
} | ||
|
||
const invalidStrings = [ | ||
"-271821-04-19T23:00-01:00[-01:00]", | ||
"-271821-04-19T00:01-23:59[-23:59]", | ||
"-271821-04-19T23:59:59.999999999Z[UTC]", | ||
"-271821-04-19T23:00-00:59[-00:59]", | ||
"-271821-04-19T00:00:00-23:59[-23:59]", | ||
"+275760-09-13T00:00:00.000000001Z[UTC]", | ||
"+275760-09-13T01:00+00:59[+00:59]", | ||
"+275760-09-14T00:00+23:59[+23:59]", | ||
"-271821-04-18", | ||
"-271821-04-18T23:00", | ||
"+275760-09-14", | ||
"+275760-09-14T01:00", | ||
]; | ||
|
||
for (const relativeTo of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => Temporal.Duration.compare(instance, instance, { relativeTo }), | ||
`"${relativeTo}" is outside the representable range for a relativeTo parameter` | ||
); | ||
} |
48 changes: 48 additions & 0 deletions
48
test/built-ins/Temporal/Duration/prototype/round/relativeto-string-limits.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,48 @@ | ||
// Copyright (C) 2024 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: ISO strings at the edges of the representable range | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(); | ||
|
||
const validStrings = [ | ||
"-271821-04-20T00:00Z[UTC]", | ||
"+275760-09-13T00:00Z[UTC]", | ||
"+275760-09-13T01:00+01:00[+01:00]", | ||
"+275760-09-13T23:59+23:59[+23:59]", | ||
"-271821-04-19", | ||
"-271821-04-19T01:00", | ||
"+275760-09-13", | ||
"+275760-09-13T23:00", | ||
]; | ||
|
||
for (const relativeTo of validStrings) { | ||
instance.round({ smallestUnit: "minutes", relativeTo }); | ||
} | ||
|
||
const invalidStrings = [ | ||
"-271821-04-19T23:00-01:00[-01:00]", | ||
"-271821-04-19T00:01-23:59[-23:59]", | ||
"-271821-04-19T23:59:59.999999999Z[UTC]", | ||
"-271821-04-19T23:00-00:59[-00:59]", | ||
"-271821-04-19T00:00:00-23:59[-23:59]", | ||
"+275760-09-13T00:00:00.000000001Z[UTC]", | ||
"+275760-09-13T01:00+00:59[+00:59]", | ||
"+275760-09-14T00:00+23:59[+23:59]", | ||
"-271821-04-18", | ||
"-271821-04-18T23:00", | ||
"+275760-09-14", | ||
"+275760-09-14T01:00", | ||
]; | ||
|
||
for (const relativeTo of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.round({ smallestUnit: "minutes", relativeTo }), | ||
`"${relativeTo}" is outside the representable range for a relativeTo parameter` | ||
); | ||
} |
48 changes: 48 additions & 0 deletions
48
test/built-ins/Temporal/Duration/prototype/total/relativeto-string-limits.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,48 @@ | ||
// Copyright (C) 2024 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.total | ||
description: ISO strings at the edges of the representable range | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(); | ||
|
||
const validStrings = [ | ||
"-271821-04-20T00:00Z[UTC]", | ||
"+275760-09-13T00:00Z[UTC]", | ||
"+275760-09-13T01:00+01:00[+01:00]", | ||
"+275760-09-13T23:59+23:59[+23:59]", | ||
"-271821-04-19", | ||
"-271821-04-19T01:00", | ||
"+275760-09-13", | ||
"+275760-09-13T23:00", | ||
]; | ||
|
||
for (const relativeTo of validStrings) { | ||
instance.total({ unit: "minutes", relativeTo }); | ||
} | ||
|
||
const invalidStrings = [ | ||
"-271821-04-19T23:00-01:00[-01:00]", | ||
"-271821-04-19T00:01-23:59[-23:59]", | ||
"-271821-04-19T23:59:59.999999999Z[UTC]", | ||
"-271821-04-19T23:00-00:59[-00:59]", | ||
"-271821-04-19T00:00:00-23:59[-23:59]", | ||
"+275760-09-13T00:00:00.000000001Z[UTC]", | ||
"+275760-09-13T01:00+00:59[+00:59]", | ||
"+275760-09-14T00:00+23:59[+23:59]", | ||
"-271821-04-18", | ||
"-271821-04-18T23:00", | ||
"+275760-09-14", | ||
"+275760-09-14T01:00", | ||
]; | ||
|
||
for (const relativeTo of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.total({ unit: "minutes", relativeTo }), | ||
`"${relativeTo}" is outside the representable range for a relativeTo parameter` | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
test/built-ins/Temporal/Instant/compare/argument-string-limits.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,46 @@ | ||
// Copyright (C) 2024 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.compare | ||
description: ISO strings at the edges of the representable range | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Instant(0n); | ||
|
||
const validStrings = [ | ||
"-271821-04-20T00:00Z", | ||
"-271821-04-19T23:00-01:00", | ||
"-271821-04-19T00:00:00.000000001-23:59:59.999999999", | ||
"+275760-09-13T00:00Z", | ||
"+275760-09-13T01:00+01:00", | ||
"+275760-09-13T23:59:59.999999999+23:59:59.999999999", | ||
]; | ||
|
||
for (const arg of validStrings) { | ||
Temporal.Instant.compare(arg, instance); | ||
Temporal.Instant.compare(instance, arg); | ||
} | ||
|
||
const invalidStrings = [ | ||
"-271821-04-19T23:59:59.999999999Z", | ||
"-271821-04-19T23:00-00:59:59.999999999", | ||
"-271821-04-19T00:00:00-23:59:59.999999999", | ||
"+275760-09-13T00:00:00.000000001Z", | ||
"+275760-09-13T01:00+00:59:59.999999999", | ||
"+275760-09-14T00:00+23:59:59.999999999", | ||
]; | ||
|
||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => Temporal.Instant.compare(arg, instance), | ||
`"${arg}" is outside the representable range of Instant (first argument)` | ||
); | ||
assert.throws( | ||
RangeError, | ||
() => Temporal.Instant.compare(instance, arg), | ||
`"${arg}" is outside the representable range of Instant (second argument)` | ||
); | ||
} |
46 changes: 0 additions & 46 deletions
46
test/built-ins/Temporal/Instant/compare/instant-string-limits.js
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
test/built-ins/Temporal/Instant/from/argument-string-limits.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,38 @@ | ||
// Copyright (C) 2024 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.from | ||
description: ISO strings at the edges of the representable range | ||
features: [Temporal] | ||
---*/ | ||
|
||
const validStrings = [ | ||
"-271821-04-20T00:00Z", | ||
"-271821-04-19T23:00-01:00", | ||
"-271821-04-19T00:00:00.000000001-23:59:59.999999999", | ||
"+275760-09-13T00:00Z", | ||
"+275760-09-13T01:00+01:00", | ||
"+275760-09-13T23:59:59.999999999+23:59:59.999999999", | ||
]; | ||
|
||
for (const arg of validStrings) { | ||
Temporal.Instant.from(arg); | ||
} | ||
|
||
const invalidStrings = [ | ||
"-271821-04-19T23:59:59.999999999Z", | ||
"-271821-04-19T23:00-00:59:59.999999999", | ||
"-271821-04-19T00:00:00-23:59:59.999999999", | ||
"+275760-09-13T00:00:00.000000001Z", | ||
"+275760-09-13T01:00+00:59:59.999999999", | ||
"+275760-09-14T00:00+23:59:59.999999999", | ||
]; | ||
|
||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => Temporal.Instant.from(arg), | ||
`"${arg}" is outside the representable range of Instant` | ||
); | ||
} |
43 changes: 0 additions & 43 deletions
43
test/built-ins/Temporal/Instant/from/instant-string-limits.js
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
test/built-ins/Temporal/Instant/prototype/equals/argument-string-limits.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,40 @@ | ||
// Copyright (C) 2024 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.equals | ||
description: ISO strings at the edges of the representable range | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Instant(0n); | ||
|
||
const validStrings = [ | ||
"-271821-04-20T00:00Z", | ||
"-271821-04-19T23:00-01:00", | ||
"-271821-04-19T00:00:00.000000001-23:59:59.999999999", | ||
"+275760-09-13T00:00Z", | ||
"+275760-09-13T01:00+01:00", | ||
"+275760-09-13T23:59:59.999999999+23:59:59.999999999", | ||
]; | ||
|
||
for (const arg of validStrings) { | ||
instance.equals(arg); | ||
} | ||
|
||
const invalidStrings = [ | ||
"-271821-04-19T23:59:59.999999999Z", | ||
"-271821-04-19T23:00-00:59:59.999999999", | ||
"-271821-04-19T00:00:00-23:59:59.999999999", | ||
"+275760-09-13T00:00:00.000000001Z", | ||
"+275760-09-13T01:00+00:59:59.999999999", | ||
"+275760-09-14T00:00+23:59:59.999999999", | ||
]; | ||
|
||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.equals(arg), | ||
`"${arg}" is outside the representable range of Instant` | ||
); | ||
} |
Oops, something went wrong.