From 655dbec995d4ed5ed3349f4e312260f3a2579182 Mon Sep 17 00:00:00 2001 From: "Amir E. Aharoni" Date: Wed, 1 Feb 2012 15:37:40 +0000 Subject: [PATCH] Fixed plural rules for Romanian / Moldovan according to CLDR. Added tests for Romanian and fixed tests for Moldovan. --- languages/classes/LanguageMo.php | 5 ++- languages/classes/LanguageRo.php | 4 +- tests/phpunit/languages/LanguageMoTest.php | 24 ++++++------ tests/phpunit/languages/LanguageRoTest.php | 43 ++++++++++++++++++++++ 4 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 tests/phpunit/languages/LanguageRoTest.php diff --git a/languages/classes/LanguageMo.php b/languages/classes/LanguageMo.php index a973a7ab35..3410729f89 100644 --- a/languages/classes/LanguageMo.php +++ b/languages/classes/LanguageMo.php @@ -14,13 +14,14 @@ class LanguageMo extends Language { function convertPlural( $count, $forms ) { // Plural rules per // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#mo + // Identical to Romanian (ro). if ( !count( $forms ) ) { return ''; } $forms = $this->preConvertPlural( $forms, 3 ); - if ( $count == 1 ) { + if ( $count === 1 ) { $index = 0; - } elseif ( $count == 0 || ( $count % 100 > 0 && $count % 100 < 20 ) ) { + } elseif ( $count === 0 || ( $count % 100 > 0 && $count % 100 < 20 ) ) { $index = 1; } else { $index = 2; diff --git a/languages/classes/LanguageRo.php b/languages/classes/LanguageRo.php index 9cfd8b572f..ea156c2749 100644 --- a/languages/classes/LanguageRo.php +++ b/languages/classes/LanguageRo.php @@ -18,9 +18,9 @@ class LanguageRo extends Language { $forms = $this->preConvertPlural( $forms, 3 ); - if ( $count == 1 ) { + if ( $count === 1 ) { $index = 0; - } elseif ( $count == 0 || $count % 100 < 20 ) { + } elseif ( $count === 0 || ( $count % 100 > 0 && $count % 100 < 20 ) ) { $index = 1; } else { $index = 2; diff --git a/tests/phpunit/languages/LanguageMoTest.php b/tests/phpunit/languages/LanguageMoTest.php index 48940a5dc6..533e590fab 100644 --- a/tests/phpunit/languages/LanguageMoTest.php +++ b/tests/phpunit/languages/LanguageMoTest.php @@ -22,22 +22,22 @@ class LanguageMoTest extends MediaWikiTestCase { $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); } - function providerPlural() { return array ( - array( 'few', 0 ), - array( 'one', 1 ), - array( 'few', 2 ), - array( 'few', 3 ), - array( 'few', 19 ), - array( 'few', 119 ), + array( 'few', 0 ), + array( 'one', 1 ), + array( 'few', 2 ), + array( 'few', 19 ), array( 'other', 20 ), - array( 'other', 20.123 ), - array( 'other', 31 ), + array( 'other', 99 ), + array( 'other', 100 ), + array( 'few', 101 ), + array( 'few', 119 ), + array( 'other', 120 ), array( 'other', 200 ), - array( 'few', 201 ), + array( 'few', 201 ), + array( 'few', 219 ), + array( 'other', 220 ), ); } - - } diff --git a/tests/phpunit/languages/LanguageRoTest.php b/tests/phpunit/languages/LanguageRoTest.php new file mode 100644 index 0000000000..5270f6fee5 --- /dev/null +++ b/tests/phpunit/languages/LanguageRoTest.php @@ -0,0 +1,43 @@ +lang = Language::factory( 'ro' ); + } + function tearDown() { + unset( $this->lang ); + } + + /** @dataProvider providerPlural */ + function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + } + + function providerPlural() { + return array ( + array( 'few', 0 ), + array( 'one', 1 ), + array( 'few', 2 ), + array( 'few', 19 ), + array( 'other', 20 ), + array( 'other', 99 ), + array( 'other', 100 ), + array( 'few', 101 ), + array( 'few', 119 ), + array( 'other', 120 ), + array( 'other', 200 ), + array( 'few', 201 ), + array( 'few', 219 ), + array( 'other', 220 ), + ); + } +} -- 2.20.1