Remove all custom plural rules and use CLDR plural rule system
[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 "fa": [
20 [ 0, [ "one", "other" ], "other", "Persian plural test- 0 is other" ],
21 [ 1, [ "one", "other" ], "one", "Persian plural test- 1 is one" ],
22 [ 2, [ "one", "other" ], "other", "Persian plural test- 2 is other" ]
23 ],
24 "fr": [
25 [ 0, [ "one", "other" ], "other", "French plural test- 0 is other" ],
26 [ 1, [ "one", "other" ], "one", "French plural test- 1 is one" ]
27 ],
28 "hi": [
29 [ 0, [ "one", "other" ], "one", "Hindi plural test- 0 is one" ],
30 [ 1, [ "one", "other" ], "one", "Hindi plural test- 1 is one" ],
31 [ 2, [ "one", "other" ], "other", "Hindi plural test- 2 is other" ]
32 ],
33 "he": [
34 [ 0, [ "one", "other" ], "other", "Hebrew plural test- 0 is other" ],
35 [ 1, [ "one", "other" ], "one", "Hebrew plural test- 1 is one" ],
36 [ 2, [ "one", "other" ], "other", "Hebrew plural test- 2 is other with 2 forms" ],
37 [ 2, [ "one", "dual", "other" ], "dual", "Hebrew plural test- 2 is dual with 3 forms" ]
38 ],
39 "hu": [
40 [ 0, [ "one", "other" ], "other", "Hungarian plural test- 0 is other" ],
41 [ 1, [ "one", "other" ], "one", "Hungarian plural test- 1 is one" ],
42 [ 2, [ "one", "other" ], "other", "Hungarian plural test- 2 is other" ]
43 ],
44 "ar": [
45 [ 0, [ "zero", "one", "two", "few", "many", "other" ], "zero", "Arabic plural test - 0 is zero" ],
46 [ 1, [ "zero", "one", "two", "few", "many", "other" ], "one", "Arabic plural test - 1 is one" ],
47 [ 2, [ "zero", "one", "two", "few", "many", "other" ], "two", "Arabic plural test - 2 is two" ],
48 [ 3, [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 3 is few" ],
49 [ 9, [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 9 is few" ],
50 [ "9", [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 9 is few" ],
51 [ 110, [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 110 is few" ],
52 [ 11, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 11 is many" ],
53 [ 15, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 15 is many" ],
54 [ 99, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 99 is many" ],
55 [ 9999, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 9999 is many" ],
56 [ 100, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 100 is other" ],
57 [ 102, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 102 is other" ],
58 [ 1000, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1000 is other" ]
59 // FIXME plural rules for decimal numbers does not work
60 // [ 1.7, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1.7 is other" ],
61 ]
62 };
63
64 function pluralTest( langCode, tests ) {
65 QUnit.test('-- Plural Test for ' + langCode, function( assert ) {
66 QUnit.expect( tests.length );
67 for ( var i = 0; i < tests.length; i++ ) {
68 assert.equal(
69 mw.language.convertPlural( tests[i][0], tests[i][1] ),
70 tests[i][2], // Expected plural form
71 tests[i][3] // Description
72 );
73 }
74 } );
75 }
76
77 $.each( pluralTestcases, function( langCode, tests ) {
78 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
79 pluralTest( langCode, tests );
80 }
81 } );