Skip to content

Commit

Permalink
Bring existing "invalid string" tests for smallestUnit and largestUni…
Browse files Browse the repository at this point in the history
…t in sync

Add a consistent set of invalid strings for all of the
smallestunit-invalid-string.js and largestunit-invalid-string.js tests:
- "era" and "eraYear" in singular and plural
- all of the units that are disallowed for that particular method call, in
  singular and plural
- an allowed unit with \0 at the end
- an allowed unit with an "i" replaced by a dotless i
- an allowed unit but with all-caps
- an unrelated string.
  • Loading branch information
ptomato authored and Ms2ger committed Apr 13, 2022
1 parent b4c0aed commit 9b2c98c
Show file tree
Hide file tree
Showing 34 changed files with 791 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@ features: [Temporal]
---*/

const duration = new Temporal.Duration(0, 0, 0, 0, 12, 34, 56, 123, 987, 500);
assert.throws(RangeError, () => duration.round({ smallestUnit: "other string" }));
const badValues = [
"era",
"eraYear",
"millisecond\0",
"mill\u0131second",
"SECOND",
"eras",
"eraYears",
"milliseconds\0",
"mill\u0131seconds",
"SECONDS",
"other string",
];
for (const smallestUnit of badValues) {
assert.throws(RangeError, () => duration.round({ smallestUnit }),
`"${smallestUnit}" is not a valid value for smallest unit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,32 @@ features: [Temporal]
---*/

const duration = new Temporal.Duration(0, 0, 0, 0, 12, 34, 56, 123, 987, 500);
const values = ["eras", "years", "months", "weeks", "days", "hours", "minutes", "nonsense", "other string", "mill\u0131seconds", "SECONDS"];
for (const smallestUnit of values) {
assert.throws(RangeError, () => duration.toString({ smallestUnit }));
const badValues = [
"era",
"eraYear",
"year",
"month",
"week",
"day",
"hour",
"minute",
"millisecond\0",
"mill\u0131second",
"SECOND",
"eras",
"eraYears",
"years",
"months",
"weeks",
"days",
"hours",
"minutes",
"milliseconds\0",
"mill\u0131seconds",
"SECONDS",
"other string",
];
for (const smallestUnit of badValues) {
assert.throws(RangeError, () => duration.toString({ smallestUnit }),
`"${smallestUnit}" is not a valid value for smallest unit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,28 @@ features: [Temporal]
---*/

const instant = new Temporal.Instant(1_000_000_000_123_987_500n);
assert.throws(RangeError, () => instant.round({ smallestUnit: "other string" }));
const badValues = [
"era",
"eraYear",
"year",
"month",
"week",
"day",
"millisecond\0",
"mill\u0131second",
"SECOND",
"eras",
"eraYears",
"years",
"months",
"weeks",
"days",
"milliseconds\0",
"mill\u0131seconds",
"SECONDS",
"other string",
];
for (const smallestUnit of badValues) {
assert.throws(RangeError, () => instant.round({ smallestUnit }),
`"${smallestUnit}" is not a valid value for smallest unit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ features: [Temporal]

const earlier = new Temporal.Instant(1_000_000_000_000_000_000n);
const later = new Temporal.Instant(1_000_090_061_987_654_321n);
const values = ["era", "eraYear", "years", "months", "weeks", "days", "other string"];
for (const largestUnit of values) {
assert.throws(RangeError, () => later.since(earlier, { largestUnit }));
const badValues = [
"era",
"eraYear",
"year",
"month",
"week",
"day",
"millisecond\0",
"mill\u0131second",
"SECOND",
"eras",
"eraYears",
"years",
"months",
"weeks",
"days",
"milliseconds\0",
"mill\u0131seconds",
"SECONDS",
"other string"
];
for (const largestUnit of badValues) {
assert.throws(RangeError, () => later.since(earlier, { largestUnit }),
`"${largestUnit}" is not a valid value for largestUnit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ features: [Temporal]

const earlier = new Temporal.Instant(1_000_000_000_000_000_000n);
const later = new Temporal.Instant(1_000_090_061_987_654_321n);
const values = ["era", "eraYear", "years", "months", "weeks", "days", "other string"];
for (const smallestUnit of values) {
assert.throws(RangeError, () => later.since(earlier, { smallestUnit }));
const badValues = [
"era",
"eraYear",
"year",
"month",
"week",
"day",
"millisecond\0",
"mill\u0131second",
"SECOND",
"eras",
"eraYears",
"years",
"months",
"weeks",
"days",
"milliseconds\0",
"mill\u0131seconds",
"SECONDS",
"other string",
];
for (const smallestUnit of badValues) {
assert.throws(RangeError, () => later.since(earlier, { smallestUnit }),
`"${smallestUnit}" is not a valid value for smallest unit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,30 @@ features: [Temporal]
---*/

const instant = new Temporal.Instant(1_000_000_000_123_987_500n);
assert.throws(RangeError, () => instant.toString({ smallestUnit: "other string" }));
const badValues = [
"era",
"eraYear",
"year",
"month",
"week",
"day",
"hour",
"millisecond\0",
"mill\u0131second",
"SECOND",
"eras",
"eraYears",
"years",
"months",
"weeks",
"days",
"hours",
"milliseconds\0",
"mill\u0131seconds",
"SECONDS",
"other string",
];
for (const smallestUnit of badValues) {
assert.throws(RangeError, () => instant.toString({ smallestUnit }),
`"${smallestUnit}" is not a valid value for smallest unit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ features: [Temporal]

const earlier = new Temporal.Instant(1_000_000_000_000_000_000n);
const later = new Temporal.Instant(1_000_090_061_987_654_321n);
const values = ["era", "eraYear", "years", "months", "weeks", "days", "other string"];
for (const largestUnit of values) {
assert.throws(RangeError, () => earlier.until(later, { largestUnit }));
const badValues = [
"era",
"eraYear",
"year",
"month",
"week",
"day",
"millisecond\0",
"mill\u0131second",
"SECOND",
"eras",
"eraYears",
"years",
"months",
"weeks",
"days",
"milliseconds\0",
"mill\u0131seconds",
"SECONDS",
"other string"
];
for (const largestUnit of badValues) {
assert.throws(RangeError, () => earlier.until(later, { largestUnit }),
`"${largestUnit}" is not a valid value for largestUnit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ features: [Temporal]

const earlier = new Temporal.Instant(1_000_000_000_000_000_000n);
const later = new Temporal.Instant(1_000_090_061_987_654_321n);
const values = ["era", "eraYear", "years", "months", "weeks", "days", "other string"];
for (const smallestUnit of values) {
assert.throws(RangeError, () => earlier.until(later, { smallestUnit }));
const badValues = [
"era",
"eraYear",
"year",
"month",
"week",
"day",
"millisecond\0",
"mill\u0131second",
"SECOND",
"eras",
"eraYears",
"years",
"months",
"weeks",
"days",
"milliseconds\0",
"mill\u0131seconds",
"SECONDS",
"other string",
];
for (const smallestUnit of badValues) {
assert.throws(RangeError, () => earlier.until(later, { smallestUnit }),
`"${smallestUnit}" is not a valid value for smallest unit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ features: [Temporal]

const earlier = new Temporal.PlainDate(2000, 5, 2);
const later = new Temporal.PlainDate(2001, 6, 3);
const values = ["era", "eraYear", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds", "other string"];
for (const largestUnit of values) {
assert.throws(RangeError, () => later.since(earlier, { largestUnit }));
const badValues = [
"era",
"eraYear",
"hour",
"minute",
"second",
"millisecond",
"microsecond",
"nanosecond",
"month\0",
"YEAR",
"eras",
"eraYears",
"hours",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds",
"months\0",
"YEARS",
"other string"
];
for (const largestUnit of badValues) {
assert.throws(RangeError, () => later.since(earlier, { largestUnit }),
`"${largestUnit}" is not a valid value for largestUnit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ features: [Temporal]

const earlier = new Temporal.PlainDate(2000, 5, 2);
const later = new Temporal.PlainDate(2001, 6, 3);
const values = ["era", "eraYear", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds", "other string"];
for (const smallestUnit of values) {
assert.throws(RangeError, () => later.since(earlier, { smallestUnit }));
const badValues = [
"era",
"eraYear",
"hour",
"minute",
"second",
"millisecond",
"microsecond",
"nanosecond",
"month\0",
"YEAR",
"eras",
"eraYears",
"hours",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds",
"months\0",
"YEARS",
"other string",
];
for (const smallestUnit of badValues) {
assert.throws(RangeError, () => later.since(earlier, { smallestUnit }),
`"${smallestUnit}" is not a valid value for smallest unit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ features: [Temporal]

const earlier = new Temporal.PlainDate(2000, 5, 2);
const later = new Temporal.PlainDate(2001, 6, 3);
const values = ["era", "eraYear", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds", "other string"];
for (const largestUnit of values) {
assert.throws(RangeError, () => earlier.until(later, { largestUnit }));
const badValues = [
"era",
"eraYear",
"hour",
"minute",
"second",
"millisecond",
"microsecond",
"nanosecond",
"month\0",
"YEAR",
"eras",
"eraYears",
"hours",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds",
"months\0",
"YEARS",
"other string"
];
for (const largestUnit of badValues) {
assert.throws(RangeError, () => earlier.until(later, { largestUnit }),
`"${largestUnit}" is not a valid value for largestUnit`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ features: [Temporal]

const earlier = new Temporal.PlainDate(2000, 5, 2);
const later = new Temporal.PlainDate(2001, 6, 3);
const values = ["era", "eraYear", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds", "other string"];
for (const smallestUnit of values) {
assert.throws(RangeError, () => earlier.until(later, { smallestUnit }));
const badValues = [
"era",
"eraYear",
"hour",
"minute",
"second",
"millisecond",
"microsecond",
"nanosecond",
"month\0",
"YEAR",
"eras",
"eraYears",
"hours",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds",
"months\0",
"YEARS",
"other string",
];
for (const smallestUnit of badValues) {
assert.throws(RangeError, () => earlier.until(later, { smallestUnit }),
`"${smallestUnit}" is not a valid value for smallest unit`);
}
Loading

0 comments on commit 9b2c98c

Please sign in to comment.