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
: 'GAdd 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, данные -> данных'
317 expected
: 'Wikipédiáról',
318 description
: 'Grammar test for rol case'
323 expected
: 'Wikipédiába',
324 description
: 'Grammar test for ba case'
329 expected
: 'Wikipédiák',
330 description
: 'Grammar test for k case'
337 grammarForm
: 'ainmlae',
338 expected
: 'Dé Domhnaigh',
339 description
: 'Grammar test for ainmlae case'
343 grammarForm
: 'ainmlae',
344 expected
: 'Dé Luain',
345 description
: 'Grammar test for ainmlae case'
349 grammarForm
: 'ainmlae',
350 expected
: 'Dé Sathairn',
351 description
: 'Grammar test for ainmlae case'
358 grammarForm
: 'genitive',
360 description
: 'Grammar test for genitive case'
364 grammarForm
: 'genitive',
365 expected
: 'Вікіпедії',
366 description
: 'Grammar test for genitive case'
370 grammarForm
: 'genitive',
371 expected
: 'установки',
372 description
: 'Grammar test for genitive case'
376 grammarForm
: 'genitive',
378 description
: 'Grammar test for genitive case'
382 grammarForm
: 'genitive',
384 description
: 'Grammar test for genitive case'
388 grammarForm
: 'genitive',
389 expected
: 'песчаника',
390 description
: 'Grammar test for genitive case'
394 grammarForm
: 'accusative',
395 expected
: 'Вікіпедію',
396 description
: 'Grammar test for accusative case'
403 grammarForm
: 'orodnik',
405 description
: 'Grammar test for orodnik case'
409 grammarForm
: 'mestnik',
411 description
: 'Grammar test for mestnik case'
418 grammarForm
: 'genitive',
420 description
: 'Grammar test for genitive case'
424 grammarForm
: 'allative',
426 description
: 'Grammar test for allative case'
430 grammarForm
: 'dative',
432 description
: 'Grammar test for dative case'
436 grammarForm
: 'dative',
437 expected
: 'цъитийæн',
438 description
: 'Grammar test for dative case'
442 grammarForm
: 'genitive',
444 description
: 'Grammar test for genitive case'
448 grammarForm
: 'equative',
450 description
: 'Grammar test for equative case'
457 grammarForm
: 'genitive',
458 expected
: 'Translationis',
459 description
: 'Grammar test for genitive case'
463 grammarForm
: 'accusative',
464 expected
: 'Translationem',
465 description
: 'Grammar test for accusative case'
469 grammarForm
: 'ablative',
470 expected
: 'Translatione',
471 description
: 'Grammar test for ablative case'
476 $.each( grammarTests
, function ( langCode
, test
) {
477 if ( langCode
=== mw
.config
.get( 'wgUserLanguage' ) ) {
478 grammarTest( langCode
, test
);
482 QUnit
.test( 'List to text test', 4, function ( assert
) {
483 assert
.equal( mw
.language
.listToText( [] ), '', 'Blank list' );
484 assert
.equal( mw
.language
.listToText( ['a'] ), 'a', 'Single item' );
485 assert
.equal( mw
.language
.listToText( ['a', 'b'] ), 'a and b', 'Two items' );
486 assert
.equal( mw
.language
.listToText( ['a', 'b', 'c'] ), 'a, b and c', 'More than two items' );
488 }( mediaWiki
, jQuery
) );