mirror of https://github.com/tc39/test262.git
Temporal: Move more collections of valid/invalid strings into TemporalHelpers
The idea is to deduplicate more string tests into methods on this object, that return collections of valid and invalid strings. This adds collections of valid and invalid PlainYearMonth and PlainMonthDay strings.
This commit is contained in:
parent
10ac2ad03e
commit
d1b16d7d0e
|
@ -1798,6 +1798,47 @@ var TemporalHelpers = {
|
|||
* testing parsers.
|
||||
*/
|
||||
ISO: {
|
||||
/*
|
||||
* PlainMonthDay strings that are not valid.
|
||||
*/
|
||||
plainMonthDayStringsInvalid() {
|
||||
return [
|
||||
"11-18junk",
|
||||
];
|
||||
},
|
||||
|
||||
/*
|
||||
* PlainMonthDay strings that are valid and that should produce October 1st.
|
||||
*/
|
||||
plainMonthDayStringsValid() {
|
||||
return [
|
||||
"10-01",
|
||||
"1001",
|
||||
"1965-10-01",
|
||||
"1976-10-01T152330.1+00:00",
|
||||
"19761001T15:23:30.1+00:00",
|
||||
"1976-10-01T15:23:30.1+0000",
|
||||
"1976-10-01T152330.1+0000",
|
||||
"19761001T15:23:30.1+0000",
|
||||
"19761001T152330.1+00:00",
|
||||
"19761001T152330.1+0000",
|
||||
"+001976-10-01T152330.1+00:00",
|
||||
"+0019761001T15:23:30.1+00:00",
|
||||
"+001976-10-01T15:23:30.1+0000",
|
||||
"+001976-10-01T152330.1+0000",
|
||||
"+0019761001T15:23:30.1+0000",
|
||||
"+0019761001T152330.1+00:00",
|
||||
"+0019761001T152330.1+0000",
|
||||
"1976-10-01T15:23:00",
|
||||
"1976-10-01T15:23",
|
||||
"1976-10-01T15",
|
||||
"1976-10-01",
|
||||
"--10-01",
|
||||
"--1001",
|
||||
1001,
|
||||
];
|
||||
},
|
||||
|
||||
/*
|
||||
* PlainTime strings that may be mistaken for PlainMonthDay or
|
||||
* PlainYearMonth strings, and so require a time designator.
|
||||
|
@ -1842,6 +1883,58 @@ var TemporalHelpers = {
|
|||
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
|
||||
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
|
||||
];
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* PlainYearMonth-like strings that are not valid.
|
||||
*/
|
||||
plainYearMonthStringsInvalid() {
|
||||
return [
|
||||
"2020-13",
|
||||
];
|
||||
},
|
||||
|
||||
/*
|
||||
* PlainYearMonth-like strings that are valid and should produce November
|
||||
* 1976 in the ISO 8601 calendar.
|
||||
*/
|
||||
plainYearMonthStringsValid() {
|
||||
return [
|
||||
"1976-11",
|
||||
"1976-11-10",
|
||||
"1976-11-01T09:00:00+00:00",
|
||||
"1976-11-01T00:00:00+05:00",
|
||||
"197611",
|
||||
"+00197611",
|
||||
"1976-11-18T15:23:30.1\u221202:00",
|
||||
"1976-11-18T152330.1+00:00",
|
||||
"19761118T15:23:30.1+00:00",
|
||||
"1976-11-18T15:23:30.1+0000",
|
||||
"1976-11-18T152330.1+0000",
|
||||
"19761118T15:23:30.1+0000",
|
||||
"19761118T152330.1+00:00",
|
||||
"19761118T152330.1+0000",
|
||||
"+001976-11-18T152330.1+00:00",
|
||||
"+0019761118T15:23:30.1+00:00",
|
||||
"+001976-11-18T15:23:30.1+0000",
|
||||
"+001976-11-18T152330.1+0000",
|
||||
"+0019761118T15:23:30.1+0000",
|
||||
"+0019761118T152330.1+00:00",
|
||||
"+0019761118T152330.1+0000",
|
||||
"1976-11-18T15:23",
|
||||
"1976-11-18T15",
|
||||
"1976-11-18",
|
||||
];
|
||||
},
|
||||
|
||||
/*
|
||||
* PlainYearMonth-like strings that are valid and should produce November of
|
||||
* the ISO year -9999.
|
||||
*/
|
||||
plainYearMonthStringsValidNegativeYear() {
|
||||
return [
|
||||
"\u2212009999-11",
|
||||
];
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,39 +8,13 @@ includes: [compareArray.js, temporalHelpers.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
"10-01",
|
||||
"1001",
|
||||
"1965-10-01",
|
||||
"1976-10-01T152330.1+00:00",
|
||||
"19761001T15:23:30.1+00:00",
|
||||
"1976-10-01T15:23:30.1+0000",
|
||||
"1976-10-01T152330.1+0000",
|
||||
"19761001T15:23:30.1+0000",
|
||||
"19761001T152330.1+00:00",
|
||||
"19761001T152330.1+0000",
|
||||
"+001976-10-01T152330.1+00:00",
|
||||
"+0019761001T15:23:30.1+00:00",
|
||||
"+001976-10-01T15:23:30.1+0000",
|
||||
"+001976-10-01T152330.1+0000",
|
||||
"+0019761001T15:23:30.1+0000",
|
||||
"+0019761001T152330.1+00:00",
|
||||
"+0019761001T152330.1+0000",
|
||||
"1976-10-01T15:23:00",
|
||||
"1976-10-01T15:23",
|
||||
"1976-10-01T15",
|
||||
"1976-10-01",
|
||||
"--10-01",
|
||||
"--1001",
|
||||
1001,
|
||||
];
|
||||
|
||||
for (const argument of tests) {
|
||||
for (const argument of TemporalHelpers.ISO.plainMonthDayStringsValid()) {
|
||||
const plainMonthDay = Temporal.PlainMonthDay.from(argument);
|
||||
assert.notSameValue(plainMonthDay, argument, `from ${argument} converts`);
|
||||
TemporalHelpers.assertPlainMonthDay(plainMonthDay, "M10", 1, `from ${argument}`);
|
||||
assert.sameValue(plainMonthDay.calendar.id, "iso8601", `from ${argument} calendar`);
|
||||
}
|
||||
|
||||
assert.throws(RangeError, () => Temporal.PlainMonthDay.from("11-18junk"), "no junk at end of string");
|
||||
|
||||
for (const arg of TemporalHelpers.ISO.plainMonthDayStringsInvalid()) {
|
||||
assert.throws(RangeError, () => Temporal.PlainMonthDay.from(arg), `"${arg}" not a valid PlainMonthDay string`);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,11 @@
|
|||
/*---
|
||||
esid: sec-temporal.plainyearmonth.from
|
||||
description: An invalid ISO string is never supported
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.throws(RangeError, () => Temporal.PlainYearMonth.from("2020-13", { overflow: "reject" }));
|
||||
assert.throws(RangeError, () => Temporal.PlainYearMonth.from("2020-13", { overflow: "constrain" }));
|
||||
for (const input of TemporalHelpers.ISO.plainYearMonthStringsInvalid()) {
|
||||
assert.throws(RangeError, () => Temporal.PlainYearMonth.from(input, { overflow: "reject" }));
|
||||
assert.throws(RangeError, () => Temporal.PlainYearMonth.from(input, { overflow: "constrain" }));
|
||||
}
|
||||
|
|
|
@ -8,34 +8,7 @@ includes: [temporalHelpers.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const inputs = [
|
||||
"1976-11",
|
||||
"1976-11-10",
|
||||
"1976-11-01T09:00:00+00:00",
|
||||
"1976-11-01T00:00:00+05:00",
|
||||
"197611",
|
||||
"+00197611",
|
||||
"1976-11-18T15:23:30.1\u221202:00",
|
||||
"1976-11-18T152330.1+00:00",
|
||||
"19761118T15:23:30.1+00:00",
|
||||
"1976-11-18T15:23:30.1+0000",
|
||||
"1976-11-18T152330.1+0000",
|
||||
"19761118T15:23:30.1+0000",
|
||||
"19761118T152330.1+00:00",
|
||||
"19761118T152330.1+0000",
|
||||
"+001976-11-18T152330.1+00:00",
|
||||
"+0019761118T15:23:30.1+00:00",
|
||||
"+001976-11-18T15:23:30.1+0000",
|
||||
"+001976-11-18T152330.1+0000",
|
||||
"+0019761118T15:23:30.1+0000",
|
||||
"+0019761118T152330.1+00:00",
|
||||
"+0019761118T152330.1+0000",
|
||||
"1976-11-18T15:23",
|
||||
"1976-11-18T15",
|
||||
"1976-11-18",
|
||||
];
|
||||
|
||||
for (const input of inputs) {
|
||||
for (const input of TemporalHelpers.ISO.plainYearMonthStringsValid()) {
|
||||
const plainYearMonth = Temporal.PlainYearMonth.from(input);
|
||||
TemporalHelpers.assertPlainYearMonth(plainYearMonth, 1976, 11, "M11");
|
||||
const fields = plainYearMonth.getISOFields();
|
||||
|
@ -45,11 +18,13 @@ for (const input of inputs) {
|
|||
assert.sameValue(fields.isoYear, 1976, "isoYear");
|
||||
}
|
||||
|
||||
const plainYearMonth = Temporal.PlainYearMonth.from("\u2212009999-11");
|
||||
TemporalHelpers.assertPlainYearMonth(plainYearMonth, -9999, 11, "M11");
|
||||
const fields = plainYearMonth.getISOFields();
|
||||
assert.sameValue(fields.calendar.id, "iso8601");
|
||||
assert.sameValue(fields.isoDay, 1, "isoDay");
|
||||
assert.sameValue(fields.isoMonth, 11, "isoMonth");
|
||||
assert.sameValue(fields.isoYear, -9999, "isoYear");
|
||||
assert.sameValue(plainYearMonth.toString(), "-009999-11");
|
||||
for (const input of TemporalHelpers.ISO.plainYearMonthStringsValidNegativeYear()) {
|
||||
const plainYearMonth = Temporal.PlainYearMonth.from(input);
|
||||
TemporalHelpers.assertPlainYearMonth(plainYearMonth, -9999, 11, "M11");
|
||||
const fields = plainYearMonth.getISOFields();
|
||||
assert.sameValue(fields.calendar.id, "iso8601");
|
||||
assert.sameValue(fields.isoDay, 1, "isoDay");
|
||||
assert.sameValue(fields.isoMonth, 11, "isoMonth");
|
||||
assert.sameValue(fields.isoYear, -9999, "isoYear");
|
||||
assert.sameValue(plainYearMonth.toString(), "-009999-11");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue