Merge "Define 'MW_UPDATER' when running update.php"
[mediawiki.git] / tests / qunit / suites / resources / mediawiki / mediawiki.cldr.test.js
blob779a0ed48dfeab7834e97cb33fa9f8c265fd5c95
1 ( function ( mw, $ ) {
2         QUnit.module( 'mediawiki.cldr', QUnit.newMwEnvironment() );
4         var pluralTestcases = {
5                 /*
6                  * Sample:
7                  * languagecode : [
8                  *   [ number, [ 'form1', 'form2', ... ],  'expected', 'description' ]
9                  * ];
10                  */
11                 en: [
12                         [ 0, [ 'one', 'other' ], 'other', 'English plural test- 0 is other' ],
13                         [ 1, [ 'one', 'other' ], 'one', 'English plural test- 1 is one' ]
14                 ],
15                 fa: [
16                         [ 0, [ 'one', 'other' ], 'other', 'Persian plural test- 0 is other' ],
17                         [ 1, [ 'one', 'other' ], 'one', 'Persian plural test- 1 is one' ],
18                         [ 2, [ 'one', 'other' ], 'other', 'Persian plural test- 2 is other' ]
19                 ],
20                 fr: [
21                         [ 0, [ 'one', 'other' ], 'other', 'French plural test- 0 is other' ],
22                         [ 1, [ 'one', 'other' ], 'one', 'French plural test- 1 is one' ]
23                 ],
24                 hi: [
25                         [ 0, [ 'one', 'other' ], 'one', 'Hindi plural test- 0 is one' ],
26                         [ 1, [ 'one', 'other' ], 'one', 'Hindi plural test- 1 is one' ],
27                         [ 2, [ 'one', 'other' ], 'other', 'Hindi plural test- 2 is other' ]
28                 ],
29                 he: [
30                         [ 0, [ 'one', 'other' ], 'other', 'Hebrew plural test- 0 is other' ],
31                         [ 1, [ 'one', 'other' ], 'one', 'Hebrew plural test- 1 is one' ],
32                         [ 2, [ 'one', 'other' ], 'other', 'Hebrew plural test- 2 is other with 2 forms' ],
33                         [ 2, [ 'one', 'dual', 'other' ], 'dual', 'Hebrew plural test- 2 is dual with 3 forms' ]
34                 ],
35                 hu: [
36                         [ 0, [ 'one', 'other' ], 'other', 'Hungarian plural test- 0 is other' ],
37                         [ 1, [ 'one', 'other' ], 'one', 'Hungarian plural test- 1 is one' ],
38                         [ 2, [ 'one', 'other' ], 'other', 'Hungarian plural test- 2 is other' ]
39                 ],
40                 hy: [
41                         [ 0, [ 'one', 'other' ], 'other', 'Armenian plural test- 0 is other' ],
42                         [ 1, [ 'one', 'other' ], 'one', 'Armenian plural test- 1 is one' ],
43                         [ 2, [ 'one', 'other' ], 'other', 'Armenian plural test- 2 is other' ]
44                 ],
45                 ar: [
46                         [ 0, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'zero', 'Arabic plural test - 0 is zero' ],
47                         [ 1, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'one', 'Arabic plural test - 1 is one' ],
48                         [ 2, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'two', 'Arabic plural test - 2 is two' ],
49                         [ 3, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'few', 'Arabic plural test - 3 is few' ],
50                         [ 9, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'few', 'Arabic plural test - 9 is few' ],
51                         [ '9', [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'few', 'Arabic plural test - 9 is few' ],
52                         [ 110, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'few', 'Arabic plural test - 110 is few' ],
53                         [ 11, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'many', 'Arabic plural test - 11 is many' ],
54                         [ 15, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'many', 'Arabic plural test - 15 is many' ],
55                         [ 99, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'many', 'Arabic plural test - 99 is many' ],
56                         [ 9999, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'many', 'Arabic plural test - 9999 is many' ],
57                         [ 100, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'other', 'Arabic plural test - 100 is other' ],
58                         [ 102, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'other', 'Arabic plural test - 102 is other' ],
59                         [ 1000, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'other', 'Arabic plural test - 1000 is other' ],
60                         [ 1.7, [ 'zero', 'one', 'two', 'few', 'many', 'other' ], 'other', 'Arabic plural test - 1.7 is other' ]
61                 ]
62         };
64         function pluralTest( langCode, tests ) {
65                 QUnit.test( 'Plural Test for ' + langCode, tests.length, function ( assert ) {
66                         for ( var i = 0; i < tests.length; i++ ) {
67                                 assert.equal(
68                                         mw.language.convertPlural( tests[i][0], tests[i][1] ),
69                                         tests[i][2],
70                                         tests[i][3]
71                                 );
72                         }
73                 } );
74         }
76         $.each( pluralTestcases, function ( langCode, tests ) {
77                 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
78                         pluralTest( langCode, tests );
79                 }
80         } );
81 }( mediaWiki, jQuery ) );