From 00f34a0260927de7ab05ff7a777a3a9b7cc5004f Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Thu, 19 Sep 2013 22:16:07 +0200 Subject: Ported old I18N tests from simpleunit to phpunit --- tests/simple_unit/I18N/ChoiceFormatTest.php | 98 --------------------------- tests/simple_unit/I18N/CultureInfoTest.php | 13 ---- tests/simple_unit/runtime/.gitignore | 0 tests/unit/I18N/core/ChoiceFormatTest.php | 101 ++++++++++++++++++++++++++++ tests/unit/I18N/core/CultureInfoTest.php | 6 ++ 5 files changed, 107 insertions(+), 111 deletions(-) delete mode 100644 tests/simple_unit/I18N/ChoiceFormatTest.php delete mode 100644 tests/simple_unit/I18N/CultureInfoTest.php mode change 100644 => 100755 tests/simple_unit/runtime/.gitignore create mode 100644 tests/unit/I18N/core/ChoiceFormatTest.php (limited to 'tests') diff --git a/tests/simple_unit/I18N/ChoiceFormatTest.php b/tests/simple_unit/I18N/ChoiceFormatTest.php deleted file mode 100644 index 809d46b4..00000000 --- a/tests/simple_unit/I18N/ChoiceFormatTest.php +++ /dev/null @@ -1,98 +0,0 @@ -assertEqual($want, $choice->format($string, 0)); - - $want = 'is one file'; - $this->assertEqual($want, $choice->format($string, 1)); - - $want = 'are {number} files'; - $this->assertEqual($want, $choice->format($string, 5)); - - $this->assertFalse($choice->format($string, -1)); - - $string = '{1,2} one two |{3,4} three four |[2,5] two to five inclusive'; - $this->assertEqual($choice->format($string,1),'one two'); - $this->assertEqual($choice->format($string,2.1),'two to five inclusive'); - $this->assertEqual($choice->format($string,3),'three four'); - } - - function test_set_notation() - { - $choice = new ChoiceFormat(); - $string = '{n: n%2 == 0} are even numbers |{n: n >= 5} are not even and greater than or equal to 5'; - - $want = 'are even numbers'; - $this->assertEqual($want, $choice->format($string, 0)); - $this->assertEqual($want, $choice->format($string, 2)); - $this->assertEqual($want, $choice->format($string, 4)); - $this->assertNotEqual($want, $choice->format($string, 1)); - - $want = 'are not even and greater than or equal to 5'; - $this->assertEqual($want, $choice->format($string, 5)); - } - - function test_polish() - { - $choice = new ChoiceFormat(); - $string = '[1] plik |{2,3,4} pliki - |[5,21] pliko\'w |{n: n % 10 > 1 && n %10 < 5} pliki |{n: n%10 >= 5 || n%10 <=1} pliko\'w'; - - $wants = array( 'plik' => array(1), - 'pliki' => array(2,3,4,22,23,24), - 'pliko\'w' => array(5,6,7,11,12,15,17,20,21,25,26,30)); - foreach($wants as $want => $numbers) - { - foreach($numbers as $n) - $this->assertEqual($want, $choice->format($string, $n)); - } - } - - function test_russian() - { - $choice = new ChoiceFormat(); - $string = ' - {n: n % 10 == 1 && n % 100 != 11} test1 - |{n: n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 )} test2 - |{n: 2} test3'; - - $wants = array('test1' => array(1,21,31,41), - 'test2' => array(2,4, 22, 24, 32, 34), - 'test3' => array(0, 5,6,7,8,9,10,11,12,13,14, 20,25,26,30) - ); - foreach($wants as $want => $numbers) - { - foreach($numbers as $n) - $this->assertEqual($want, $choice->format($string, $n)); - } - } - - function test_english() - { - $choice = new ChoiceFormat(); - $string = '[0] none |{n: n % 10 == 1} 1st |{n: n % 10 == 2} 2nd |{n: n % 10 == 3} 3rd |{n:n} th'; - - $wants = array('none' => array(0), - '1st' => array(1,11,21), - '2nd' => array(2,12,22), - '3rd' => array(3,13,23), - 'th' => array(4,5,6,7,14,15) - ); - foreach($wants as $want => $numbers) - { - foreach($numbers as $n) - $this->assertEqual($want, $choice->format($string, $n)); - } - } -} - -?> \ No newline at end of file diff --git a/tests/simple_unit/I18N/CultureInfoTest.php b/tests/simple_unit/I18N/CultureInfoTest.php deleted file mode 100644 index 7df7deeb..00000000 --- a/tests/simple_unit/I18N/CultureInfoTest.php +++ /dev/null @@ -1,13 +0,0 @@ -assertEqual($culture->getEnglishName(), 'iw'); - } -} - -?> \ No newline at end of file diff --git a/tests/simple_unit/runtime/.gitignore b/tests/simple_unit/runtime/.gitignore old mode 100644 new mode 100755 diff --git a/tests/unit/I18N/core/ChoiceFormatTest.php b/tests/unit/I18N/core/ChoiceFormatTest.php new file mode 100644 index 00000000..ef397e05 --- /dev/null +++ b/tests/unit/I18N/core/ChoiceFormatTest.php @@ -0,0 +1,101 @@ +assertEquals($want, $choice->format($string, 0)); + + $want = 'is one file'; + $this->assertEquals($want, $choice->format($string, 1)); + + $want = 'are {number} files'; + $this->assertEquals($want, $choice->format($string, 5)); + + $this->assertFalse($choice->format($string, -1)); + + $string = '{1,2} one two |{3,4} three four |[2,5] two to five inclusive'; + $this->assertEquals($choice->format($string,1),'one two'); + $this->assertEquals($choice->format($string,2.1),'two to five inclusive'); + $this->assertEquals($choice->format($string,3),'three four'); + } + + function test_set_notation() + { + $choice = new ChoiceFormat(); + $string = '{n: n%2 == 0} are even numbers |{n: n >= 5} are not even and greater than or equal to 5'; + + $want = 'are even numbers'; + $this->assertEquals($want, $choice->format($string, 0)); + $this->assertEquals($want, $choice->format($string, 2)); + $this->assertEquals($want, $choice->format($string, 4)); + $this->assertNotEquals($want, $choice->format($string, 1)); + + $want = 'are not even and greater than or equal to 5'; + $this->assertEquals($want, $choice->format($string, 5)); + } + + function test_polish() + { + $choice = new ChoiceFormat(); + $string = '[1] plik |{2,3,4} pliki + |[5,21] pliko\'w |{n: n % 10 > 1 && n %10 < 5} pliki |{n: n%10 >= 5 || n%10 <=1} pliko\'w'; + + $wants = array( 'plik' => array(1), + 'pliki' => array(2,3,4,22,23,24), + 'pliko\'w' => array(5,6,7,11,12,15,17,20,21,25,26,30)); + foreach($wants as $want => $numbers) + { + foreach($numbers as $n) + $this->assertEquals($want, $choice->format($string, $n)); + } + } + + function test_russian() + { + $choice = new ChoiceFormat(); + $string = ' + {n: n % 10 == 1 && n % 100 != 11} test1 + |{n: n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 )} test2 + |{n: 2} test3'; + + $wants = array('test1' => array(1,21,31,41), + 'test2' => array(2,4, 22, 24, 32, 34), + 'test3' => array(0, 5,6,7,8,9,10,11,12,13,14, 20,25,26,30) + ); + foreach($wants as $want => $numbers) + { + foreach($numbers as $n) + $this->assertEquals($want, $choice->format($string, $n)); + } + } + + function test_english() + { + $choice = new ChoiceFormat(); + $string = '[0] none |{n: n % 10 == 1} 1st |{n: n % 10 == 2} 2nd |{n: n % 10 == 3} 3rd |{n:n} th'; + + $wants = array('none' => array(0), + '1st' => array(1,11,21), + '2nd' => array(2,12,22), + '3rd' => array(3,13,23), + 'th' => array(4,5,6,7,14,15) + ); + foreach($wants as $want => $numbers) + { + foreach($numbers as $n) + $this->assertEquals($want, $choice->format($string, $n)); + } + } +} + +?> \ No newline at end of file diff --git a/tests/unit/I18N/core/CultureInfoTest.php b/tests/unit/I18N/core/CultureInfoTest.php index 0a96639f..6c1eda06 100644 --- a/tests/unit/I18N/core/CultureInfoTest.php +++ b/tests/unit/I18N/core/CultureInfoTest.php @@ -76,6 +76,12 @@ class CultureInfoTest extends PHPUnit_Framework_TestCase { "Los Angeles"); $this->assertEquals($culture->TimeZones[1],$zone); } + + function test_missing_english_names_returns_culture_code() + { + $culture = new CultureInfo('iw'); + $this->assertEquals($culture->getEnglishName(), 'iw'); + } } ?> \ No newline at end of file -- cgit v1.2.3