v8/test/mjsunit/temporal/plain-date-time-compare.js
Frank Tang 790d55486b [Temporal] Add some tests for PlainDateTime
Land some of the tests for Temporal.PlainDateTime
All marked as FAIL at this stage.

Bug: v8:11544
Change-Id: I09bf681e61f19d96607c848ddcb6bee06580aff1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3085625
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77332}
2021-10-12 08:48:20 +00:00

35 lines
1.7 KiB
JavaScript

// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let t1 = new Temporal.PlainDateTime(2021, 3, 14, 1, 2, 3, 4, 5, 6);
let t2 = new Temporal.PlainDateTime(2021, 3, 14, 1, 2, 3, 4, 5, 6);
let t3 = t1;
let t4 = new Temporal.PlainDateTime(2021, 3, 15, 1, 2, 3, 4, 5, 6);
let t5 = new Temporal.PlainDateTime(2021, 4, 14, 1, 2, 3, 4, 5, 6);
let t6 = new Temporal.PlainDateTime(2022, 3, 14, 1, 2, 3, 4, 5, 6);
let t7 = new Temporal.PlainDateTime(2021, 3, 14, 1, 2, 3, 4, 5, 7);
// years in 4 digits range
assertEquals(0, Temporal.PlainDateTime.compare(t1, t1));
assertEquals(0, Temporal.PlainDateTime.compare(t1, t2));
assertEquals(0, Temporal.PlainDateTime.compare(t1, t3));
assertEquals(1, Temporal.PlainDateTime.compare(t1, "2021-03-14T01:02:03"));
assertEquals(1, Temporal.PlainDateTime.compare(t4, t1));
assertEquals(1, Temporal.PlainDateTime.compare(t5, t1));
assertEquals(1, Temporal.PlainDateTime.compare(t6, t1));
assertEquals(1, Temporal.PlainDateTime.compare(t7, t1));
assertEquals(-1, Temporal.PlainDateTime.compare(t1, t4));
assertEquals(-1, Temporal.PlainDateTime.compare(t1, t5));
assertEquals(-1, Temporal.PlainDateTime.compare(t1, t6));
assertEquals(-1, Temporal.PlainDateTime.compare(t1, t7));
assertEquals(1, Temporal.PlainDateTime.compare("2021-07-21", t1));
assertEquals(0, Temporal.PlainDateTime.compare(
t1, "2021-03-14T01:02:03.004005006"));
// Test Throw
assertThrows(() => Temporal.PlainDateTime.compare(t1, "invalid iso8601 string"),
RangeError);
assertThrows(() => Temporal.PlainDateTime.compare("invalid iso8601 string", t1),
RangeError);