Skip to content

Commit

Permalink
Temporal: Deduplicate strings-with-calendar from strings-without-cale…
Browse files Browse the repository at this point in the history
…ndar

The strings with calendar annotations in these tests don't need to be
listed separately, they can be derived from the original strings.
  • Loading branch information
ptomato committed Aug 31, 2022
1 parent 409d6dc commit ddef61a
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"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) => {
let arg = string;
assert.throws(
RangeError,
() => instance.toPlainDateTime(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toPlainDateTime(arg);
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.toPlainDateTime(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toPlainDateTime(arg);

arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.toPlainDateTime(arg),
"space is not accepted as a substitute for T prefix"
);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.toPlainDateTime(arg),
"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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"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) => {
let arg = string;
assert.throws(
RangeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" });
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" });

arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
"space is not accepted as a substitute for T prefix"
);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
"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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"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) => {
let arg = string;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.withPlainTime(arg);
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.withPlainTime(arg);

arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
"space is not accepted as a substitute for T prefix"
);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
"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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,39 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"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) => {
let arg = string;
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(arg, midnight),
`${string} is ambiguous and requires T prefix (first argument)`
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
`${string} is ambiguous and requires T prefix (second argument)`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
Temporal.PlainTime.compare(arg, midnight);
Temporal.PlainTime.compare(midnight, arg);
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(arg, midnight),
`${string} is ambiguous and requires T prefix (first argument)`
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
`${string} is ambiguous and requires T prefix (second argument)`
);
// 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}`;
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(arg, midnight),
'space is not accepted as a substitute for T prefix (first argument)'
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
'space is not accepted as a substitute for T prefix (second argument)'
);
arg = ` ${string}`;
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(arg, midnight),
'space is not accepted as a substitute for T prefix (first argument)'
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
'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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"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) => {
let arg = string;
assert.throws(
RangeError,
() => Temporal.PlainTime.from(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
Temporal.PlainTime.from(arg);
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => Temporal.PlainTime.from(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
Temporal.PlainTime.from(arg);

arg = ` ${string}`;
assert.throws(
RangeError,
() => Temporal.PlainTime.from(arg),
"space is not accepted as a substitute for T prefix"
);
arg = ` ${string}`;
assert.throws(
RangeError,
() => Temporal.PlainTime.from(arg),
"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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"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) => {
let arg = string;
assert.throws(
RangeError,
() => instance.equals(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.equals(arg);
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.equals(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.equals(arg);

arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.equals(arg),
"space is not accepted as a substitute for T prefix"
);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.equals(arg),
"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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@ const ambiguousStrings = [
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"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) => {
let arg = string;
assert.throws(
RangeError,
() => instance.since(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.since(arg);
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.since(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.since(arg);

arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.since(arg),
"space is not accepted as a substitute for T prefix"
);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.since(arg),
"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:
Expand Down

0 comments on commit ddef61a

Please sign in to comment.