Merge "Revert "Setting up a way to have uploading by URL, but not on Special:Upload""
[lhc/web/wiklou.git] / tests / phpunit / languages / utils / CLDRPluralRuleEvaluatorTest.php
1 <?php
2 /**
3 * @author Niklas Laxström
4 * @file
5 */
6
7 class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase {
8 /**
9 * @dataProvider validTestCases
10 */
11 function testValidRules( $expected, $rules, $number, $comment ) {
12 $result = CLDRPluralRuleEvaluator::evaluate( $number, (array) $rules );
13 $this->assertEquals( $expected, $result, $comment );
14 }
15
16 /**
17 * @dataProvider invalidTestCases
18 * @expectedException CLDRPluralRuleError
19 */
20 function testInvalidRules( $rules, $comment ) {
21 CLDRPluralRuleEvaluator::evaluate( 1, (array) $rules );
22 }
23
24 function validTestCases() {
25 $tests = array(
26 # expected, number, rule, comment
27 array( 0, 'n is 1', 1, 'integer number and is' ),
28 array( 0, 'n is 1', "1", 'string integer number and is' ),
29 array( 0, 'n is 1', 1.0, 'float number and is' ),
30 array( 0, 'n is 1', "1.0", 'string float number and is' ),
31 array( 1, 'n is 1', 1.1, 'float number and is' ),
32 array( 1, 'n is 1', 2, 'float number and is' ),
33
34 array( 0, 'n in 1,3,5', 3, '' ),
35 array( 1, 'n not in 1,3,5', 5, '' ),
36
37 array( 1, 'n in 1,3,5', 2, '' ),
38 array( 0, 'n not in 1,3,5', 4, '' ),
39
40 array( 0, 'n in 1..3', 2, '' ),
41 array( 0, 'n in 1..3', 3, 'in is inclusive' ),
42 array( 1, 'n in 1..3', 0, '' ),
43
44 array( 1, 'n not in 1..3', 2, '' ),
45 array( 1, 'n not in 1..3', 3, 'in is inclusive' ),
46 array( 0, 'n not in 1..3', 0, '' ),
47
48 array( 1, 'n is not 1 and n is not 2 and n is not 3', 1, 'and relation' ),
49 array( 0, 'n is not 1 and n is not 2 and n is not 4', 3, 'and relation' ),
50
51 array( 0, 'n is not 1 or n is 1', 1, 'or relation' ),
52 array( 1, 'n is 1 or n is 2', 3, 'or relation' ),
53
54 array( 0, 'n is 1', 1, 'extra whitespace' ),
55
56 array( 0, 'n mod 3 is 1', 7, 'mod' ),
57 array( 0, 'n mod 3 is not 1', 4.3, 'mod with floats' ),
58
59 array( 0, 'n within 1..3', 2, 'within with integer' ),
60 array( 0, 'n within 1..3', 2.5, 'within with float' ),
61 array( 0, 'n in 1..3', 2, 'in with integer' ),
62 array( 1, 'n in 1..3', 2.5, 'in with float' ),
63
64 array( 0, 'n in 3 or n is 4 and n is 5', 3, 'and binds more tightly than or' ),
65 array( 1, 'n is 3 or n is 4 and n is 5', 4, 'and binds more tightly than or' ),
66
67 array( 0, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 24, 'breton rule' ),
68 array( 1, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 25, 'breton rule' ),
69
70 array( 0, 'n within 0..2 and n is not 2', 0, 'french rule' ),
71 array( 0, 'n within 0..2 and n is not 2', 1, 'french rule' ),
72 array( 0, 'n within 0..2 and n is not 2', 1.2, 'french rule' ),
73 array( 1, 'n within 0..2 and n is not 2', 2, 'french rule' ),
74
75 array( 1, 'n in 3..10,13..19', 2, 'scottish rule - ranges with comma' ),
76 array( 0, 'n in 3..10,13..19', 4, 'scottish rule - ranges with comma' ),
77 array( 1, 'n in 3..10,13..19', 12.999, 'scottish rule - ranges with comma' ),
78 array( 0, 'n in 3..10,13..19', 13, 'scottish rule - ranges with comma' ),
79
80 array( 0, '5 mod 3 is n', 2, 'n as result of mod - no need to pass' ),
81 );
82
83 return $tests;
84 }
85
86 function invalidTestCases() {
87 $tests = array(
88 array( 'n mod mod 5 is 1', 'mod mod' ),
89 array( 'n', 'just n' ),
90 array( 'n is in 5', 'is in' ),
91 );
92 return $tests;
93 }
94
95 }