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

Bug: v8:11544
Change-Id: I004b7cb34effe1de1735b61c7ac749ae3c8e9bf7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3085624
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76551}
2021-08-28 05:40:50 +00:00

31 lines
1.3 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.PlainDate(2021, 3, 14);
let t2 = new Temporal.PlainDate(2021, 3, 14);
let t3 = t1;
let t4 = new Temporal.PlainDate(2021, 3, 15);
let t5 = new Temporal.PlainDate(2021, 4, 14);
let t6 = new Temporal.PlainDate(2022, 3, 14);
// years in 4 digits range
assertEquals(0, Temporal.PlainDate.compare(t1, t1));
assertEquals(0, Temporal.PlainDate.compare(t1, t2));
assertEquals(0, Temporal.PlainDate.compare(t1, t3));
assertEquals(0, Temporal.PlainDate.compare(t1, "2021-03-14"));
assertEquals(0, Temporal.PlainDate.compare(t1, "2021-03-14T23:59:59"));
assertEquals(1, Temporal.PlainDate.compare(t4, t1));
assertEquals(1, Temporal.PlainDate.compare(t5, t1));
assertEquals(1, Temporal.PlainDate.compare(t6, t1));
assertEquals(-1, Temporal.PlainDate.compare(t1, t4));
assertEquals(-1, Temporal.PlainDate.compare(t1, t5));
assertEquals(-1, Temporal.PlainDate.compare(t1, t6));
assertEquals(1, Temporal.PlainDate.compare("2021-07-21", t1));
// Test Throw
assertThrows(() => Temporal.PlainDate.compare(t1, "invalid iso8601 string"),
RangeError);
assertThrows(() => Temporal.PlainDate.compare("invalid iso8601 string", t1),
RangeError);