Skip to content

Commit

Permalink
Add tests for T time designator prefix not allowing space
Browse files Browse the repository at this point in the history
Here's a test I should have included in #3395. It's allowed to replace the
"T" in the middle of an ISO string with a space, but not when the "T" is a
time designator prefix. This assertion ensures that implementations make
this distinction correctly.
  • Loading branch information
ptomato authored and rwaldron committed Feb 28, 2022
1 parent 131c396 commit f7fb969
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ ambiguousStrings.forEach((string) => {
// 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'
);
});

// 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 @@ -27,6 +27,13 @@ ambiguousStrings.forEach((string) => {
// 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'
);
});

// 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 @@ -27,6 +27,13 @@ ambiguousStrings.forEach((string) => {
// 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'
);
});

// 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 @@ -33,6 +33,18 @@ ambiguousStrings.forEach((string) => {
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)'
);
});

// 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 @@ -25,6 +25,13 @@ ambiguousStrings.forEach((string) => {
// 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'
);
});

// 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 @@ -27,6 +27,13 @@ ambiguousStrings.forEach((string) => {
// 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'
);
});

// 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 @@ -27,6 +27,13 @@ ambiguousStrings.forEach((string) => {
// 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'
);
});

// 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 @@ -27,6 +27,13 @@ ambiguousStrings.forEach((string) => {
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.until(arg);

arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.until(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 @@ -27,6 +27,13 @@ ambiguousStrings.forEach((string) => {
// 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'
);
});

// None of these should throw without a T prefix, because they are unambiguously time strings:
Expand Down

0 comments on commit f7fb969

Please sign in to comment.