Skip to content

Commit

Permalink
Temporal: Consistently test all string entry points for representable…
Browse files Browse the repository at this point in the history
… 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
ptomato committed Oct 3, 2024
1 parent e3da187 commit a9c026b
Show file tree
Hide file tree
Showing 33 changed files with 1,173 additions and 220 deletions.
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`
);
}
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`
);
}
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 test/built-ins/Temporal/Instant/compare/argument-string-limits.js
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 test/built-ins/Temporal/Instant/compare/instant-string-limits.js

This file was deleted.

38 changes: 38 additions & 0 deletions test/built-ins/Temporal/Instant/from/argument-string-limits.js
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 test/built-ins/Temporal/Instant/from/instant-string-limits.js

This file was deleted.

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`
);
}
Loading

0 comments on commit a9c026b

Please sign in to comment.