4 QUnit.module( 'mediawiki.language', QUnit.newMwEnvironment( {
6 this.liveLangData = mw.language.data.values;
7 mw.language.data.values = $.extend( true, {}, this.liveLangData );
9 teardown: function () {
10 mw.language.data.values = this.liveLangData;
14 QUnit.test( 'mw.language getData and setData', 2, function ( assert ) {
15 mw.language.setData( 'en', 'testkey', 'testvalue' );
16 assert.equal( mw.language.getData( 'en', 'testkey' ), 'testvalue', 'Getter setter test for mw.language' );
17 assert.equal( mw.language.getData( 'en', 'invalidkey' ), undefined, 'Getter setter test for mw.language with invalid key' );
20 QUnit.test( 'mw.language.commafy test', 9, function ( assert ) {
21 // Number grouping patterns are as per http://cldr.unicode.org/translation/number-patterns
22 assert.equal( mw.language.commafy( 1234.567, '###0.#####' ), '1234.567', 'Pattern with no digit grouping separator defined' );
23 assert.equal( mw.language.commafy( 123456789.567, '###0.#####' ), '123456789.567', 'Pattern with no digit grouping seperator defined, bigger decimal part' );
24 assert.equal( mw.language.commafy( 0.567, '###0.#####' ), '0.567', 'Decimal part 0' );
25 assert.equal( mw.language.commafy( '.567', '###0.#####' ), '0.567', 'Decimal part missing. replace with zero' );
26 assert.equal( mw.language.commafy( 1234, '##,#0.#####' ), '12,34', 'Pattern with no fractional part' );
27 assert.equal( mw.language.commafy( -1234.567, '###0.#####' ), '-1234.567', 'Negative number' );
28 assert.equal( mw.language.commafy( -1234.567, '#,###.00' ), '-1,234.56', 'Fractional part bigger than pattern.' );
29 assert.equal( mw.language.commafy( 123456789.567, '###,##0.00' ), '123,456,789.56', 'Decimal part as group of 3' );
30 assert.equal( mw.language.commafy( 123456789.567, '###,###,#0.00' ), '1,234,567,89.56', 'Decimal part as group of 3 and last one 2' );
33 function grammarTest( langCode, test ) {
34 // The test works only if the content language is opt.language
35 // because it requires [lang].js to be loaded.
36 QUnit.test( 'Grammar test for lang=' + langCode, function ( assert ) {
37 QUnit.expect( test.length );
39 for ( var i = 0; i < test.length; i++ ) {
41 mw.language.convertGrammar( test[i].word, test[i].grammarForm ),
49 // These tests run only for the current UI language.
54 grammarForm: 'instrumental',
56 description: 'Grammar test for instrumental case'
60 grammarForm: 'lokativ',
62 description: 'Grammar test for lokativ case'
69 grammarForm: 'prefixed',
70 expected: 'וויקיפדיה',
71 description: 'Duplicate the "Waw" if prefixed'
75 grammarForm: 'prefixed',
77 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
81 grammarForm: 'prefixed',
83 description: 'Remove the "He" if prefixed'
87 grammarForm: 'תחילית',
88 expected: '־Wikipedia',
89 description: 'GAdd a hyphen (maqaf) before non-Hebrew letters'
93 grammarForm: 'תחילית',
95 description: 'Add a hyphen (maqaf) before numbers'
102 grammarForm: 'instrumental',
104 description: 'Grammar test for instrumental case'
108 grammarForm: 'lokatiw',
110 description: 'Grammar test for lokatiw case'
117 grammarForm: 'instrumental',
119 description: 'Grammar test for instrumental case'
123 grammarForm: 'lokatiw',
125 description: 'Grammar test for lokatiw case'
132 grammarForm: 'genitive',
133 expected: 'Մաունայի',
134 description: 'Grammar test for genitive case'
138 grammarForm: 'genitive',
140 description: 'Grammar test for genitive case'
144 grammarForm: 'genitive',
146 description: 'Grammar test for genitive case'
150 grammarForm: 'genitive',
151 expected: 'ժամանակիի',
152 description: 'Grammar test for genitive case'
159 grammarForm: 'genitive',
161 description: 'Grammar test for genitive case'
165 grammarForm: 'genitive',
167 description: 'Grammar test for genitive case'
171 grammarForm: 'elative',
173 description: 'Grammar test for elative case'
177 grammarForm: 'partitive',
178 expected: 'pastöroitua',
179 description: 'Grammar test for partitive case'
183 grammarForm: 'partitive',
185 description: 'Grammar test for partitive case'
189 grammarForm: 'illative',
191 description: 'Grammar test for illative case'
195 grammarForm: 'inessive',
196 expected: 'linuxissa',
197 description: 'Grammar test for inessive case'
204 grammarForm: 'genitive',
206 description: 'Grammar test for genitive case, тесть -> тестя'
210 grammarForm: 'genitive',
211 expected: 'привилегии',
212 description: 'Grammar test for genitive case, привилегия -> привилегии'
216 grammarForm: 'genitive',
217 expected: 'установки',
218 description: 'Grammar test for genitive case, установка -> установки'
222 grammarForm: 'genitive',
224 description: 'Grammar test for genitive case, похоти -> похотей'
228 grammarForm: 'genitive',
230 description: 'Grammar test for genitive case, доводы -> доводов'
234 grammarForm: 'genitive',
235 expected: 'песчаника',
236 description: 'Grammar test for genitive case, песчаник -> песчаника'
240 grammarForm: 'genitive',
242 description: 'Grammar test for genitive case, данные -> данных'
246 grammarForm: 'prepositional',
248 description: 'Grammar test for prepositional case, тесть -> тесте'
252 grammarForm: 'prepositional',
253 expected: 'привилегии',
254 description: 'Grammar test for prepositional case, привилегия -> привилегии'
258 grammarForm: 'prepositional',
259 expected: 'установке',
260 description: 'Grammar test for prepositional case, установка -> установке'
264 grammarForm: 'prepositional',
266 description: 'Grammar test for prepositional case, похоти -> похотях'
270 grammarForm: 'prepositional',
272 description: 'Grammar test for prepositional case, доводы -> доводах'
276 grammarForm: 'prepositional',
277 expected: 'Викискладе',
278 description: 'Grammar test for prepositional case, Викисклад -> Викискладе'
282 grammarForm: 'genitive',
283 expected: 'Викисклада',
284 description: 'Grammar test for genitive case, Викисклад -> Викисклада'
288 grammarForm: 'prepositional',
289 expected: 'песчанике',
290 description: 'Grammar test for prepositional case, песчаник -> песчанике'
294 grammarForm: 'prepositional',
296 description: 'Grammar test for prepositional case, данные -> данных'
304 expected: 'Wikipédiáról',
305 description: 'Grammar test for rol case'
310 expected: 'Wikipédiába',
311 description: 'Grammar test for ba case'
316 expected: 'Wikipédiák',
317 description: 'Grammar test for k case'
324 grammarForm: 'ainmlae',
325 expected: 'Dé Domhnaigh',
326 description: 'Grammar test for ainmlae case'
330 grammarForm: 'ainmlae',
331 expected: 'Dé Luain',
332 description: 'Grammar test for ainmlae case'
336 grammarForm: 'ainmlae',
337 expected: 'Dé Sathairn',
338 description: 'Grammar test for ainmlae case'
345 grammarForm: 'genitive',
347 description: 'Grammar test for genitive case'
351 grammarForm: 'genitive',
352 expected: 'Вікіпедії',
353 description: 'Grammar test for genitive case'
357 grammarForm: 'genitive',
358 expected: 'установки',
359 description: 'Grammar test for genitive case'
363 grammarForm: 'genitive',
365 description: 'Grammar test for genitive case'
369 grammarForm: 'genitive',
371 description: 'Grammar test for genitive case'
375 grammarForm: 'genitive',
376 expected: 'песчаника',
377 description: 'Grammar test for genitive case'
381 grammarForm: 'accusative',
382 expected: 'Вікіпедію',
383 description: 'Grammar test for accusative case'
390 grammarForm: 'orodnik',
392 description: 'Grammar test for orodnik case'
396 grammarForm: 'mestnik',
398 description: 'Grammar test for mestnik case'
405 grammarForm: 'genitive',
407 description: 'Grammar test for genitive case'
411 grammarForm: 'allative',
413 description: 'Grammar test for allative case'
417 grammarForm: 'dative',
419 description: 'Grammar test for dative case'
423 grammarForm: 'dative',
424 expected: 'цъитийæн',
425 description: 'Grammar test for dative case'
429 grammarForm: 'genitive',
431 description: 'Grammar test for genitive case'
435 grammarForm: 'equative',
437 description: 'Grammar test for equative case'
444 grammarForm: 'genitive',
445 expected: 'Translationis',
446 description: 'Grammar test for genitive case'
450 grammarForm: 'accusative',
451 expected: 'Translationem',
452 description: 'Grammar test for accusative case'
456 grammarForm: 'ablative',
457 expected: 'Translatione',
458 description: 'Grammar test for ablative case'
463 $.each( grammarTests, function ( langCode, test ) {
464 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
465 grammarTest( langCode, test );
469 QUnit.test( 'List to text test', 4, function ( assert ) {
470 assert.equal( mw.language.listToText( [] ), '', 'Blank list' );
471 assert.equal( mw.language.listToText( ['a'] ), 'a', 'Single item' );
472 assert.equal( mw.language.listToText( ['a', 'b'] ), 'a and b', 'Two items' );
473 assert.equal( mw.language.listToText( ['a', 'b', 'c'] ), 'a, b and c', 'More than two items' );
475 }( mediaWiki, jQuery ) );