09a11b0e510b44cade49ed26056a2df8d011d21a
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.cldr.test.js
1 module( 'mediawiki.cldr' );
2
3 test( '-- Initial check', function() {
4 expect( 1 );
5 ok( mw.cldr, 'mw.cldr defined' );
6 } );
7
8 var pluralTestcases = {
9 /*
10 * Sample:
11 *"languagecode" : [
12 * [ number, [ "form1", "form2", ... ], "expected", "description" ],
13 * ]
14 */
15 "en": [
16 [ 0, [ "one", "other" ], "other", "English plural test- 0 is other" ],
17 [ 1, [ "one", "other" ], "one", "English plural test- 1 is one" ]
18 ],
19 "hi": [
20 [ 0, [ "one", "other" ], "one", "Hindi plural test- 0 is one" ],
21 [ 1, [ "one", "other" ], "one", "Hindi plural test- 1 is one" ],
22 [ 2, [ "one", "other" ], "other", "Hindi plural test- 2 is other" ]
23 ],
24 "he": [
25 [ 0, [ "one", "other" ], "other", "Hebrew plural test- 0 is other" ],
26 [ 1, [ "one", "other" ], "one", "Hebrew plural test- 1 is one" ],
27 [ 2, [ "one", "other" ], "other", "Hebrew plural test- 2 is other with 2 forms" ],
28 [ 2, [ "one", "dual", "other" ], "dual", "Hebrew plural test- 2 is dual with 3 forms" ]
29 ],
30 "ar": [
31 [ 0, [ "zero", "one", "two", "few", "many", "other" ], "zero", "Arabic plural test - 0 is zero" ],
32 [ 1, [ "zero", "one", "two", "few", "many", "other" ], "one", "Arabic plural test - 1 is one" ],
33 [ 2, [ "zero", "one", "two", "few", "many", "other" ], "two", "Arabic plural test - 2 is two" ],
34 [ 3, [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 3 is few" ],
35 [ 9, [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 9 is few" ],
36 [ "9", [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 9 is few" ],
37 [ 110, [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 110 is few" ],
38 [ 11, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 11 is many" ],
39 [ 15, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 15 is many" ],
40 [ 99, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 99 is many" ],
41 [ 9999, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 9999 is many" ],
42 [ 100, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 100 is other" ],
43 [ 102, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 102 is other" ],
44 [ 1000, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1000 is other" ]
45 // FIXME plural rules for decimal numbers does not work
46 // [ 1.7, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1.7 is other" ],
47 ]
48 };
49
50 function pluralTest( langCode, tests ) {
51 QUnit.test('-- Plural Test for ' + langCode, function( assert ) {
52 QUnit.expect( tests.length );
53 for ( var i = 0; i < tests.length; i++ ) {
54 assert.equal(
55 mw.language.convertPlural( tests[i][0], tests[i][1] ),
56 tests[i][2], // Expected plural form
57 tests[i][3] // Description
58 );
59 }
60 } );
61 }
62
63 $.each( pluralTestcases, function( langCode, tests ) {
64 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
65 pluralTest( langCode, tests );
66 }
67 } );