summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/DateTimeFormat/prototype/formatToParts/related-year-zh.js
blob: 1033404e008346d63d673b63b21e15ea45c0a55d (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
// Copyright 2019 Google Inc, Igalia S.L. All rights reserved.
// Copyright 2020 Apple Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-partitiondatetimepattern
description: >
  Checks the output of 'relatedYear' and 'yearName' type, and
  the choice of pattern based on calendar.
locale: [zh-u-ca-chinese]
---*/

const df = new Intl.DateTimeFormat("zh-u-ca-chinese", {year: "numeric"});
const date = new Date(2019, 5, 1);
const actual = df.formatToParts(date);

const expected = [
  {type: "relatedYear", value: "2019"},
  {type: "yearName", value: "己亥"},
  {type: "literal", value: "年"},
];

assert.sameValue(Array.isArray(actual), true, 'actual is Array');

if (actual.length <= 2) {
  expected.shift(); // removes the relatedYear
}

actual.forEach(({ type, value }, i) => {
  const { type: eType, value: eValue } = expected[i];
  assert.sameValue(type, eType, `actual[${i}].type should be ${eType}`);
  assert.sameValue(value, eValue, `actual[${i}].value should be ${eValue}`);
});

reportCompare(0, 0);