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;
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 function grammarTest( langCode, test ) {
47 // The test works only if the content language is opt.language
48 // because it requires [lang].js to be loaded.
49 QUnit.test( 'Grammar test for lang=' + langCode, function ( assert ) {
50 QUnit.expect( test.length );
52 for ( var i = 0; i < test.length; i++ ) {
54 mw.language.convertGrammar( test[ i ].word, test[ i ].grammarForm ),
62 // These tests run only for the current UI language.
67 grammarForm: 'instrumental',
69 description: 'Grammar test for instrumental case'
73 grammarForm: 'lokativ',
75 description: 'Grammar test for lokativ case'
82 grammarForm: 'prefixed',
83 expected: 'וויקיפדיה',
84 description: 'Duplicate the "Waw" if prefixed'
88 grammarForm: 'prefixed',
90 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
94 grammarForm: 'prefixed',
96 description: 'Remove the "He" if prefixed'
100 grammarForm: 'תחילית',
101 expected: '־Wikipedia',
102 description: 'Add a hyphen (maqaf) before non-Hebrew letters'
106 grammarForm: 'תחילית',
108 description: 'Add a hyphen (maqaf) before numbers'
115 grammarForm: 'instrumental',
117 description: 'Grammar test for instrumental case'
121 grammarForm: 'lokatiw',
123 description: 'Grammar test for lokatiw case'
130 grammarForm: 'instrumental',
132 description: 'Grammar test for instrumental case'
136 grammarForm: 'lokatiw',
138 description: 'Grammar test for lokatiw case'
145 grammarForm: 'genitive',
146 expected: 'Մաունայի',
147 description: 'Grammar test for genitive case'
151 grammarForm: 'genitive',
153 description: 'Grammar test for genitive case'
157 grammarForm: 'genitive',
159 description: 'Grammar test for genitive case'
163 grammarForm: 'genitive',
164 expected: 'ժամանակիի',
165 description: 'Grammar test for genitive case'
172 grammarForm: 'genitive',
174 description: 'Grammar test for genitive case'
178 grammarForm: 'genitive',
180 description: 'Grammar test for genitive case'
184 grammarForm: 'elative',
186 description: 'Grammar test for elative case'
190 grammarForm: 'partitive',
191 expected: 'pastöroitua',
192 description: 'Grammar test for partitive case'
196 grammarForm: 'partitive',
198 description: 'Grammar test for partitive case'
202 grammarForm: 'illative',
204 description: 'Grammar test for illative case'
208 grammarForm: 'inessive',
209 expected: 'linuxissa',
210 description: 'Grammar test for inessive case'
217 grammarForm: 'genitive',
219 description: 'Grammar test for genitive case, тесть -> тестя'
223 grammarForm: 'genitive',
224 expected: 'привилегии',
225 description: 'Grammar test for genitive case, привилегия -> привилегии'
229 grammarForm: 'genitive',
230 expected: 'установки',
231 description: 'Grammar test for genitive case, установка -> установки'
235 grammarForm: 'genitive',
237 description: 'Grammar test for genitive case, похоти -> похотей'
241 grammarForm: 'genitive',
243 description: 'Grammar test for genitive case, доводы -> доводов'
247 grammarForm: 'genitive',
248 expected: 'песчаника',
249 description: 'Grammar test for genitive case, песчаник -> песчаника'
253 grammarForm: 'genitive',
255 description: 'Grammar test for genitive case, данные -> данных'
259 grammarForm: 'prepositional',
261 description: 'Grammar test for prepositional case, тесть -> тесте'
265 grammarForm: 'prepositional',
266 expected: 'привилегии',
267 description: 'Grammar test for prepositional case, привилегия -> привилегии'
271 grammarForm: 'prepositional',
272 expected: 'установке',
273 description: 'Grammar test for prepositional case, установка -> установке'
277 grammarForm: 'prepositional',
279 description: 'Grammar test for prepositional case, похоти -> похотях'
283 grammarForm: 'prepositional',
285 description: 'Grammar test for prepositional case, доводы -> доводах'
289 grammarForm: 'prepositional',
290 expected: 'Викискладе',
291 description: 'Grammar test for prepositional case, Викисклад -> Викискладе'
295 grammarForm: 'genitive',
296 expected: 'Викисклада',
297 description: 'Grammar test for genitive case, Викисклад -> Викисклада'
301 grammarForm: 'prepositional',
302 expected: 'песчанике',
303 description: 'Grammar test for prepositional case, песчаник -> песчанике'
307 grammarForm: 'prepositional',
309 description: 'Grammar test for prepositional case, данные -> данных'
313 grammarForm: 'languagegen',
314 expected: 'русского',
315 description: 'Grammar test for languagegen case, русский -> русского'
319 grammarForm: 'languagegen',
320 expected: 'немецкого',
321 description: 'Grammar test for languagegen case, немецкий -> немецкого'
325 grammarForm: 'languagegen',
327 description: 'Grammar test for languagegen case, иврит -> иврита'
331 grammarForm: 'languagegen',
332 expected: 'эсперанто',
333 description: 'Grammar test for languagegen case, эсперанто -> эсперанто'
337 grammarForm: 'languageprep',
339 description: 'Grammar test for languageprep case, русский -> русском'
343 grammarForm: 'languageprep',
344 expected: 'немецком',
345 description: 'Grammar test for languageprep case, немецкий -> немецком'
349 grammarForm: 'languageprep',
351 description: 'Grammar test for languageprep case, идиш -> идише'
355 grammarForm: 'languageprep',
356 expected: 'эсперанто',
357 description: 'Grammar test for languageprep case, эсперанто -> эсперанто'
361 grammarForm: 'languageadverb',
362 expected: 'по-русски',
363 description: 'Grammar test for languageadverb case, русский -> по-русски'
367 grammarForm: 'languageadverb',
368 expected: 'по-немецки',
369 description: 'Grammar test for languageadverb case, немецкий -> по-немецки'
373 grammarForm: 'languageadverb',
374 expected: 'на иврите',
375 description: 'Grammar test for languageadverb case, иврит -> на иврите'
379 grammarForm: 'languageadverb',
380 expected: 'на эсперанто',
381 description: 'Grammar test for languageadverb case, эсперанто -> на эсперанто'
385 grammarForm: 'languageadverb',
386 expected: 'на языке гуарани',
387 description: 'Grammar test for languageadverb case, гуарани -> на языке гуарани'
395 expected: 'Wikipédiáról',
396 description: 'Grammar test for rol case'
401 expected: 'Wikipédiába',
402 description: 'Grammar test for ba case'
407 expected: 'Wikipédiák',
408 description: 'Grammar test for k case'
415 grammarForm: 'ainmlae',
416 expected: 'Dé Domhnaigh',
417 description: 'Grammar test for ainmlae case'
421 grammarForm: 'ainmlae',
422 expected: 'Dé Luain',
423 description: 'Grammar test for ainmlae case'
427 grammarForm: 'ainmlae',
428 expected: 'Dé Sathairn',
429 description: 'Grammar test for ainmlae case'
436 grammarForm: 'genitive',
437 expected: 'Вікіпедії',
438 description: 'Grammar test for genitive case'
442 grammarForm: 'genitive',
443 expected: 'Віківидів',
444 description: 'Grammar test for genitive case'
448 grammarForm: 'genitive',
449 expected: 'Вікіцитат',
450 description: 'Grammar test for genitive case'
453 word: 'Вікіпідручник',
454 grammarForm: 'genitive',
455 expected: 'Вікіпідручника',
456 description: 'Grammar test for genitive case'
460 grammarForm: 'accusative',
461 expected: 'Вікіпедію',
462 description: 'Grammar test for accusative case'
469 grammarForm: 'orodnik',
471 description: 'Grammar test for orodnik case'
475 grammarForm: 'mestnik',
477 description: 'Grammar test for mestnik case'
484 grammarForm: 'genitive',
486 description: 'Grammar test for genitive case'
490 grammarForm: 'allative',
492 description: 'Grammar test for allative case'
496 grammarForm: 'dative',
498 description: 'Grammar test for dative case'
502 grammarForm: 'dative',
503 expected: 'цъитийæн',
504 description: 'Grammar test for dative case'
508 grammarForm: 'genitive',
510 description: 'Grammar test for genitive case'
514 grammarForm: 'equative',
516 description: 'Grammar test for equative case'
523 grammarForm: 'genitive',
524 expected: 'Translationis',
525 description: 'Grammar test for genitive case'
529 grammarForm: 'accusative',
530 expected: 'Translationem',
531 description: 'Grammar test for accusative case'
535 grammarForm: 'ablative',
536 expected: 'Translatione',
537 description: 'Grammar test for ablative case'
542 $.each( grammarTests, function ( langCode, test ) {
543 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
544 grammarTest( langCode, test );
548 QUnit.test( 'List to text test', 4, function ( assert ) {
549 assert.equal( mw.language.listToText( [] ), '', 'Blank list' );
550 assert.equal( mw.language.listToText( [ 'a' ] ), 'a', 'Single item' );
551 assert.equal( mw.language.listToText( [ 'a', 'b' ] ), 'a and b', 'Two items' );
552 assert.equal( mw.language.listToText( [ 'a', 'b', 'c' ] ), 'a, b and c', 'More than two items' );
554 }( mediaWiki, jQuery ) );