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', 3, 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' );
18 mw
.language
.setData( 'en-us', 'testkey', 'testvalue' );
19 assert
.equal( mw
.language
.getData( 'en-US', 'testkey' ), 'testvalue', 'Case insensitive test for mw.language' );
22 QUnit
.test( 'mw.language.commafy test', 9, function ( assert
) {
23 // Number grouping patterns are as per http://cldr.unicode.org/translation/number-patterns
24 assert
.equal( mw
.language
.commafy( 1234.567, '###0.#####' ), '1234.567', 'Pattern with no digit grouping separator defined' );
25 assert
.equal( mw
.language
.commafy( 123456789.567, '###0.#####' ), '123456789.567', 'Pattern with no digit grouping separator defined, bigger decimal part' );
26 assert
.equal( mw
.language
.commafy( 0.567, '###0.#####' ), '0.567', 'Decimal part 0' );
27 assert
.equal( mw
.language
.commafy( '.567', '###0.#####' ), '0.567', 'Decimal part missing. replace with zero' );
28 assert
.equal( mw
.language
.commafy( 1234, '##,#0.#####' ), '12,34', 'Pattern with no fractional part' );
29 assert
.equal( mw
.language
.commafy( -1234.567, '###0.#####' ), '-1234.567', 'Negative number' );
30 assert
.equal( mw
.language
.commafy( -1234.567, '#,###.00' ), '-1,234.56', 'Fractional part bigger than pattern.' );
31 assert
.equal( mw
.language
.commafy( 123456789.567, '###,##0.00' ), '123,456,789.56', 'Decimal part as group of 3' );
32 assert
.equal( mw
.language
.commafy( 123456789.567, '###,###,#0.00' ), '1,234,567,89.56', 'Decimal part as group of 3 and last one 2' );
35 function grammarTest( langCode
, test
) {
36 // The test works only if the content language is opt.language
37 // because it requires [lang].js to be loaded.
38 QUnit
.test( 'Grammar test for lang=' + langCode
, function ( assert
) {
39 QUnit
.expect( test
.length
);
41 for ( var i
= 0; i
< test
.length
; i
++ ) {
43 mw
.language
.convertGrammar( test
[i
].word
, test
[i
].grammarForm
),
51 // These tests run only for the current UI language.
56 grammarForm
: 'instrumental',
58 description
: 'Grammar test for instrumental case'
62 grammarForm
: 'lokativ',
64 description
: 'Grammar test for lokativ case'
71 grammarForm
: 'prefixed',
72 expected
: 'וויקיפדיה',
73 description
: 'Duplicate the "Waw" if prefixed'
77 grammarForm
: 'prefixed',
79 description
: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
83 grammarForm
: 'prefixed',
85 description
: 'Remove the "He" if prefixed'
89 grammarForm
: 'תחילית',
90 expected
: '־Wikipedia',
91 description
: 'GAdd a hyphen (maqaf) before non-Hebrew letters'
95 grammarForm
: 'תחילית',
97 description
: 'Add a hyphen (maqaf) before numbers'
104 grammarForm
: 'instrumental',
106 description
: 'Grammar test for instrumental case'
110 grammarForm
: 'lokatiw',
112 description
: 'Grammar test for lokatiw case'
119 grammarForm
: 'instrumental',
121 description
: 'Grammar test for instrumental case'
125 grammarForm
: 'lokatiw',
127 description
: 'Grammar test for lokatiw case'
134 grammarForm
: 'genitive',
135 expected
: 'Մաունայի',
136 description
: 'Grammar test for genitive case'
140 grammarForm
: 'genitive',
142 description
: 'Grammar test for genitive case'
146 grammarForm
: 'genitive',
148 description
: 'Grammar test for genitive case'
152 grammarForm
: 'genitive',
153 expected
: 'ժամանակիի',
154 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
: 'elative',
175 description
: 'Grammar test for elative case'
179 grammarForm
: 'partitive',
180 expected
: 'pastöroitua',
181 description
: 'Grammar test for partitive case'
185 grammarForm
: 'partitive',
187 description
: 'Grammar test for partitive case'
191 grammarForm
: 'illative',
193 description
: 'Grammar test for illative case'
197 grammarForm
: 'inessive',
198 expected
: 'linuxissa',
199 description
: 'Grammar test for inessive case'
206 grammarForm
: 'genitive',
208 description
: 'Grammar test for genitive case, тесть -> тестя'
212 grammarForm
: 'genitive',
213 expected
: 'привилегии',
214 description
: 'Grammar test for genitive case, привилегия -> привилегии'
218 grammarForm
: 'genitive',
219 expected
: 'установки',
220 description
: 'Grammar test for genitive case, установка -> установки'
224 grammarForm
: 'genitive',
226 description
: 'Grammar test for genitive case, похоти -> похотей'
230 grammarForm
: 'genitive',
232 description
: 'Grammar test for genitive case, доводы -> доводов'
236 grammarForm
: 'genitive',
237 expected
: 'песчаника',
238 description
: 'Grammar test for genitive case, песчаник -> песчаника'
242 grammarForm
: 'genitive',
244 description
: 'Grammar test for genitive case, данные -> данных'
248 grammarForm
: 'prepositional',
250 description
: 'Grammar test for prepositional case, тесть -> тесте'
254 grammarForm
: 'prepositional',
255 expected
: 'привилегии',
256 description
: 'Grammar test for prepositional case, привилегия -> привилегии'
260 grammarForm
: 'prepositional',
261 expected
: 'установке',
262 description
: 'Grammar test for prepositional case, установка -> установке'
266 grammarForm
: 'prepositional',
268 description
: 'Grammar test for prepositional case, похоти -> похотях'
272 grammarForm
: 'prepositional',
274 description
: 'Grammar test for prepositional case, доводы -> доводах'
278 grammarForm
: 'prepositional',
279 expected
: 'Викискладе',
280 description
: 'Grammar test for prepositional case, Викисклад -> Викискладе'
284 grammarForm
: 'genitive',
285 expected
: 'Викисклада',
286 description
: 'Grammar test for genitive case, Викисклад -> Викисклада'
290 grammarForm
: 'prepositional',
291 expected
: 'песчанике',
292 description
: 'Grammar test for prepositional case, песчаник -> песчанике'
296 grammarForm
: 'prepositional',
298 description
: 'Grammar test for prepositional case, данные -> данных'
306 expected
: 'Wikipédiáról',
307 description
: 'Grammar test for rol case'
312 expected
: 'Wikipédiába',
313 description
: 'Grammar test for ba case'
318 expected
: 'Wikipédiák',
319 description
: 'Grammar test for k case'
326 grammarForm
: 'ainmlae',
327 expected
: 'Dé Domhnaigh',
328 description
: 'Grammar test for ainmlae case'
332 grammarForm
: 'ainmlae',
333 expected
: 'Dé Luain',
334 description
: 'Grammar test for ainmlae case'
338 grammarForm
: 'ainmlae',
339 expected
: 'Dé Sathairn',
340 description
: 'Grammar test for ainmlae case'
347 grammarForm
: 'genitive',
349 description
: 'Grammar test for genitive case'
353 grammarForm
: 'genitive',
354 expected
: 'Вікіпедії',
355 description
: 'Grammar test for genitive case'
359 grammarForm
: 'genitive',
360 expected
: 'установки',
361 description
: 'Grammar test for genitive case'
365 grammarForm
: 'genitive',
367 description
: 'Grammar test for genitive case'
371 grammarForm
: 'genitive',
373 description
: 'Grammar test for genitive case'
377 grammarForm
: 'genitive',
378 expected
: 'песчаника',
379 description
: 'Grammar test for genitive case'
383 grammarForm
: 'accusative',
384 expected
: 'Вікіпедію',
385 description
: 'Grammar test for accusative case'
392 grammarForm
: 'orodnik',
394 description
: 'Grammar test for orodnik case'
398 grammarForm
: 'mestnik',
400 description
: 'Grammar test for mestnik case'
407 grammarForm
: 'genitive',
409 description
: 'Grammar test for genitive case'
413 grammarForm
: 'allative',
415 description
: 'Grammar test for allative case'
419 grammarForm
: 'dative',
421 description
: 'Grammar test for dative case'
425 grammarForm
: 'dative',
426 expected
: 'цъитийæн',
427 description
: 'Grammar test for dative case'
431 grammarForm
: 'genitive',
433 description
: 'Grammar test for genitive case'
437 grammarForm
: 'equative',
439 description
: 'Grammar test for equative case'
446 grammarForm
: 'genitive',
447 expected
: 'Translationis',
448 description
: 'Grammar test for genitive case'
452 grammarForm
: 'accusative',
453 expected
: 'Translationem',
454 description
: 'Grammar test for accusative case'
458 grammarForm
: 'ablative',
459 expected
: 'Translatione',
460 description
: 'Grammar test for ablative case'
465 $.each( grammarTests
, function ( langCode
, test
) {
466 if ( langCode
=== mw
.config
.get( 'wgUserLanguage' ) ) {
467 grammarTest( langCode
, test
);
471 QUnit
.test( 'List to text test', 4, function ( assert
) {
472 assert
.equal( mw
.language
.listToText( [] ), '', 'Blank list' );
473 assert
.equal( mw
.language
.listToText( ['a'] ), 'a', 'Single item' );
474 assert
.equal( mw
.language
.listToText( ['a', 'b'] ), 'a and b', 'Two items' );
475 assert
.equal( mw
.language
.listToText( ['a', 'b', 'c'] ), 'a, b and c', 'More than two items' );
477 }( mediaWiki
, jQuery
) );