summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Intl/DateTimeFormat/prototype/formatRange/fails-on-distinct-temporal-types.js
blob: 9bac489052b2288a85ea8ff2de20c97baa88c5df (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
// |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-intl.datetimeformat.prototype.formatRange
description: formatRange fails if given arguments of different Temporal types
features: [Temporal]
---*/

const us = new Intl.DateTimeFormat('en-US');

const instances = {
  date: new Date(1580527800000),
  instant: new Temporal.Instant(0n),
  plaindate: new Temporal.PlainDate(2000, 5, 2),
  plaindatetime: new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321),
  plainmonthday: new Temporal.PlainMonthDay(5, 2),
  plaintime: new Temporal.PlainTime(13, 37),
  plainyearmonth: new Temporal.PlainYearMonth(2019, 6),
  zoneddatetime: new Temporal.ZonedDateTime(0n, 'America/Kentucky/Louisville')
};

Object.entries(instances).forEach(([typeName, instance]) => {
  Object.entries(instances).forEach(([anotherTypeName, anotherInstance]) => {
    if (typeName !== anotherTypeName) {
      assert.throws(
        TypeError,
        () => { us.formatRange(instance, anotherInstance); },
        'formatRange: bad arguments (' + typeName + ' and ' + anotherTypeName + ')'
      );
    }
  });
});

reportCompare(0, 0);