summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/PlainDate/argument-convert.js
blob: 678c6a5f00a6e9fa0230dca365213312fb9f265a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// 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.plaindate
description: PlainDate constructor with non-integer arguments.
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

TemporalHelpers.assertPlainDate(new Temporal.PlainDate(2020.6, 11.7, 24.1),
  2020, 11, "M11", 24, "positive fractional");

TemporalHelpers.assertPlainDate(new Temporal.PlainDate(-2020.6, 11.7, 24.1),
  -2020, 11, "M11", 24, "negative fractional");

TemporalHelpers.assertPlainDate(new Temporal.PlainDate(null, 11, 24),
  0, 11, "M11", 24, "null");

TemporalHelpers.assertPlainDate(new Temporal.PlainDate(true, 11, 24),
  1, 11, "M11", 24, "boolean");

TemporalHelpers.assertPlainDate(new Temporal.PlainDate("2020.6", "11.7", "24.1"),
  2020, 11, "M11", 24, "fractional strings");

for (const invalid of [Symbol(), 1n]) {
  assert.throws(TypeError, () => new Temporal.PlainDate(invalid, 11, 24), `year ${typeof invalid}`);
  assert.throws(TypeError, () => new Temporal.PlainDate(2020, invalid, 24), `month ${typeof invalid}`);
  assert.throws(TypeError, () => new Temporal.PlainDate(2020, 11, invalid), `day ${typeof invalid}`);
}

for (const invalid of [undefined, "invalid"]) {
  assert.throws(RangeError, () => new Temporal.PlainDate(invalid, 11, 24), `year ${typeof invalid}`);
  assert.throws(RangeError, () => new Temporal.PlainDate(2020, invalid, 24), `month ${typeof invalid}`);
  assert.throws(RangeError, () => new Temporal.PlainDate(2020, 11, invalid), `day ${typeof invalid}`);
} 
const actual = [];
const args = [
  TemporalHelpers.toPrimitiveObserver(actual, 2020, "year"),
  TemporalHelpers.toPrimitiveObserver(actual, 11, "month"),
  TemporalHelpers.toPrimitiveObserver(actual, 24, "day"),
];
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(...args),
  2020, 11, "M11", 24, "invalid string");
assert.compareArray(actual, [
  "get year.valueOf",
  "call year.valueOf",
  "get month.valueOf",
  "call month.valueOf",
  "get day.valueOf",
  "call day.valueOf",
]);

reportCompare(0, 0);