Skip to content

Commit f34bdde

Browse files
committed
Add more tests for PluralRules, including welsh and slovenian tests
1 parent e40c4d7 commit f34bdde

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

test/Intl/PluralRules.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55

66
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
77

8+
function testData(locale, ordinals, cardinals) {
9+
const plOrdinal = new Intl.PluralRules(locale, { type: "ordinal" });
10+
const plCardinal = new Intl.PluralRules(locale, { type: "cardinal" });
11+
assert.areEqual(locale, plOrdinal.resolvedOptions().locale);
12+
assert.areEqual(locale, plCardinal.resolvedOptions().locale);
13+
14+
ordinals.forEach((ordinal, i) => ordinal !== undefined && assert.areEqual(ordinal, plOrdinal.select(i), `Selecting ${i} for locale ${locale} with ordinal type`));
15+
cardinals.forEach((cardinal, i) => cardinal !== undefined && assert.areEqual(cardinal, plCardinal.select(i), `Selecting ${i} for locale ${locale} with cardinal type`));
16+
}
17+
818
testRunner.runTests([
919
{
1020
name: "Basic resolved options",
1121
body() {
12-
const pr = new Intl.PluralRules();
22+
const pr = new Intl.PluralRules("en");
1323
const opts = pr.resolvedOptions();
1424
assert.areEqual("string", typeof opts.locale, "Locale should be the default locale");
1525
assert.areEqual("cardinal", opts.type, "Default type should be cardinal");
@@ -24,7 +34,7 @@ testRunner.runTests([
2434
if (WScript.Platform.ICU_VERSION >= 61) {
2535
// In ICU 61+, uplrules_getKeywords became stable, so we can actually use it
2636
// REVIEW(jahorto): In all locales, there should be at least a singular and plural category?
27-
assert.isTrue(opts.pluralCategories.length > 2, "pluralCategories should use uplrules_getKeywords");
37+
assert.isTrue(opts.pluralCategories.length >= 2, "pluralCategories should use uplrules_getKeywords");
2838
} else {
2939
assert.isTrue(opts.pluralCategories.length === 1, "pluralCategories should not use uplrules_getKeywords");
3040
}
@@ -53,29 +63,33 @@ testRunner.runTests([
5363
}
5464
},
5565
{
56-
name: "https://github.com/tc39/proposal-intl-plural-rules/issues/37",
66+
name: "Welsh data tests",
5767
body() {
58-
assert.areEqual("cy", Intl.PluralRules.supportedLocalesOf("cy")[0]);
59-
const cy = new Intl.PluralRules("cy", { type: "ordinal" });
60-
assert.areEqual("few", cy.select(3));
61-
assert.areEqual("many", cy.select(6));
68+
testData("cy",
69+
["zero", "one", "two", "few", "few", "many", "many", "zero", "zero", "zero", "other"],
70+
["zero", "one", "two", "few", "other", "other", "many", "other", "other", "other"]
71+
);
6272
}
6373
},
6474
{
65-
name: "https://github.com/tc39/proposal-intl-plural-rules/issues/39",
75+
name: "Slovenian data tests",
6676
body() {
67-
const en = new Intl.PluralRules("en", { type: "ordinal" });
68-
assert.areEqual("other", en.select(10));
69-
assert.areEqual("other", en.select(11));
70-
assert.areEqual("other", en.select(12));
71-
assert.areEqual("other", en.select(13));
72-
assert.areEqual("other", en.select(14));
77+
const ordinals = Array(10).fill("other");
78+
const cardinals = ["other", "one", "two", "few", "few", "other"];
79+
cardinals[10] = "other";
80+
cardinals[11] = "other";
81+
cardinals[12] = "other";
82+
cardinals[13] = "other";
83+
cardinals[14] = "other";
84+
cardinals[15] = "other";
85+
cardinals[100] = "other";
86+
cardinals[101] = "one";
87+
cardinals[102] = "two";
88+
cardinals[103] = "few";
89+
cardinals[104] = "few";
90+
cardinals[105] = "other";
7391

74-
assert.areEqual("other", en.select(20));
75-
assert.areEqual("one", en.select(21));
76-
assert.areEqual("two", en.select(22));
77-
assert.areEqual("few", en.select(23));
78-
assert.areEqual("other", en.select(24));
92+
testData("sl", ordinals, cardinals);
7993
}
8094
},
8195
], { verbose: false });

0 commit comments

Comments
 (0)