Skip to content

Commit 58f29a2

Browse files
committed
intl tests for proposed additional options in options bag
This patch implements tests for the ECMA 402 PR at tc39/ecma402#175 It is based on the test test/intl402/Collator/10.1.1_19_c.js
1 parent 290799b commit 58f29a2

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2012 Mozilla Corporation. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-initializedatetimeformat
6+
description: >
7+
Tests that the options numberingSystem and calendar can be set through
8+
either the locale or the options.
9+
author: Norbert Lindenberg, Daniel Ehrenberg
10+
includes: [testIntl.js]
11+
---*/
12+
13+
let defaultLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
14+
15+
let supportedNumberingSystems = ["latn", "arab"].filter(nu =>
16+
new Intl.DateTimeFormat(defaultLocale + "-u-nu-" + nu)
17+
.resolvedOptions().numberingSystem === nu
18+
);
19+
20+
let supportedCalendars = ["gregory", "chinese"].filter(ca =>
21+
new Intl.DateTimeFormat(defaultLocale + "-u-ca-" + ca)
22+
.resolvedOptions().calendar === ca
23+
);
24+
25+
let options = [
26+
{key: "nu", property: "numberingSystem", type: "string", values: supportedNumberingSystems},
27+
{key: "ca", property: "calendar", type: "string", values: supportedCalendars}
28+
];
29+
30+
options.forEach(function (option) {
31+
let dateTimeFormat, opt, result;
32+
33+
// find out which values are supported for a property in the default locale
34+
let supportedValues = [];
35+
option.values.forEach(function (value) {
36+
opt = {};
37+
opt[option.property] = value;
38+
dateTimeFormat = new Intl.DateTimeFormat([defaultLocale], opt);
39+
result = dateTimeFormat.resolvedOptions()[option.property];
40+
if (result !== undefined && supportedValues.indexOf(result) === -1) {
41+
supportedValues.push(result);
42+
}
43+
});
44+
45+
// verify that the supported values can also be set through the locale
46+
supportedValues.forEach(function (value) {
47+
dateTimeFormat = new Intl.DateTimeFormat([defaultLocale + "-u-" + option.key + "-" + value]);
48+
result = dateTimeFormat.resolvedOptions()[option.property];
49+
assert.sameValue(result, value, "Property " + option.property + " couldn't be set through locale extension key " + option.key + ".");
50+
});
51+
52+
// verify that the options setting overrides the locale setting
53+
supportedValues.forEach(function (value) {
54+
let otherValue;
55+
option.values.forEach(function (possibleValue) {
56+
if (possibleValue !== value) {
57+
otherValue = possibleValue;
58+
}
59+
});
60+
if (otherValue !== undefined) {
61+
opt = {};
62+
opt[option.property] = value;
63+
dateTimeFormat = new Intl.DateTimeFormat([defaultLocale + "-u-" + option.key + "-" + otherValue], opt);
64+
result = dateTimeFormat.resolvedOptions()[option.property];
65+
assert.sameValue(result, value, "Options value for property " + option.property + " doesn't override locale extension key " + option.key + ".");
66+
}
67+
});
68+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2012 Mozilla Corporation. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-initializenumberformat
6+
description: >
7+
Tests that the options numberingSystem and calendar can be set through
8+
either the locale or the options.
9+
author: Norbert Lindenberg, Daniel Ehrenberg
10+
includes: [testIntl.js]
11+
---*/
12+
13+
let defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
14+
15+
let supportedNumberingSystems = ["latn", "arab"].filter(nu =>
16+
new Intl.NumberFormat(defaultLocale + "-u-nu-" + nu)
17+
.resolvedOptions().numberingSystem === nu
18+
);
19+
20+
let options = [
21+
{key: "nu", property: "numberingSystem", type: "string", values: supportedNumberingSystems},
22+
];
23+
24+
options.forEach(function (option) {
25+
let numberFormat, opt, result;
26+
27+
// find out which values are supported for a property in the default locale
28+
let supportedValues = [];
29+
option.values.forEach(function (value) {
30+
opt = {};
31+
opt[option.property] = value;
32+
numberFormat = new Intl.NumberFormat([defaultLocale], opt);
33+
result = numberFormat.resolvedOptions()[option.property];
34+
if (result !== undefined && supportedValues.indexOf(result) === -1) {
35+
supportedValues.push(result);
36+
}
37+
});
38+
39+
// verify that the supported values can also be set through the locale
40+
supportedValues.forEach(function (value) {
41+
numberFormat = new Intl.NumberFormat([defaultLocale + "-u-" + option.key + "-" + value]);
42+
result = numberFormat.resolvedOptions()[option.property];
43+
assert.sameValue(result, value, "Property " + option.property + " couldn't be set through locale extension key " + option.key + ".");
44+
});
45+
46+
// verify that the options setting overrides the locale setting
47+
supportedValues.forEach(function (value) {
48+
let otherValue;
49+
option.values.forEach(function (possibleValue) {
50+
if (possibleValue !== value) {
51+
otherValue = possibleValue;
52+
}
53+
});
54+
if (otherValue !== undefined) {
55+
opt = {};
56+
opt[option.property] = value;
57+
numberFormat = new Intl.NumberFormat([defaultLocale + "-u-" + option.key + "-" + otherValue], opt);
58+
result = numberFormat.resolvedOptions()[option.property];
59+
assert.sameValue(result, value, "Options value for property " + option.property + " doesn't override locale extension key " + option.key + ".");
60+
}
61+
});
62+
});
63+

0 commit comments

Comments
 (0)