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.
Add tests for various invalid ISO strings for PlainDate
These tests check API entry points that convert strings to Temporal.PlainDate, with a list of various strings that are all not valid for that context according to ISO 8601.
- Loading branch information
Showing
25 changed files
with
1,535 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
test/built-ins/Temporal/Calendar/prototype/dateAdd/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,61 @@ | ||
// 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.calendar.prototype.dateadd | ||
description: > | ||
RangeError thrown if an invalid ISO string (or syntactically valid ISO string | ||
that is not supported) is used as a PlainDate | ||
features: [Temporal, arrow-function] | ||
---*/ | ||
|
||
const invalidStrings = [ | ||
// invalid ISO strings: | ||
"", | ||
"invalid iso8601", | ||
"2020-01-00", | ||
"2020-01-32", | ||
"2020-02-30", | ||
"2021-02-29", | ||
"2020-00-01", | ||
"2020-13-01", | ||
"2020-01-01T", | ||
"2020-01-01T25:00:00", | ||
"2020-01-01T01:60:00", | ||
"2020-01-01T01:60:61", | ||
"2020-01-01junk", | ||
"2020-01-01T00:00:00junk", | ||
"2020-01-01T00:00:00+00:00junk", | ||
"2020-01-01T00:00:00+00:00[UTC]junk", | ||
"2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", | ||
"02020-01-01", | ||
"2020-001-01", | ||
"2020-01-001", | ||
"2020-01-01T001", | ||
"2020-01-01T01:001", | ||
"2020-01-01T01:01:001", | ||
// valid, but forms not supported in Temporal: | ||
"2020-W01-1", | ||
"2020-001", | ||
"+0002020-01-01", | ||
// valid, but this calendar must not exist: | ||
"2020-01-01[u-ca=notexist]", | ||
// may be valid in other contexts, but insufficient information for PlainDate: | ||
"2020-01", | ||
"+002020-01", | ||
"01-01", | ||
"2020-W01", | ||
"P1Y", | ||
"-P12Y", | ||
// valid, but outside the supported range: | ||
"-999999-01-01", | ||
"+999999-01-01", | ||
]; | ||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.dateAdd(arg), | ||
`"${arg}" should not be a valid ISO string for a PlainDate` | ||
); | ||
} |
67 changes: 67 additions & 0 deletions
67
test/built-ins/Temporal/Calendar/prototype/dateUntil/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,67 @@ | ||
// 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.calendar.prototype.dateuntil | ||
description: > | ||
RangeError thrown if an invalid ISO string (or syntactically valid ISO string | ||
that is not supported) is used as a %%%conversion_target%%% | ||
features: [Temporal, arrow-function] | ||
---*/ | ||
|
||
const invalidStrings = [ | ||
// invalid ISO strings: | ||
"", | ||
"invalid iso8601", | ||
"2020-01-00", | ||
"2020-01-32", | ||
"2020-02-30", | ||
"2021-02-29", | ||
"2020-00-01", | ||
"2020-13-01", | ||
"2020-01-01T", | ||
"2020-01-01T25:00:00", | ||
"2020-01-01T01:60:00", | ||
"2020-01-01T01:60:61", | ||
"2020-01-01junk", | ||
"2020-01-01T00:00:00junk", | ||
"2020-01-01T00:00:00+00:00junk", | ||
"2020-01-01T00:00:00+00:00[UTC]junk", | ||
"2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", | ||
"02020-01-01", | ||
"2020-001-01", | ||
"2020-01-001", | ||
"2020-01-01T001", | ||
"2020-01-01T01:001", | ||
"2020-01-01T01:01:001", | ||
// valid, but forms not supported in Temporal: | ||
"2020-W01-1", | ||
"2020-001", | ||
"+0002020-01-01", | ||
// valid, but this calendar must not exist: | ||
"2020-01-01[u-ca=notexist]", | ||
// may be valid in other contexts, but insufficient information for PlainDate: | ||
"2020-01", | ||
"+002020-01", | ||
"01-01", | ||
"2020-W01", | ||
"P1Y", | ||
"-P12Y", | ||
// valid, but outside the supported range: | ||
"-999999-01-01", | ||
"+999999-01-01", | ||
]; | ||
const instance = new Temporal.Calendar("iso8601"); | ||
const other = new Temporal.PlainDate(2020, 1, 1, instance); | ||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.dateUntil(arg, other), | ||
`"${arg}" should not be a valid ISO string for a PlainDate (first argument)` | ||
); | ||
assert.throws( | ||
RangeError, | ||
() => instance.dateUntil(other, arg), | ||
`"${arg}" should not be a valid ISO string for a PlainDate (second argument)` | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
test/built-ins/Temporal/Calendar/prototype/day/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,61 @@ | ||
// 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.calendar.prototype.day | ||
description: > | ||
RangeError thrown if an invalid ISO string (or syntactically valid ISO string | ||
that is not supported) is used as a PlainDate | ||
features: [Temporal, arrow-function] | ||
---*/ | ||
|
||
const invalidStrings = [ | ||
// invalid ISO strings: | ||
"", | ||
"invalid iso8601", | ||
"2020-01-00", | ||
"2020-01-32", | ||
"2020-02-30", | ||
"2021-02-29", | ||
"2020-00-01", | ||
"2020-13-01", | ||
"2020-01-01T", | ||
"2020-01-01T25:00:00", | ||
"2020-01-01T01:60:00", | ||
"2020-01-01T01:60:61", | ||
"2020-01-01junk", | ||
"2020-01-01T00:00:00junk", | ||
"2020-01-01T00:00:00+00:00junk", | ||
"2020-01-01T00:00:00+00:00[UTC]junk", | ||
"2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", | ||
"02020-01-01", | ||
"2020-001-01", | ||
"2020-01-001", | ||
"2020-01-01T001", | ||
"2020-01-01T01:001", | ||
"2020-01-01T01:01:001", | ||
// valid, but forms not supported in Temporal: | ||
"2020-W01-1", | ||
"2020-001", | ||
"+0002020-01-01", | ||
// valid, but this calendar must not exist: | ||
"2020-01-01[u-ca=notexist]", | ||
// may be valid in other contexts, but insufficient information for PlainDate: | ||
"2020-01", | ||
"+002020-01", | ||
"01-01", | ||
"2020-W01", | ||
"P1Y", | ||
"-P12Y", | ||
// valid, but outside the supported range: | ||
"-999999-01-01", | ||
"+999999-01-01", | ||
]; | ||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.day(arg), | ||
`"${arg}" should not be a valid ISO string for a PlainDate` | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
test/built-ins/Temporal/Calendar/prototype/dayOfWeek/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,61 @@ | ||
// 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.calendar.prototype.dayofweek | ||
description: > | ||
RangeError thrown if an invalid ISO string (or syntactically valid ISO string | ||
that is not supported) is used as a PlainDate | ||
features: [Temporal, arrow-function] | ||
---*/ | ||
|
||
const invalidStrings = [ | ||
// invalid ISO strings: | ||
"", | ||
"invalid iso8601", | ||
"2020-01-00", | ||
"2020-01-32", | ||
"2020-02-30", | ||
"2021-02-29", | ||
"2020-00-01", | ||
"2020-13-01", | ||
"2020-01-01T", | ||
"2020-01-01T25:00:00", | ||
"2020-01-01T01:60:00", | ||
"2020-01-01T01:60:61", | ||
"2020-01-01junk", | ||
"2020-01-01T00:00:00junk", | ||
"2020-01-01T00:00:00+00:00junk", | ||
"2020-01-01T00:00:00+00:00[UTC]junk", | ||
"2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", | ||
"02020-01-01", | ||
"2020-001-01", | ||
"2020-01-001", | ||
"2020-01-01T001", | ||
"2020-01-01T01:001", | ||
"2020-01-01T01:01:001", | ||
// valid, but forms not supported in Temporal: | ||
"2020-W01-1", | ||
"2020-001", | ||
"+0002020-01-01", | ||
// valid, but this calendar must not exist: | ||
"2020-01-01[u-ca=notexist]", | ||
// may be valid in other contexts, but insufficient information for PlainDate: | ||
"2020-01", | ||
"+002020-01", | ||
"01-01", | ||
"2020-W01", | ||
"P1Y", | ||
"-P12Y", | ||
// valid, but outside the supported range: | ||
"-999999-01-01", | ||
"+999999-01-01", | ||
]; | ||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.dayOfWeek(arg), | ||
`"${arg}" should not be a valid ISO string for a PlainDate` | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
test/built-ins/Temporal/Calendar/prototype/dayOfYear/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,61 @@ | ||
// 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.calendar.prototype.dayofyear | ||
description: > | ||
RangeError thrown if an invalid ISO string (or syntactically valid ISO string | ||
that is not supported) is used as a PlainDate | ||
features: [Temporal, arrow-function] | ||
---*/ | ||
|
||
const invalidStrings = [ | ||
// invalid ISO strings: | ||
"", | ||
"invalid iso8601", | ||
"2020-01-00", | ||
"2020-01-32", | ||
"2020-02-30", | ||
"2021-02-29", | ||
"2020-00-01", | ||
"2020-13-01", | ||
"2020-01-01T", | ||
"2020-01-01T25:00:00", | ||
"2020-01-01T01:60:00", | ||
"2020-01-01T01:60:61", | ||
"2020-01-01junk", | ||
"2020-01-01T00:00:00junk", | ||
"2020-01-01T00:00:00+00:00junk", | ||
"2020-01-01T00:00:00+00:00[UTC]junk", | ||
"2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", | ||
"02020-01-01", | ||
"2020-001-01", | ||
"2020-01-001", | ||
"2020-01-01T001", | ||
"2020-01-01T01:001", | ||
"2020-01-01T01:01:001", | ||
// valid, but forms not supported in Temporal: | ||
"2020-W01-1", | ||
"2020-001", | ||
"+0002020-01-01", | ||
// valid, but this calendar must not exist: | ||
"2020-01-01[u-ca=notexist]", | ||
// may be valid in other contexts, but insufficient information for PlainDate: | ||
"2020-01", | ||
"+002020-01", | ||
"01-01", | ||
"2020-W01", | ||
"P1Y", | ||
"-P12Y", | ||
// valid, but outside the supported range: | ||
"-999999-01-01", | ||
"+999999-01-01", | ||
]; | ||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.dayOfYear(arg), | ||
`"${arg}" should not be a valid ISO string for a PlainDate` | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
test/built-ins/Temporal/Calendar/prototype/daysInMonth/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,61 @@ | ||
// 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.calendar.prototype.daysinmonth | ||
description: > | ||
RangeError thrown if an invalid ISO string (or syntactically valid ISO string | ||
that is not supported) is used as a PlainDate | ||
features: [Temporal, arrow-function] | ||
---*/ | ||
|
||
const invalidStrings = [ | ||
// invalid ISO strings: | ||
"", | ||
"invalid iso8601", | ||
"2020-01-00", | ||
"2020-01-32", | ||
"2020-02-30", | ||
"2021-02-29", | ||
"2020-00-01", | ||
"2020-13-01", | ||
"2020-01-01T", | ||
"2020-01-01T25:00:00", | ||
"2020-01-01T01:60:00", | ||
"2020-01-01T01:60:61", | ||
"2020-01-01junk", | ||
"2020-01-01T00:00:00junk", | ||
"2020-01-01T00:00:00+00:00junk", | ||
"2020-01-01T00:00:00+00:00[UTC]junk", | ||
"2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", | ||
"02020-01-01", | ||
"2020-001-01", | ||
"2020-01-001", | ||
"2020-01-01T001", | ||
"2020-01-01T01:001", | ||
"2020-01-01T01:01:001", | ||
// valid, but forms not supported in Temporal: | ||
"2020-W01-1", | ||
"2020-001", | ||
"+0002020-01-01", | ||
// valid, but this calendar must not exist: | ||
"2020-01-01[u-ca=notexist]", | ||
// may be valid in other contexts, but insufficient information for PlainDate: | ||
"2020-01", | ||
"+002020-01", | ||
"01-01", | ||
"2020-W01", | ||
"P1Y", | ||
"-P12Y", | ||
// valid, but outside the supported range: | ||
"-999999-01-01", | ||
"+999999-01-01", | ||
]; | ||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.daysInMonth(arg), | ||
`"${arg}" should not be a valid ISO string for a PlainDate` | ||
); | ||
} |
Oops, something went wrong.