Skip to content

Commit

Permalink
Expand overflow-invalid-string.js tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger authored and ptomato committed Mar 25, 2022
1 parent 7b78d4b commit f964584
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ features: [Temporal, arrow-function]
const calendar = new Temporal.Calendar("iso8601");
const date = new Temporal.PlainDate(2000, 5, 2, calendar);
const duration = new Temporal.Duration(3, 3, 0, 3);
assert.throws(RangeError,
() => calendar.dateAdd(date, duration, { overflow: "other string" }),
"Value for overflow not one of the allowed string values");
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => calendar.dateAdd(date, duration, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ features: [Temporal, arrow-function]
---*/

const calendar = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => calendar.dateFromFields({ year: 2000, month: 5, day: 2 },
{ overflow: "other string" }),
"Value for overflow not one of the allowed string values");
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => calendar.dateFromFields({ year: 2000, month: 5, day: 2 },
{ overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ features: [Temporal]
---*/

const calendar = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => calendar.monthDayFromFields({ year: 2000, month: 5, day: 2 }, { overflow: "other string" }));
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => calendar.monthDayFromFields({ year: 2000, month: 5, day: 2 }, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ features: [Temporal]
---*/

const calendar = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => calendar.yearMonthFromFields({ year: 2000, month: 5 }, { overflow: "other string" }));
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => calendar.yearMonthFromFields({ year: 2000, month: 5 }, { overflow }),
`invalid overflow ("${overflow}")`
);
}
16 changes: 11 additions & 5 deletions test/built-ins/Temporal/PlainDate/from/overflow-invalid-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ const invalidOverflow = [
"CONSTRAIN",
"constra\u0131n",
];
validItems.forEach((item) => {
invalidOverflow.forEach((overflow) => {
assert.throws(RangeError, () => Temporal.PlainDate.from(item, { overflow }));
});
});

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const item of validItems) {
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => Temporal.PlainDate.from(item, { overflow }),
`invalid overflow ("${overflow}")`
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ features: [Temporal]

const date = new Temporal.PlainDate(2000, 5, 2);
const duration = new Temporal.Duration(3, 3, 0, 3);
for (const overflow of ["", "CONSTRAIN", "balance", "other string", "constra\u0131n"]) {
assert.throws(RangeError, () => date.add(duration, { overflow }));

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => date.add(duration, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ features: [Temporal]

const date = new Temporal.PlainDate(2000, 5, 2);
const duration = new Temporal.Duration(3, 3, 0, 3);
for (const overflow of ["", "CONSTRAIN", "balance", "other string", "constra\u0131n"]) {
assert.throws(RangeError, () => date.subtract(duration, { overflow }));

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => date.subtract(duration, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ features: [Temporal]
---*/

const date = new Temporal.PlainDate(2000, 5, 2);
["", "CONSTRAIN", "balance", "other string"].forEach((overflow) =>
assert.throws(RangeError, () => date.with({ month: 8 }, { overflow }))
);

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => date.with({ month: 8 }, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const validValues = [
{ year: 2000, month: 5, day: 2, hour: 12 },
"2000-05-02T12:00",
];
validValues.forEach((value) => {
assert.throws(RangeError, () => Temporal.PlainDateTime.from(value, { overflow: "other string" }));
});

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const value of validValues) {
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => Temporal.PlainDateTime.from(value, { overflow }),
`invalid overflow ("${overflow}")`
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ features: [Temporal]
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12);
const duration = new Temporal.Duration(3, 3, 0, 3, 3);

const badOverflows = ['', 'CONSTRAIN', 'balance', "other string"];
badOverflows.forEach((overflow) => {

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => datetime.add({ months: 1 }, { overflow }),
`invalid overflow ("${overflow}")`
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ features: [Temporal]

const date = new Temporal.PlainDateTime(2000, 5, 2, 12);
const duration = new Temporal.Duration(3, 3, 0, 3, 3);
assert.throws(RangeError, () => date.subtract(duration, { overflow: "other string" }));
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => date.subtract(duration, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ features: [Temporal]
---*/

const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12);
const badOverflows = ["", "CONSTRAIN", "balance", "other string"];
badOverflows.forEach((overflow) => {

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => datetime.with({ minute: 45 }, { overflow }),
`invalid overflow string (${overflow})`);
});
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const validValues = [
{ monthCode: "M05", day: 2 },
"05-02",
];
validValues.forEach((value) => {
assert.throws(RangeError, () => Temporal.PlainMonthDay.from(value, { overflow: "other string" }));
});

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const value of validValues) {
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => Temporal.PlainMonthDay.from(value, { overflow }),
`invalid overflow ("${overflow}")`
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ features: [Temporal]
---*/

const monthday = new Temporal.PlainMonthDay(5, 2);
for (const overflow of ["", "CONSTRAIN", "balance", "other string", "constra\u0131n"]) {
assert.throws(RangeError, () => monthday.with({ day: 8 }, { overflow }));

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => monthday.with({ day: 8 }, { overflow }),
`invalid overflow ("${overflow}")`
);
}
16 changes: 11 additions & 5 deletions test/built-ins/Temporal/PlainTime/from/overflow-invalid-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ const validValues = [
{ hour: 12 },
"12:00",
];
validValues.forEach((value) => {
["", "CONSTRAIN", "balance", "other string", "constra\u0131n"].forEach((overflow) => {
assert.throws(RangeError, () => Temporal.PlainTime.from(value, { overflow }));
});
});

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const value of validValues) {
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => Temporal.PlainTime.from(value, { overflow }),
`invalid overflow ("${overflow}")`
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ features: [Temporal]

const time = new Temporal.PlainTime(12);
const values = ["", "CONSTRAIN", "balance", "other string"];
for (const overflow of values) {
assert.throws(RangeError, () => time.with({ minute: 45 }, { overflow }));

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => time.with({ minute: 45 }, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ const validValues = [
{ year: 2000, month: 5 },
"2000-05",
];
validValues.forEach((value) => {
["", "CONSTRAIN", "balance", "other string", "constra\u0131n"].forEach((overflow) => {
assert.throws(RangeError, () => Temporal.PlainYearMonth.from(value, { overflow }));
});
});

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const value of validValues) {
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => Temporal.PlainYearMonth.from(value, { overflow }),
`invalid overflow ("${overflow}")`
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ features: [Temporal]

const yearmonth = new Temporal.PlainYearMonth(2000, 5);
const duration = new Temporal.Duration(1, 1);
for (const overflow of ["", "CONSTRAIN", "balance", "other string", "constra\u0131n"]) {
assert.throws(RangeError, () => yearmonth.add(duration, { overflow }));

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => yearmonth.add(duration, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ features: [Temporal]

const yearmonth = new Temporal.PlainYearMonth(2000, 5);
const duration = new Temporal.Duration(1, 1);
for (const overflow of ["", "CONSTRAIN", "balance", "other string", "constra\u0131n"]) {
assert.throws(RangeError, () => yearmonth.subtract(duration, { overflow }));

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => yearmonth.subtract(duration, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ features: [Temporal]
---*/

const yearmonth = new Temporal.PlainYearMonth(2000, 5);
for (const overflow of ["", "CONSTRAIN", "balance", "other string", "constra\u0131n"]) {
assert.throws(RangeError, () => yearmonth.with({ month: 8 }, { overflow }));

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => yearmonth.with({ month: 8 }, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const validValues = [
{ year: 2000, month: 5, day: 2, hour: 12, timeZone: "UTC" },
"2001-09-09T01:46:40.987654321+00:00[UTC]",
];
validValues.forEach((value) => {
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(value, { overflow: "other string" }));
});

const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const value of validValues) {
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => Temporal.ZonedDateTime.from(value, { overflow }),
`invalid overflow ("${overflow}")`
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ features: [Temporal]

const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
const duration = new Temporal.Duration(0, 0, 0, 1);
assert.throws(RangeError, () => datetime.add(duration, { overflow: "other string" }));
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => datetime.add(duration, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ features: [Temporal]

const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
const duration = new Temporal.Duration(0, 0, 0, 1);
assert.throws(RangeError, () => datetime.subtract(duration, { overflow: "other string" }));
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => datetime.subtract(duration, { overflow }),
`invalid overflow ("${overflow}")`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ features: [Temporal]
---*/

const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
assert.throws(RangeError, () => datetime.with({ minute: 45 }, { overflow: "other string" }));
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => datetime.with({ minute: 45 }, { overflow }),
`invalid overflow ("${overflow}")`
);
}

0 comments on commit f964584

Please sign in to comment.