Check for a null argument to Intl.plural
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132116745
diff --git a/lib/intl.dart b/lib/intl.dart
index 19b5a3b..29b78ff 100644
--- a/lib/intl.dart
+++ b/lib/intl.dart
@@ -295,6 +295,9 @@
if (other == null) {
throw new ArgumentError("The 'other' named argument must be provided");
}
+ if (howMany == null) {
+ throw new ArgumentError("The howMany argument to plural cannot be null");
+ }
// If there's an explicit case for the exact number, we use it. This is not
// strictly in accord with the CLDR rules, but it seems to be the
// expectation. At least I see e.g. Russian translations that have a zero
diff --git a/test/plural_test.dart b/test/plural_test.dart
index 5987936..cb4f81c 100644
--- a/test/plural_test.dart
+++ b/test/plural_test.dart
@@ -189,6 +189,12 @@
verify(expectedEn, 'en', plural);
verify(expectedRo, 'ro', pluralNoZero);
verify(expectedSr, 'sr', pluralNoZero);
+
+ test("Check null howMany", () {
+ expect(plural(0, null), "0:Zero");
+ expect(() => plural(null, null), throwsArgumentError);
+ expect(() => plural(null, "ru"), throwsArgumentError);
+ });
}
verify(expectedValues, locale, pluralFunction) {