test262/test/built-ins/Temporal/PlainTime/compare/argument-string-time-designator-required-for-disambiguation.js
Philip Chimento 051631f58b Temporal: Start moving collections of valid/invalid strings into TemporalHelpers
This adds an object, TemporalHelpers.ISO, which has methods that return
arrays of various ISO strings. The idea is to deduplicate more string
tests into methods on this object.
2022-08-31 08:59:33 -07:00

48 lines
1.5 KiB
JavaScript

// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.compare
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const midnight = new Temporal.PlainTime();
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(arg, midnight),
`'${arg}' is ambiguous and requires T prefix (first argument)`
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
`'${arg}' 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): '${arg}'`
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
`space is not accepted as a substitute for T prefix (second argument): '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach((arg) => {
Temporal.PlainTime.compare(arg, midnight);
Temporal.PlainTime.compare(midnight, arg);
});