| 1 |
// |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options |
| 2 |
// Copyright (C) 2022 Igalia, S.L. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-temporal.plaintime.compare |
| 7 |
description: ISO 8601 time designator "T" required in cases of ambiguity |
| 8 |
includes: [temporalHelpers.js] |
| 9 |
features: [Temporal, arrow-function] |
| 10 |
---*/ |
| 11 |
|
| 12 |
const midnight = new Temporal.PlainTime(); |
| 13 |
|
| 14 |
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => { |
| 15 |
let arg = string; |
| 16 |
assert.throws( |
| 17 |
RangeError, |
| 18 |
() => Temporal.PlainTime.compare(arg, midnight), |
| 19 |
`'${arg}' is ambiguous and requires T prefix (first argument)` |
| 20 |
); |
| 21 |
assert.throws( |
| 22 |
RangeError, |
| 23 |
() => Temporal.PlainTime.compare(midnight, arg), |
| 24 |
`'${arg}' is ambiguous and requires T prefix (second argument)` |
| 25 |
); |
| 26 |
// The same string with a T prefix should not throw: |
| 27 |
arg = `T${string}`; |
| 28 |
Temporal.PlainTime.compare(arg, midnight); |
| 29 |
Temporal.PlainTime.compare(midnight, arg); |
| 30 |
|
| 31 |
arg = ` ${string}`; |
| 32 |
assert.throws( |
| 33 |
RangeError, |
| 34 |
() => Temporal.PlainTime.compare(arg, midnight), |
| 35 |
`space is not accepted as a substitute for T prefix (first argument): '${arg}'` |
| 36 |
); |
| 37 |
assert.throws( |
| 38 |
RangeError, |
| 39 |
() => Temporal.PlainTime.compare(midnight, arg), |
| 40 |
`space is not accepted as a substitute for T prefix (second argument): '${arg}'` |
| 41 |
); |
| 42 |
}); |
| 43 |
|
| 44 |
// None of these should throw without a T prefix, because they are unambiguously time strings: |
| 45 |
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach((arg) => { |
| 46 |
Temporal.PlainTime.compare(arg, midnight); |
| 47 |
Temporal.PlainTime.compare(midnight, arg); |
| 48 |
}); |
| 49 |
|
| 50 |
reportCompare(0, 0); |