Index: trunk/phase3/tests/phpunit/includes/GlobalTest.php |
— | — | @@ -633,6 +633,61 @@ |
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
| 637 | + * test @see wfShorthandToInteger() |
| 638 | + * @dataProvider provideShorthand |
| 639 | + */ |
| 640 | + public function testWfShorthandToInteger( $shorthand, $expected ) { |
| 641 | + $this->assertEquals( $expected, |
| 642 | + wfShorthandToInteger( $shorthand ) |
| 643 | + ); |
| 644 | + } |
| 645 | + |
| 646 | + /** array( shorthand, expected integer ) */ |
| 647 | + public function provideShorthand() { |
| 648 | + return array( |
| 649 | + # Null, empty ... |
| 650 | + array( '', -1), |
| 651 | + array( ' ', -1), |
| 652 | + array( null, -1), |
| 653 | + |
| 654 | + # Failures returns 0 :( |
| 655 | + array( 'ABCDEFG', 0 ), |
| 656 | + array( 'Ak', 0 ), |
| 657 | + |
| 658 | + # Int, strings with spaces |
| 659 | + array( 1, 1 ), |
| 660 | + array( ' 1 ', 1 ), |
| 661 | + array( 1023, 1023 ), |
| 662 | + array( ' 1023 ', 1023 ), |
| 663 | + |
| 664 | + # kilo, Mega, Giga |
| 665 | + array( '1k', 1024 ), |
| 666 | + array( '1K', 1024 ), |
| 667 | + array( '1m', 1024 * 1024 ), |
| 668 | + array( '1M', 1024 * 1024 ), |
| 669 | + array( '1g', 1024 * 1024 * 1024 ), |
| 670 | + array( '1G', 1024 * 1024 * 1024 ), |
| 671 | + |
| 672 | + # Negatives |
| 673 | + array( -1, -1 ), |
| 674 | + array( -500, -500 ), |
| 675 | + array( '-500', -500 ), |
| 676 | + array( '-1k', -1024 ), |
| 677 | + |
| 678 | + # Zeroes |
| 679 | + array( '0', 0 ), |
| 680 | + array( '0k', 0 ), |
| 681 | + array( '0M', 0 ), |
| 682 | + array( '0G', 0 ), |
| 683 | + array( '-0', 0 ), |
| 684 | + array( '-0k', 0 ), |
| 685 | + array( '-0M', 0 ), |
| 686 | + array( '-0G', 0 ), |
| 687 | + ); |
| 688 | + } |
| 689 | + |
| 690 | + |
| 691 | + /** |
637 | 692 | * test @see wfBCP47(). |
638 | 693 | * Please note the BCP explicitly state that language codes are case |
639 | 694 | * insensitive, there are some exceptions to the rule :) |