mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 23:44:27 +02:00
Add test to ensure Intl.DateTimeFormat choose pattern by calendar (#2381)
* Add test for different pattern based on calendar * Add test for formatRangeToParts * remove debug print * fix typo * fix typo * address review feedback * address review feedback * change the map and use string template * rewrite maps and use string template
This commit is contained in:
parent
8f6369d1c4
commit
b073c48b49
53
test/intl402/DateTimeFormat/prototype/formatRangeToParts/pattern-on-calendar.js
vendored
Normal file
53
test/intl402/DateTimeFormat/prototype/formatRangeToParts/pattern-on-calendar.js
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-initializedatetimeformat
|
||||||
|
description: Checks the DateTimeFormat choose different patterns based
|
||||||
|
on calendar.
|
||||||
|
locale: [en]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let calendars = [
|
||||||
|
"buddhist",
|
||||||
|
"chinese",
|
||||||
|
"coptic",
|
||||||
|
"dangi",
|
||||||
|
"ethiopic",
|
||||||
|
"ethioaa",
|
||||||
|
"gregory",
|
||||||
|
"hebrew",
|
||||||
|
"indian",
|
||||||
|
"islamic",
|
||||||
|
"islamic-civil",
|
||||||
|
"islamic-rgsa",
|
||||||
|
"islamic-tbla",
|
||||||
|
"islamic-umalqura",
|
||||||
|
"japanese",
|
||||||
|
"persian",
|
||||||
|
"roc"
|
||||||
|
];
|
||||||
|
let date1 = new Date(2017, 3, 12);
|
||||||
|
let date2 = new Date();
|
||||||
|
|
||||||
|
// serialize parts to a string by considering only the type and literal.
|
||||||
|
function serializeTypesAndLiteral(parts) {
|
||||||
|
let types = parts.map(part => {
|
||||||
|
if (part.type == "literal") {
|
||||||
|
return `${part.type}(${part.value})`;
|
||||||
|
}
|
||||||
|
return part.type;
|
||||||
|
});
|
||||||
|
return types.join(":");
|
||||||
|
}
|
||||||
|
|
||||||
|
let df = new Intl.DateTimeFormat("en");
|
||||||
|
let base = serializeTypesAndLiteral(df.formatRangeToParts(date1, date2));
|
||||||
|
|
||||||
|
const foundDifferentPattern = calendars.some(function(calendar) {
|
||||||
|
let cdf = new Intl.DateTimeFormat("en-u-ca-" + calendar);
|
||||||
|
return base != serializeTypesAndLiteral(cdf.formatRangeToParts(date1, date2));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Expect at least some calendar use different pattern.
|
||||||
|
assert.sameValue(foundDifferentPattern, true);
|
52
test/intl402/DateTimeFormat/prototype/formatToParts/pattern-on-calendar.js
vendored
Normal file
52
test/intl402/DateTimeFormat/prototype/formatToParts/pattern-on-calendar.js
vendored
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-initializedatetimeformat
|
||||||
|
description: Checks the DateTimeFormat choose different patterns based
|
||||||
|
on calendar.
|
||||||
|
locale: [en]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let calendars = [
|
||||||
|
"buddhist",
|
||||||
|
"chinese",
|
||||||
|
"coptic",
|
||||||
|
"dangi",
|
||||||
|
"ethiopic",
|
||||||
|
"ethioaa",
|
||||||
|
"gregory",
|
||||||
|
"hebrew",
|
||||||
|
"indian",
|
||||||
|
"islamic",
|
||||||
|
"islamic-civil",
|
||||||
|
"islamic-rgsa",
|
||||||
|
"islamic-tbla",
|
||||||
|
"islamic-umalqura",
|
||||||
|
"japanese",
|
||||||
|
"persian",
|
||||||
|
"roc"
|
||||||
|
];
|
||||||
|
let date = new Date();
|
||||||
|
|
||||||
|
// serialize parts to a string by considering only the type and literal.
|
||||||
|
function serializeTypesAndLiteral(parts) {
|
||||||
|
let types = parts.map(part => {
|
||||||
|
if (part.type == "literal") {
|
||||||
|
return `${part.type}(${part.value})`;
|
||||||
|
}
|
||||||
|
return part.type;
|
||||||
|
});
|
||||||
|
return types.join(":");
|
||||||
|
}
|
||||||
|
|
||||||
|
let df = new Intl.DateTimeFormat("en");
|
||||||
|
let base = serializeTypesAndLiteral(df.formatToParts(date));
|
||||||
|
|
||||||
|
const foundDifferentPattern = calendars.some(function(calendar) {
|
||||||
|
let cdf = new Intl.DateTimeFormat("en-u-ca-" + calendar);
|
||||||
|
return base != serializeTypesAndLiteral(cdf.formatToParts(date));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Expect at least some calendar use different pattern.
|
||||||
|
assert.sameValue(foundDifferentPattern, true);
|
Loading…
x
Reference in New Issue
Block a user