mirror of https://github.com/tc39/test262.git
related-year-zh.js may not contain years (#2718)
macOS system ICU is shipping new CLDR, but it has many overrides on the top of it to make the formatted output suitable for the system. And in related-year-zh.js tests, we intentionally override the CLDR data with the different format. This change modifies the test to accept that alternative output.
This commit is contained in:
parent
0f5a274aad
commit
f6a9847c73
|
@ -1,4 +1,5 @@
|
|||
// 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.
|
||||
|
||||
/*---
|
||||
|
@ -11,4 +12,6 @@ locale: [zh-u-ca-chinese]
|
|||
|
||||
const df = new Intl.DateTimeFormat("zh-u-ca-chinese", {year: "numeric"});
|
||||
const date = new Date(2019, 5, 1);
|
||||
assert.sameValue(df.format(date), "2019己亥年");
|
||||
const formatted = df.format(date);
|
||||
const expected = ["2019己亥年", "己亥年"];
|
||||
assert(expected.includes(formatted));
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// 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.
|
||||
|
||||
/*---
|
||||
|
@ -9,21 +10,24 @@ description: >
|
|||
locale: [zh-u-ca-chinese]
|
||||
---*/
|
||||
|
||||
function verifyFormatParts(actual, expected, message) {
|
||||
assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
|
||||
assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
|
||||
assert.sameValue(actual.length, expected.length, `${message}: length`);
|
||||
|
||||
for (let i = 0; i < actual.length; ++i) {
|
||||
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
|
||||
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
|
||||
}
|
||||
}
|
||||
|
||||
const df = new Intl.DateTimeFormat("zh-u-ca-chinese", {year: "numeric"});
|
||||
const date = new Date(2019, 5, 1);
|
||||
verifyFormatParts(df.formatToParts(date), [
|
||||
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}`);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue