MediaWiki  1.23.13
CLDRPluralRuleEvaluatorTest.php
Go to the documentation of this file.
1 <?php
14  function testValidRules( $expected, $rules, $number, $comment ) {
15  $result = CLDRPluralRuleEvaluator::evaluate( $number, (array)$rules );
16  $this->assertEquals( $expected, $result, $comment );
17  }
18 
23  function testInvalidRules( $rules, $comment ) {
25  }
26 
27  function validTestCases() {
28  $tests = array(
29  # expected, rule, number, comment
30  array( 0, 'n is 1', 1, 'integer number and is' ),
31  array( 0, 'n is 1', "1", 'string integer number and is' ),
32  array( 0, 'n is 1', 1.0, 'float number and is' ),
33  array( 0, 'n is 1', "1.0", 'string float number and is' ),
34  array( 1, 'n is 1', 1.1, 'float number and is' ),
35  array( 1, 'n is 1', 2, 'float number and is' ),
36 
37  array( 0, 'n in 1,3,5', 3, '' ),
38  array( 1, 'n not in 1,3,5', 5, '' ),
39 
40  array( 1, 'n in 1,3,5', 2, '' ),
41  array( 0, 'n not in 1,3,5', 4, '' ),
42 
43  array( 0, 'n in 1..3', 2, '' ),
44  array( 0, 'n in 1..3', 3, 'in is inclusive' ),
45  array( 1, 'n in 1..3', 0, '' ),
46 
47  array( 1, 'n not in 1..3', 2, '' ),
48  array( 1, 'n not in 1..3', 3, 'in is inclusive' ),
49  array( 0, 'n not in 1..3', 0, '' ),
50 
51  array( 1, 'n is not 1 and n is not 2 and n is not 3', 1, 'and relation' ),
52  array( 0, 'n is not 1 and n is not 2 and n is not 4', 3, 'and relation' ),
53 
54  array( 0, 'n is not 1 or n is 1', 1, 'or relation' ),
55  array( 1, 'n is 1 or n is 2', 3, 'or relation' ),
56 
57  array( 0, 'n is 1', 1, 'extra whitespace' ),
58 
59  array( 0, 'n mod 3 is 1', 7, 'mod' ),
60  array( 0, 'n mod 3 is not 1', 4.3, 'mod with floats' ),
61 
62  array( 0, 'n within 1..3', 2, 'within with integer' ),
63  array( 0, 'n within 1..3', 2.5, 'within with float' ),
64  array( 0, 'n in 1..3', 2, 'in with integer' ),
65  array( 1, 'n in 1..3', 2.5, 'in with float' ),
66 
67  array( 0, 'n in 3 or n is 4 and n is 5', 3, 'and binds more tightly than or' ),
68  array( 1, 'n is 3 or n is 4 and n is 5', 4, 'and binds more tightly than or' ),
69 
70  array( 0, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 24, 'breton rule' ),
71  array( 1, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 25, 'breton rule' ),
72 
73  array( 0, 'n within 0..2 and n is not 2', 0, 'french rule' ),
74  array( 0, 'n within 0..2 and n is not 2', 1, 'french rule' ),
75  array( 0, 'n within 0..2 and n is not 2', 1.2, 'french rule' ),
76  array( 1, 'n within 0..2 and n is not 2', 2, 'french rule' ),
77 
78  array( 1, 'n in 3..10,13..19', 2, 'scottish rule - ranges with comma' ),
79  array( 0, 'n in 3..10,13..19', 4, 'scottish rule - ranges with comma' ),
80  array( 1, 'n in 3..10,13..19', 12.999, 'scottish rule - ranges with comma' ),
81  array( 0, 'n in 3..10,13..19', 13, 'scottish rule - ranges with comma' ),
82 
83  array( 0, '5 mod 3 is n', 2, 'n as result of mod - no need to pass' ),
84 
85  # Revision 33 new operand examples
86  # expected, rule, number, comment
87  array( 0, 'i is 1', '1.00', 'new operand i' ),
88  array( 0, 'v is 2', '1.00', 'new operand v' ),
89  array( 0, 'w is 0', '1.00', 'new operand w' ),
90  array( 0, 'f is 0', '1.00', 'new operand f' ),
91  array( 0, 't is 0', '1.00', 'new operand t' ),
92 
93  array( 0, 'i is 1', '1.30', 'new operand i' ),
94  array( 0, 'v is 2', '1.30', 'new operand v' ),
95  array( 0, 'w is 1', '1.30', 'new operand w' ),
96  array( 0, 'f is 30', '1.30', 'new operand f' ),
97  array( 0, 't is 3', '1.30', 'new operand t' ),
98 
99  array( 0, 'i is 1', '1.03', 'new operand i' ),
100  array( 0, 'v is 2', '1.03', 'new operand v' ),
101  array( 0, 'w is 2', '1.03', 'new operand w' ),
102  array( 0, 'f is 3', '1.03', 'new operand f' ),
103  array( 0, 't is 3', '1.03', 'new operand t' ),
104 
105  # Revision 33 new operator aliases
106  # expected, rule, number, comment
107  array( 0, 'n % 3 is 1', 7, 'new % operator' ),
108  array( 0, 'n = 1,3,5', 3, 'new = operator' ),
109  array( 1, 'n != 1,3,5', 5, 'new != operator' ),
110 
111  # Revision 33 samples
112  # expected, rule, number, comment
113  array( 0, 'n in 1,3,5@integer 3~10, 103~110, 1003, … @decimal 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 103.0, 1003.0, …', 3, 'samples' ),
114 
115  # Revision 33 some test cases from CLDR
116  array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.1', 'pt one' ),
117  array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.01', 'pt one' ),
118  array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.10', 'pt one' ),
119  array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.010', 'pt one' ),
120  array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.100', 'pt one' ),
121  array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.0', 'pt other' ),
122  array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.2', 'pt other' ),
123  array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '10.0', 'pt other' ),
124  array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '100.0', 'pt other' ),
125  array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '2', 'bs few' ),
126  array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '4', 'bs few' ),
127  array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '22', 'bs few' ),
128  array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '102', 'bs few' ),
129  array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '0.2', 'bs few' ),
130  array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '0.4', 'bs few' ),
131  array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.2', 'bs few' ),
132  array( 1, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.0', 'bs other' ),
133 
134  );
135 
136  return $tests;
137  }
138 
139  function invalidTestCases() {
140  $tests = array(
141  array( 'n mod mod 5 is 1', 'mod mod' ),
142  array( 'n', 'just n' ),
143  array( 'n is in 5', 'is in' ),
144  );
145 
146  return $tests;
147  }
148 }
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
CLDRPluralRuleEvaluatorTest\testValidRules
testValidRules( $expected, $rules, $number, $comment)
@dataProvider validTestCases
Definition: CLDRPluralRuleEvaluatorTest.php:14
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Revision
Definition: Revision.php:26
CLDRPluralRuleEvaluatorTest
@covers CLDRPluralRuleEvaluator
Definition: CLDRPluralRuleEvaluatorTest.php:10
CLDRPluralRuleEvaluatorTest\testInvalidRules
testInvalidRules( $rules, $comment)
@dataProvider invalidTestCases @expectedException CLDRPluralRuleError
Definition: CLDRPluralRuleEvaluatorTest.php:23
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$comment
$comment
Definition: importImages.php:107
cases
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those cases
Definition: All_system_messages.txt:2677
CLDRPluralRuleEvaluatorTest\validTestCases
validTestCases()
Definition: CLDRPluralRuleEvaluatorTest.php:27
CLDRPluralRuleEvaluatorTest\invalidTestCases
invalidTestCases()
Definition: CLDRPluralRuleEvaluatorTest.php:139
some
I won t presume to tell you how to I m just describing the methods I chose to use for myself If you do choose to follow these it will probably be easier for you to collaborate with others on the but if you want to contribute without by all means do which work well I also use K &R brace matching style I know that s a religious issue for some
Definition: design.txt:79
from
Please log in again after you receive it</td >< td > s a saved copy from
Definition: All_system_messages.txt:3297
CLDRPluralRuleEvaluator\evaluate
static evaluate( $number, array $rules)
Evaluate a number against a set of plural rules.
Definition: CLDRPluralRuleEvaluator.php:43