From df928851f649b942e898160ac0ec6dedc17cee41 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 6 Feb 2011 18:02:47 +0000 Subject: [PATCH] wfShorthandToInteger() PHPUnit code coverage Some easy assertions. $ php phpunit.php --configuration suite.xml --filter Shorthand PHPUnit 3.5.10 by Sebastian Bergmann. ........................... Time: 2 seconds, Memory: 22.00Mb OK (27 tests, 27 assertions) --- tests/phpunit/includes/GlobalTest.php | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/phpunit/includes/GlobalTest.php b/tests/phpunit/includes/GlobalTest.php index a7ba796222..1cbb5dd896 100644 --- a/tests/phpunit/includes/GlobalTest.php +++ b/tests/phpunit/includes/GlobalTest.php @@ -632,6 +632,61 @@ class GlobalTest extends MediaWikiTestCase { } + /** + * test @see wfShorthandToInteger() + * @dataProvider provideShorthand + */ + public function testWfShorthandToInteger( $shorthand, $expected ) { + $this->assertEquals( $expected, + wfShorthandToInteger( $shorthand ) + ); + } + + /** array( shorthand, expected integer ) */ + public function provideShorthand() { + return array( + # Null, empty ... + array( '', -1), + array( ' ', -1), + array( null, -1), + + # Failures returns 0 :( + array( 'ABCDEFG', 0 ), + array( 'Ak', 0 ), + + # Int, strings with spaces + array( 1, 1 ), + array( ' 1 ', 1 ), + array( 1023, 1023 ), + array( ' 1023 ', 1023 ), + + # kilo, Mega, Giga + array( '1k', 1024 ), + array( '1K', 1024 ), + array( '1m', 1024 * 1024 ), + array( '1M', 1024 * 1024 ), + array( '1g', 1024 * 1024 * 1024 ), + array( '1G', 1024 * 1024 * 1024 ), + + # Negatives + array( -1, -1 ), + array( -500, -500 ), + array( '-500', -500 ), + array( '-1k', -1024 ), + + # Zeroes + array( '0', 0 ), + array( '0k', 0 ), + array( '0M', 0 ), + array( '0G', 0 ), + array( '-0', 0 ), + array( '-0k', 0 ), + array( '-0M', 0 ), + array( '-0G', 0 ), + ); + } + + /** * test @see wfBCP47(). * Please note the BCP explicitly state that language codes are case -- 2.20.1