4 QUnit.module( 'mediawiki.language', QUnit.newMwEnvironment( {
6 this.liveLangData = mw.language.data;
9 teardown: function () {
10 mw.language.data = this.liveLangData;
13 // mw.language.listToText test
15 'comma-separator': ', ',
20 QUnit.test( 'mw.language getData and setData', 3, function ( assert ) {
21 mw.language.setData( 'en', 'testkey', 'testvalue' );
22 assert.equal( mw.language.getData( 'en', 'testkey' ), 'testvalue', 'Getter setter test for mw.language' );
23 assert.equal( mw.language.getData( 'en', 'invalidkey' ), undefined, 'Getter setter test for mw.language with invalid key' );
24 mw.language.setData( 'en-us', 'testkey', 'testvalue' );
25 assert.equal( mw.language.getData( 'en-US', 'testkey' ), 'testvalue', 'Case insensitive test for mw.language' );
28 QUnit.test( 'mw.language.commafy test', 9, function ( assert ) {
29 mw.language.setData( 'en', 'digitGroupingPattern', null );
30 mw.language.setData( 'en', 'digitTransformTable', null );
31 mw.language.setData( 'en', 'separatorTransformTable', null );
33 mw.config.set( 'wgUserLanguage', 'en' );
34 // Number grouping patterns are as per http://cldr.unicode.org/translation/number-patterns
35 assert.equal( mw.language.commafy( 1234.567, '###0.#####' ), '1234.567', 'Pattern with no digit grouping separator defined' );
36 assert.equal( mw.language.commafy( 123456789.567, '###0.#####' ), '123456789.567', 'Pattern with no digit grouping separator defined, bigger decimal part' );
37 assert.equal( mw.language.commafy( 0.567, '###0.#####' ), '0.567', 'Decimal part 0' );
38 assert.equal( mw.language.commafy( '.567', '###0.#####' ), '0.567', 'Decimal part missing. replace with zero' );
39 assert.equal( mw.language.commafy( 1234, '##,#0.#####' ), '12,34', 'Pattern with no fractional part' );
40 assert.equal( mw.language.commafy( -1234.567, '###0.#####' ), '-1234.567', 'Negative number' );
41 assert.equal( mw.language.commafy( -1234.567, '#,###.00' ), '-1,234.56', 'Fractional part bigger than pattern.' );
42 assert.equal( mw.language.commafy( 123456789.567, '###,##0.00' ), '123,456,789.56', 'Decimal part as group of 3' );
43 assert.equal( mw.language.commafy( 123456789.567, '###,###,#0.00' ), '1,234,567,89.56', 'Decimal part as group of 3 and last one 2' );
46 QUnit.test( 'mw.language.convertNumber', 2, function ( assert ) {
47 mw.language.setData( 'en', 'digitGroupingPattern', null );
48 mw.language.setData( 'en', 'digitTransformTable', null );
49 mw.language.setData( 'en', 'separatorTransformTable', { ',': '.', '.': ',' } );
50 mw.config.set( 'wgUserLanguage', 'en' );
52 assert.equal( mw.language.convertNumber( 1800 ), '1.800', 'formatting' );
53 assert.equal( mw.language.convertNumber( '1.800', true ), '1800', 'unformatting' );
56 function grammarTest( langCode, test ) {
57 // The test works only if the content language is opt.language
58 // because it requires [lang].js to be loaded.
59 QUnit.test( 'Grammar test for lang=' + langCode, function ( assert ) {
60 QUnit.expect( test.length );
62 for ( var i = 0; i < test.length; i++ ) {
64 mw.language.convertGrammar( test[ i ].word, test[ i ].grammarForm ),
72 // These tests run only for the current UI language.
77 grammarForm: 'instrumental',
79 description: 'Grammar test for instrumental case'
83 grammarForm: 'lokativ',
85 description: 'Grammar test for lokativ case'
92 grammarForm: 'prefixed',
93 expected: 'וויקיפדיה',
94 description: 'Duplicate the "Waw" if prefixed'
98 grammarForm: 'prefixed',
100 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
104 grammarForm: 'prefixed',
106 description: 'Remove the "He" if prefixed'
110 grammarForm: 'תחילית',
111 expected: '־Wikipedia',
112 description: 'Add a hyphen (maqaf) before non-Hebrew letters'
116 grammarForm: 'תחילית',
118 description: 'Add a hyphen (maqaf) before numbers'
125 grammarForm: 'instrumental',
127 description: 'Grammar test for instrumental case'
131 grammarForm: 'lokatiw',
133 description: 'Grammar test for lokatiw case'
140 grammarForm: 'instrumental',
142 description: 'Grammar test for instrumental case'
146 grammarForm: 'lokatiw',
148 description: 'Grammar test for lokatiw case'
155 grammarForm: 'genitive',
156 expected: 'Մաունայի',
157 description: 'Grammar test for genitive case'
161 grammarForm: 'genitive',
163 description: 'Grammar test for genitive case'
167 grammarForm: 'genitive',
169 description: 'Grammar test for genitive case'
173 grammarForm: 'genitive',
174 expected: 'ժամանակիի',
175 description: 'Grammar test for genitive case'
182 grammarForm: 'genitive',
184 description: 'Grammar test for genitive case'
188 grammarForm: 'genitive',
190 description: 'Grammar test for genitive case'
194 grammarForm: 'elative',
196 description: 'Grammar test for elative case'
200 grammarForm: 'partitive',
201 expected: 'pastöroitua',
202 description: 'Grammar test for partitive case'
206 grammarForm: 'partitive',
208 description: 'Grammar test for partitive case'
212 grammarForm: 'illative',
214 description: 'Grammar test for illative case'
218 grammarForm: 'inessive',
219 expected: 'linuxissa',
220 description: 'Grammar test for inessive case'
227 grammarForm: 'genitive',
229 description: 'Grammar test for genitive case, тесть -> тестя'
233 grammarForm: 'genitive',
234 expected: 'привилегии',
235 description: 'Grammar test for genitive case, привилегия -> привилегии'
239 grammarForm: 'genitive',
240 expected: 'установки',
241 description: 'Grammar test for genitive case, установка -> установки'
245 grammarForm: 'genitive',
247 description: 'Grammar test for genitive case, похоти -> похотей'
251 grammarForm: 'genitive',
253 description: 'Grammar test for genitive case, доводы -> доводов'
257 grammarForm: 'genitive',
258 expected: 'песчаника',
259 description: 'Grammar test for genitive case, песчаник -> песчаника'
263 grammarForm: 'genitive',
265 description: 'Grammar test for genitive case, данные -> данных'
269 grammarForm: 'prepositional',
271 description: 'Grammar test for prepositional case, тесть -> тесте'
275 grammarForm: 'prepositional',
276 expected: 'привилегии',
277 description: 'Grammar test for prepositional case, привилегия -> привилегии'
281 grammarForm: 'prepositional',
282 expected: 'установке',
283 description: 'Grammar test for prepositional case, установка -> установке'
287 grammarForm: 'prepositional',
289 description: 'Grammar test for prepositional case, похоти -> похотях'
293 grammarForm: 'prepositional',
295 description: 'Grammar test for prepositional case, доводы -> доводах'
299 grammarForm: 'prepositional',
300 expected: 'Викискладе',
301 description: 'Grammar test for prepositional case, Викисклад -> Викискладе'
305 grammarForm: 'genitive',
306 expected: 'Викисклада',
307 description: 'Grammar test for genitive case, Викисклад -> Викисклада'
311 grammarForm: 'prepositional',
312 expected: 'песчанике',
313 description: 'Grammar test for prepositional case, песчаник -> песчанике'
317 grammarForm: 'prepositional',
319 description: 'Grammar test for prepositional case, данные -> данных'
323 grammarForm: 'languagegen',
324 expected: 'русского',
325 description: 'Grammar test for languagegen case, русский -> русского'
329 grammarForm: 'languagegen',
330 expected: 'немецкого',
331 description: 'Grammar test for languagegen case, немецкий -> немецкого'
335 grammarForm: 'languagegen',
337 description: 'Grammar test for languagegen case, иврит -> иврита'
341 grammarForm: 'languagegen',
342 expected: 'эсперанто',
343 description: 'Grammar test for languagegen case, эсперанто -> эсперанто'
347 grammarForm: 'languageprep',
349 description: 'Grammar test for languageprep case, русский -> русском'
353 grammarForm: 'languageprep',
354 expected: 'немецком',
355 description: 'Grammar test for languageprep case, немецкий -> немецком'
359 grammarForm: 'languageprep',
361 description: 'Grammar test for languageprep case, идиш -> идише'
365 grammarForm: 'languageprep',
366 expected: 'эсперанто',
367 description: 'Grammar test for languageprep case, эсперанто -> эсперанто'
371 grammarForm: 'languageadverb',
372 expected: 'по-русски',
373 description: 'Grammar test for languageadverb case, русский -> по-русски'
377 grammarForm: 'languageadverb',
378 expected: 'по-немецки',
379 description: 'Grammar test for languageadverb case, немецкий -> по-немецки'
383 grammarForm: 'languageadverb',
384 expected: 'на иврите',
385 description: 'Grammar test for languageadverb case, иврит -> на иврите'
389 grammarForm: 'languageadverb',
390 expected: 'на эсперанто',
391 description: 'Grammar test for languageadverb case, эсперанто -> на эсперанто'
395 grammarForm: 'languageadverb',
396 expected: 'на языке гуарани',
397 description: 'Grammar test for languageadverb case, гуарани -> на языке гуарани'
405 expected: 'Wikipédiáról',
406 description: 'Grammar test for rol case'
411 expected: 'Wikipédiába',
412 description: 'Grammar test for ba case'
417 expected: 'Wikipédiák',
418 description: 'Grammar test for k case'
425 grammarForm: 'ainmlae',
426 expected: 'Dé Domhnaigh',
427 description: 'Grammar test for ainmlae case'
431 grammarForm: 'ainmlae',
432 expected: 'Dé Luain',
433 description: 'Grammar test for ainmlae case'
437 grammarForm: 'ainmlae',
438 expected: 'Dé Sathairn',
439 description: 'Grammar test for ainmlae case'
446 grammarForm: 'genitive',
447 expected: 'Вікіпедії',
448 description: 'Grammar test for genitive case'
452 grammarForm: 'genitive',
453 expected: 'Віківидів',
454 description: 'Grammar test for genitive case'
458 grammarForm: 'genitive',
459 expected: 'Вікіцитат',
460 description: 'Grammar test for genitive case'
463 word: 'Вікіпідручник',
464 grammarForm: 'genitive',
465 expected: 'Вікіпідручника',
466 description: 'Grammar test for genitive case'
470 grammarForm: 'accusative',
471 expected: 'Вікіпедію',
472 description: 'Grammar test for accusative case'
479 grammarForm: 'orodnik',
481 description: 'Grammar test for orodnik case'
485 grammarForm: 'mestnik',
487 description: 'Grammar test for mestnik case'
494 grammarForm: 'genitive',
496 description: 'Grammar test for genitive case'
500 grammarForm: 'allative',
502 description: 'Grammar test for allative case'
506 grammarForm: 'dative',
508 description: 'Grammar test for dative case'
512 grammarForm: 'dative',
513 expected: 'цъитийæн',
514 description: 'Grammar test for dative case'
518 grammarForm: 'genitive',
520 description: 'Grammar test for genitive case'
524 grammarForm: 'equative',
526 description: 'Grammar test for equative case'
533 grammarForm: 'genitive',
534 expected: 'Translationis',
535 description: 'Grammar test for genitive case'
539 grammarForm: 'accusative',
540 expected: 'Translationem',
541 description: 'Grammar test for accusative case'
545 grammarForm: 'ablative',
546 expected: 'Translatione',
547 description: 'Grammar test for ablative case'
552 $.each( grammarTests, function ( langCode, test ) {
553 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
554 grammarTest( langCode, test );
558 QUnit.test( 'List to text test', 4, function ( assert ) {
559 assert.equal( mw.language.listToText( [] ), '', 'Blank list' );
560 assert.equal( mw.language.listToText( [ 'a' ] ), 'a', 'Single item' );
561 assert.equal( mw.language.listToText( [ 'a', 'b' ] ), 'a and b', 'Two items' );
562 assert.equal( mw.language.listToText( [ 'a', 'b', 'c' ] ), 'a, b and c', 'More than two items' );
564 }( mediaWiki, jQuery ) );