Temporal: Deduplicate strings-with-calendar from strings-without-calendar

The strings with calendar annotations in these tests don't need to be
listed separately, they can be derived from the original strings.
This commit is contained in:
Philip Chimento 2022-08-17 12:34:48 -07:00 committed by Philip Chimento
parent 409d6dc71a
commit ddef61a106
9 changed files with 191 additions and 227 deletions

View File

@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month "1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU "12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS "202112", // ambiguity between YYYYMM and HHMMSS
// same strings as above but with a calendar annotation, which must not cause
// disambiguation in favour of time
"2021-12[u-ca=iso8601]",
"1214[u-ca=iso8601]",
"0229[u-ca=iso8601]",
"1130[u-ca=iso8601]",
"12-14[u-ca=iso8601]",
"202112[u-ca=iso8601]",
]; ];
ambiguousStrings.forEach((string) => { ambiguousStrings.forEach((stringWithoutCalendar) => {
let arg = string; // calendar annotation must not cause disambiguation in favour of time
assert.throws( const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
RangeError, [stringWithoutCalendar, stringWithCalendar].forEach((string) => {
() => instance.toPlainDateTime(arg), let arg = string;
`${string} is ambiguous and requires T prefix` assert.throws(
); RangeError,
// The same string with a T prefix should not throw: () => instance.toPlainDateTime(arg),
arg = `T${string}`; `${string} is ambiguous and requires T prefix`
instance.toPlainDateTime(arg); );
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toPlainDateTime(arg);
arg = ` ${string}`; arg = ` ${string}`;
assert.throws( assert.throws(
RangeError, RangeError,
() => instance.toPlainDateTime(arg), () => instance.toPlainDateTime(arg),
"space is not accepted as a substitute for T prefix" "space is not accepted as a substitute for T prefix"
); );
});
}); });
// None of these should throw without a T prefix, because they are unambiguously time strings: // None of these should throw without a T prefix, because they are unambiguously time strings:

View File

@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month "1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU "12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS "202112", // ambiguity between YYYYMM and HHMMSS
// same strings as above but with a calendar annotation, which must not cause
// disambiguation in favour of time
"2021-12[u-ca=iso8601]",
"1214[u-ca=iso8601]",
"0229[u-ca=iso8601]",
"1130[u-ca=iso8601]",
"12-14[u-ca=iso8601]",
"202112[u-ca=iso8601]",
]; ];
ambiguousStrings.forEach((string) => { ambiguousStrings.forEach((stringWithoutCalendar) => {
let arg = string; // calendar annotation must not cause disambiguation in favour of time
assert.throws( const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
RangeError, [stringWithoutCalendar, stringWithCalendar].forEach((string) => {
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), let arg = string;
`${string} is ambiguous and requires T prefix` assert.throws(
); RangeError,
// The same string with a T prefix should not throw: () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
arg = `T${string}`; `${string} is ambiguous and requires T prefix`
instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }); );
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" });
arg = ` ${string}`; arg = ` ${string}`;
assert.throws( assert.throws(
RangeError, RangeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
"space is not accepted as a substitute for T prefix" "space is not accepted as a substitute for T prefix"
); );
});
}); });
// None of these should throw without a T prefix, because they are unambiguously time strings: // None of these should throw without a T prefix, because they are unambiguously time strings:

View File

@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month "1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU "12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS "202112", // ambiguity between YYYYMM and HHMMSS
// same strings as above but with a calendar annotation, which must not cause
// disambiguation in favour of time
"2021-12[u-ca=iso8601]",
"1214[u-ca=iso8601]",
"0229[u-ca=iso8601]",
"1130[u-ca=iso8601]",
"12-14[u-ca=iso8601]",
"202112[u-ca=iso8601]",
]; ];
ambiguousStrings.forEach((string) => { ambiguousStrings.forEach((stringWithoutCalendar) => {
let arg = string; // calendar annotation must not cause disambiguation in favour of time
assert.throws( const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
RangeError, [stringWithoutCalendar, stringWithCalendar].forEach((string) => {
() => instance.withPlainTime(arg), let arg = string;
`${string} is ambiguous and requires T prefix` assert.throws(
); RangeError,
// The same string with a T prefix should not throw: () => instance.withPlainTime(arg),
arg = `T${string}`; `${string} is ambiguous and requires T prefix`
instance.withPlainTime(arg); );
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.withPlainTime(arg);
arg = ` ${string}`; arg = ` ${string}`;
assert.throws( assert.throws(
RangeError, RangeError,
() => instance.withPlainTime(arg), () => instance.withPlainTime(arg),
"space is not accepted as a substitute for T prefix" "space is not accepted as a substitute for T prefix"
); );
});
}); });
// None of these should throw without a T prefix, because they are unambiguously time strings: // None of these should throw without a T prefix, because they are unambiguously time strings:

View File

@ -16,43 +16,39 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month "1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU "12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS "202112", // ambiguity between YYYYMM and HHMMSS
// same strings as above but with a calendar annotation, which must not cause
// disambiguation in favour of time
"2021-12[u-ca=iso8601]",
"1214[u-ca=iso8601]",
"0229[u-ca=iso8601]",
"1130[u-ca=iso8601]",
"12-14[u-ca=iso8601]",
"202112[u-ca=iso8601]",
]; ];
ambiguousStrings.forEach((string) => { ambiguousStrings.forEach((stringWithoutCalendar) => {
let arg = string; // calendar annotation must not cause disambiguation in favour of time
assert.throws( const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
RangeError, [stringWithoutCalendar, stringWithCalendar].forEach((string) => {
() => Temporal.PlainTime.compare(arg, midnight), let arg = string;
`${string} is ambiguous and requires T prefix (first argument)` assert.throws(
); RangeError,
assert.throws( () => Temporal.PlainTime.compare(arg, midnight),
RangeError, `${string} is ambiguous and requires T prefix (first argument)`
() => Temporal.PlainTime.compare(midnight, arg), );
`${string} is ambiguous and requires T prefix (second argument)` assert.throws(
); RangeError,
// The same string with a T prefix should not throw: () => Temporal.PlainTime.compare(midnight, arg),
arg = `T${string}`; `${string} is ambiguous and requires T prefix (second argument)`
Temporal.PlainTime.compare(arg, midnight); );
Temporal.PlainTime.compare(midnight, arg); // The same string with a T prefix should not throw:
arg = `T${string}`;
Temporal.PlainTime.compare(arg, midnight);
Temporal.PlainTime.compare(midnight, arg);
arg = ` ${string}`; arg = ` ${string}`;
assert.throws( assert.throws(
RangeError, RangeError,
() => Temporal.PlainTime.compare(arg, midnight), () => Temporal.PlainTime.compare(arg, midnight),
'space is not accepted as a substitute for T prefix (first argument)' 'space is not accepted as a substitute for T prefix (first argument)'
); );
assert.throws( assert.throws(
RangeError, RangeError,
() => Temporal.PlainTime.compare(midnight, arg), () => Temporal.PlainTime.compare(midnight, arg),
'space is not accepted as a substitute for T prefix (second argument)' 'space is not accepted as a substitute for T prefix (second argument)'
); );
});
}); });
// None of these should throw without a T prefix, because they are unambiguously time strings: // None of these should throw without a T prefix, because they are unambiguously time strings:

View File

@ -14,32 +14,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month "1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU "12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS "202112", // ambiguity between YYYYMM and HHMMSS
// same strings as above but with a calendar annotation, which must not cause
// disambiguation in favour of time
"2021-12[u-ca=iso8601]",
"1214[u-ca=iso8601]",
"0229[u-ca=iso8601]",
"1130[u-ca=iso8601]",
"12-14[u-ca=iso8601]",
"202112[u-ca=iso8601]",
]; ];
ambiguousStrings.forEach((string) => { ambiguousStrings.forEach((stringWithoutCalendar) => {
let arg = string; // calendar annotation must not cause disambiguation in favour of time
assert.throws( const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
RangeError, [stringWithoutCalendar, stringWithCalendar].forEach((string) => {
() => Temporal.PlainTime.from(arg), let arg = string;
`${string} is ambiguous and requires T prefix` assert.throws(
); RangeError,
// The same string with a T prefix should not throw: () => Temporal.PlainTime.from(arg),
arg = `T${string}`; `${string} is ambiguous and requires T prefix`
Temporal.PlainTime.from(arg); );
// The same string with a T prefix should not throw:
arg = `T${string}`;
Temporal.PlainTime.from(arg);
arg = ` ${string}`; arg = ` ${string}`;
assert.throws( assert.throws(
RangeError, RangeError,
() => Temporal.PlainTime.from(arg), () => Temporal.PlainTime.from(arg),
"space is not accepted as a substitute for T prefix" "space is not accepted as a substitute for T prefix"
); );
});
}); });
// None of these should throw without a T prefix, because they are unambiguously time strings: // None of these should throw without a T prefix, because they are unambiguously time strings:

View File

@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month "1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU "12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS "202112", // ambiguity between YYYYMM and HHMMSS
// same strings as above but with a calendar annotation, which must not cause
// disambiguation in favour of time
"2021-12[u-ca=iso8601]",
"1214[u-ca=iso8601]",
"0229[u-ca=iso8601]",
"1130[u-ca=iso8601]",
"12-14[u-ca=iso8601]",
"202112[u-ca=iso8601]",
]; ];
ambiguousStrings.forEach((string) => { ambiguousStrings.forEach((stringWithoutCalendar) => {
let arg = string; // calendar annotation must not cause disambiguation in favour of time
assert.throws( const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
RangeError, [stringWithoutCalendar, stringWithCalendar].forEach((string) => {
() => instance.equals(arg), let arg = string;
`${string} is ambiguous and requires T prefix` assert.throws(
); RangeError,
// The same string with a T prefix should not throw: () => instance.equals(arg),
arg = `T${string}`; `${string} is ambiguous and requires T prefix`
instance.equals(arg); );
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.equals(arg);
arg = ` ${string}`; arg = ` ${string}`;
assert.throws( assert.throws(
RangeError, RangeError,
() => instance.equals(arg), () => instance.equals(arg),
"space is not accepted as a substitute for T prefix" "space is not accepted as a substitute for T prefix"
); );
});
}); });
// None of these should throw without a T prefix, because they are unambiguously time strings: // None of these should throw without a T prefix, because they are unambiguously time strings:

View File

@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month "1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU "12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS "202112", // ambiguity between YYYYMM and HHMMSS
// same strings as above but with a calendar annotation, which must not cause
// disambiguation in favour of time
"2021-12[u-ca=iso8601]",
"1214[u-ca=iso8601]",
"0229[u-ca=iso8601]",
"1130[u-ca=iso8601]",
"12-14[u-ca=iso8601]",
"202112[u-ca=iso8601]",
]; ];
ambiguousStrings.forEach((string) => { ambiguousStrings.forEach((stringWithoutCalendar) => {
let arg = string; // calendar annotation must not cause disambiguation in favour of time
assert.throws( const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
RangeError, [stringWithoutCalendar, stringWithCalendar].forEach((string) => {
() => instance.since(arg), let arg = string;
`${string} is ambiguous and requires T prefix` assert.throws(
); RangeError,
// The same string with a T prefix should not throw: () => instance.since(arg),
arg = `T${string}`; `${string} is ambiguous and requires T prefix`
instance.since(arg); );
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.since(arg);
arg = ` ${string}`; arg = ` ${string}`;
assert.throws( assert.throws(
RangeError, RangeError,
() => instance.since(arg), () => instance.since(arg),
"space is not accepted as a substitute for T prefix" "space is not accepted as a substitute for T prefix"
); );
});
}); });
// None of these should throw without a T prefix, because they are unambiguously time strings: // None of these should throw without a T prefix, because they are unambiguously time strings:

View File

@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month "1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU "12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS "202112", // ambiguity between YYYYMM and HHMMSS
// same strings as above but with a calendar annotation, which must not cause
// disambiguation in favour of time
"2021-12[u-ca=iso8601]",
"1214[u-ca=iso8601]",
"0229[u-ca=iso8601]",
"1130[u-ca=iso8601]",
"12-14[u-ca=iso8601]",
"202112[u-ca=iso8601]",
]; ];
ambiguousStrings.forEach((string) => { ambiguousStrings.forEach((stringWithoutCalendar) => {
let arg = string; // calendar annotation must not cause disambiguation in favour of time
assert.throws( const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
RangeError, [stringWithoutCalendar, stringWithCalendar].forEach((string) => {
() => instance.until(arg), let arg = string;
`${string} is ambiguous and requires T prefix` assert.throws(
); RangeError,
// The same string with a T prefix should not throw: () => instance.until(arg),
arg = `T${string}`; `${string} is ambiguous and requires T prefix`
instance.until(arg); );
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.until(arg);
arg = ` ${string}`; arg = ` ${string}`;
assert.throws( assert.throws(
RangeError, RangeError,
() => instance.until(arg), () => instance.until(arg),
"space is not accepted as a substitute for T prefix" "space is not accepted as a substitute for T prefix"
); );
});
}); });
// None of these should throw without a T prefix, because they are unambiguously time strings: // None of these should throw without a T prefix, because they are unambiguously time strings:

View File

@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month "1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU "12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS "202112", // ambiguity between YYYYMM and HHMMSS
// same strings as above but with a calendar annotation, which must not cause
// disambiguation in favour of time
"2021-12[u-ca=iso8601]",
"1214[u-ca=iso8601]",
"0229[u-ca=iso8601]",
"1130[u-ca=iso8601]",
"12-14[u-ca=iso8601]",
"202112[u-ca=iso8601]",
]; ];
ambiguousStrings.forEach((string) => { ambiguousStrings.forEach((stringWithoutCalendar) => {
let arg = string; // calendar annotation must not cause disambiguation in favour of time
assert.throws( const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
RangeError, [stringWithoutCalendar, stringWithCalendar].forEach((string) => {
() => instance.withPlainTime(arg), let arg = string;
`${string} is ambiguous and requires T prefix` assert.throws(
); RangeError,
// The same string with a T prefix should not throw: () => instance.withPlainTime(arg),
arg = `T${string}`; `${string} is ambiguous and requires T prefix`
instance.withPlainTime(arg); );
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.withPlainTime(arg);
arg = ` ${string}`; arg = ` ${string}`;
assert.throws( assert.throws(
RangeError, RangeError,
() => instance.withPlainTime(arg), () => instance.withPlainTime(arg),
"space is not accepted as a substitute for T prefix" "space is not accepted as a substitute for T prefix"
); );
});
}); });
// None of these should throw without a T prefix, because they are unambiguously time strings: // None of these should throw without a T prefix, because they are unambiguously time strings: