Skip to content

Commit

Permalink
Add more tests for PluralRules, including welsh and slovenian tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhorton committed Apr 26, 2018
1 parent e40c4d7 commit f34bdde
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions test/Intl/PluralRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@

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

function testData(locale, ordinals, cardinals) {
const plOrdinal = new Intl.PluralRules(locale, { type: "ordinal" });
const plCardinal = new Intl.PluralRules(locale, { type: "cardinal" });
assert.areEqual(locale, plOrdinal.resolvedOptions().locale);
assert.areEqual(locale, plCardinal.resolvedOptions().locale);

ordinals.forEach((ordinal, i) => ordinal !== undefined && assert.areEqual(ordinal, plOrdinal.select(i), `Selecting ${i} for locale ${locale} with ordinal type`));
cardinals.forEach((cardinal, i) => cardinal !== undefined && assert.areEqual(cardinal, plCardinal.select(i), `Selecting ${i} for locale ${locale} with cardinal type`));
}

testRunner.runTests([
{
name: "Basic resolved options",
body() {
const pr = new Intl.PluralRules();
const pr = new Intl.PluralRules("en");
const opts = pr.resolvedOptions();
assert.areEqual("string", typeof opts.locale, "Locale should be the default locale");
assert.areEqual("cardinal", opts.type, "Default type should be cardinal");
Expand All @@ -24,7 +34,7 @@ testRunner.runTests([
if (WScript.Platform.ICU_VERSION >= 61) {
// In ICU 61+, uplrules_getKeywords became stable, so we can actually use it
// REVIEW(jahorto): In all locales, there should be at least a singular and plural category?
assert.isTrue(opts.pluralCategories.length > 2, "pluralCategories should use uplrules_getKeywords");
assert.isTrue(opts.pluralCategories.length >= 2, "pluralCategories should use uplrules_getKeywords");
} else {
assert.isTrue(opts.pluralCategories.length === 1, "pluralCategories should not use uplrules_getKeywords");
}
Expand Down Expand Up @@ -53,29 +63,33 @@ testRunner.runTests([
}
},
{
name: "https://github.com/tc39/proposal-intl-plural-rules/issues/37",
name: "Welsh data tests",
body() {
assert.areEqual("cy", Intl.PluralRules.supportedLocalesOf("cy")[0]);
const cy = new Intl.PluralRules("cy", { type: "ordinal" });
assert.areEqual("few", cy.select(3));
assert.areEqual("many", cy.select(6));
testData("cy",
["zero", "one", "two", "few", "few", "many", "many", "zero", "zero", "zero", "other"],
["zero", "one", "two", "few", "other", "other", "many", "other", "other", "other"]
);
}
},
{
name: "https://github.com/tc39/proposal-intl-plural-rules/issues/39",
name: "Slovenian data tests",
body() {
const en = new Intl.PluralRules("en", { type: "ordinal" });
assert.areEqual("other", en.select(10));
assert.areEqual("other", en.select(11));
assert.areEqual("other", en.select(12));
assert.areEqual("other", en.select(13));
assert.areEqual("other", en.select(14));
const ordinals = Array(10).fill("other");
const cardinals = ["other", "one", "two", "few", "few", "other"];
cardinals[10] = "other";
cardinals[11] = "other";
cardinals[12] = "other";
cardinals[13] = "other";
cardinals[14] = "other";
cardinals[15] = "other";
cardinals[100] = "other";
cardinals[101] = "one";
cardinals[102] = "two";
cardinals[103] = "few";
cardinals[104] = "few";
cardinals[105] = "other";

assert.areEqual("other", en.select(20));
assert.areEqual("one", en.select(21));
assert.areEqual("two", en.select(22));
assert.areEqual("few", en.select(23));
assert.areEqual("other", en.select(24));
testData("sl", ordinals, cardinals);
}
},
], { verbose: false });

0 comments on commit f34bdde

Please sign in to comment.