Make MessageCache::load() require a language code
[mediawiki.git] / tests / qunit / suites / resources / mediawiki / mediawiki.language.test.js
blobe4c38515933d292ef40c8adcef0e88facd8a5fe4
1 ( function ( mw, $ ) {
2 'use strict';
4 QUnit.module( 'mediawiki.language', QUnit.newMwEnvironment( {
5 setup: function () {
6 this.liveLangData = mw.language.data.values;
7 mw.language.data.values = $.extend( true, {}, this.liveLangData );
8 },
9 teardown: function () {
10 mw.language.data.values = this.liveLangData;
12 messages: {
13 // mw.language.listToText test
14 and: ' and',
15 'comma-separator': ', ',
16 'word-separator': ' '
18 } ) );
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' );
26 } );
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' );
44 } );
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++ ) {
53 assert.equal(
54 mw.language.convertGrammar( test[ i ].word, test[ i ].grammarForm ),
55 test[ i ].expected,
56 test[ i ].description
59 } );
62 // These tests run only for the current UI language.
63 var grammarTests = {
64 bs: [
66 word: 'word',
67 grammarForm: 'instrumental',
68 expected: 's word',
69 description: 'Grammar test for instrumental case'
72 word: 'word',
73 grammarForm: 'lokativ',
74 expected: 'o word',
75 description: 'Grammar test for lokativ case'
79 he: [
81 word: 'ויקיפדיה',
82 grammarForm: 'prefixed',
83 expected: 'וויקיפדיה',
84 description: 'Duplicate the "Waw" if prefixed'
87 word: 'וולפגנג',
88 grammarForm: 'prefixed',
89 expected: 'וולפגנג',
90 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
93 word: 'הקובץ',
94 grammarForm: 'prefixed',
95 expected: 'קובץ',
96 description: 'Remove the "He" if prefixed'
99 word: 'Wikipedia',
100 grammarForm: 'תחילית',
101 expected: '־Wikipedia',
102 description: 'Add a hyphen (maqaf) before non-Hebrew letters'
105 word: '1995',
106 grammarForm: 'תחילית',
107 expected: '־1995',
108 description: 'Add a hyphen (maqaf) before numbers'
112 hsb: [
114 word: 'word',
115 grammarForm: 'instrumental',
116 expected: 'z word',
117 description: 'Grammar test for instrumental case'
120 word: 'word',
121 grammarForm: 'lokatiw',
122 expected: 'wo word',
123 description: 'Grammar test for lokatiw case'
127 dsb: [
129 word: 'word',
130 grammarForm: 'instrumental',
131 expected: 'z word',
132 description: 'Grammar test for instrumental case'
135 word: 'word',
136 grammarForm: 'lokatiw',
137 expected: 'wo word',
138 description: 'Grammar test for lokatiw case'
142 hy: [
144 word: 'Մաունա',
145 grammarForm: 'genitive',
146 expected: 'Մաունայի',
147 description: 'Grammar test for genitive case'
150 word: 'հետո',
151 grammarForm: 'genitive',
152 expected: 'հետոյի',
153 description: 'Grammar test for genitive case'
156 word: 'գիրք',
157 grammarForm: 'genitive',
158 expected: 'գրքի',
159 description: 'Grammar test for genitive case'
162 word: 'ժամանակի',
163 grammarForm: 'genitive',
164 expected: 'ժամանակիի',
165 description: 'Grammar test for genitive case'
169 fi: [
171 word: 'talo',
172 grammarForm: 'genitive',
173 expected: 'talon',
174 description: 'Grammar test for genitive case'
177 word: 'linux',
178 grammarForm: 'genitive',
179 expected: 'linuxin',
180 description: 'Grammar test for genitive case'
183 word: 'talo',
184 grammarForm: 'elative',
185 expected: 'talosta',
186 description: 'Grammar test for elative case'
189 word: 'pastöroitu',
190 grammarForm: 'partitive',
191 expected: 'pastöroitua',
192 description: 'Grammar test for partitive case'
195 word: 'talo',
196 grammarForm: 'partitive',
197 expected: 'taloa',
198 description: 'Grammar test for partitive case'
201 word: 'talo',
202 grammarForm: 'illative',
203 expected: 'taloon',
204 description: 'Grammar test for illative case'
207 word: 'linux',
208 grammarForm: 'inessive',
209 expected: 'linuxissa',
210 description: 'Grammar test for inessive case'
214 ru: [
216 word: 'тесть',
217 grammarForm: 'genitive',
218 expected: 'тестя',
219 description: 'Grammar test for genitive case, тесть -> тестя'
222 word: 'привилегия',
223 grammarForm: 'genitive',
224 expected: 'привилегии',
225 description: 'Grammar test for genitive case, привилегия -> привилегии'
228 word: 'установка',
229 grammarForm: 'genitive',
230 expected: 'установки',
231 description: 'Grammar test for genitive case, установка -> установки'
234 word: 'похоти',
235 grammarForm: 'genitive',
236 expected: 'похотей',
237 description: 'Grammar test for genitive case, похоти -> похотей'
240 word: 'доводы',
241 grammarForm: 'genitive',
242 expected: 'доводов',
243 description: 'Grammar test for genitive case, доводы -> доводов'
246 word: 'песчаник',
247 grammarForm: 'genitive',
248 expected: 'песчаника',
249 description: 'Grammar test for genitive case, песчаник -> песчаника'
252 word: 'данные',
253 grammarForm: 'genitive',
254 expected: 'данных',
255 description: 'Grammar test for genitive case, данные -> данных'
258 word: 'тесть',
259 grammarForm: 'prepositional',
260 expected: 'тесте',
261 description: 'Grammar test for prepositional case, тесть -> тесте'
264 word: 'привилегия',
265 grammarForm: 'prepositional',
266 expected: 'привилегии',
267 description: 'Grammar test for prepositional case, привилегия -> привилегии'
270 word: 'установка',
271 grammarForm: 'prepositional',
272 expected: 'установке',
273 description: 'Grammar test for prepositional case, установка -> установке'
276 word: 'похоти',
277 grammarForm: 'prepositional',
278 expected: 'похотях',
279 description: 'Grammar test for prepositional case, похоти -> похотях'
282 word: 'доводы',
283 grammarForm: 'prepositional',
284 expected: 'доводах',
285 description: 'Grammar test for prepositional case, доводы -> доводах'
288 word: 'Викисклад',
289 grammarForm: 'prepositional',
290 expected: 'Викискладе',
291 description: 'Grammar test for prepositional case, Викисклад -> Викискладе'
294 word: 'Викисклад',
295 grammarForm: 'genitive',
296 expected: 'Викисклада',
297 description: 'Grammar test for genitive case, Викисклад -> Викисклада'
300 word: 'песчаник',
301 grammarForm: 'prepositional',
302 expected: 'песчанике',
303 description: 'Grammar test for prepositional case, песчаник -> песчанике'
306 word: 'данные',
307 grammarForm: 'prepositional',
308 expected: 'данных',
309 description: 'Grammar test for prepositional case, данные -> данных'
312 word: 'русский',
313 grammarForm: 'languagegen',
314 expected: 'русского',
315 description: 'Grammar test for languagegen case, русский -> русского'
318 word: 'немецкий',
319 grammarForm: 'languagegen',
320 expected: 'немецкого',
321 description: 'Grammar test for languagegen case, немецкий -> немецкого'
324 word: 'иврит',
325 grammarForm: 'languagegen',
326 expected: 'иврита',
327 description: 'Grammar test for languagegen case, иврит -> иврита'
330 word: 'эсперанто',
331 grammarForm: 'languagegen',
332 expected: 'эсперанто',
333 description: 'Grammar test for languagegen case, эсперанто -> эсперанто'
336 word: 'русский',
337 grammarForm: 'languageprep',
338 expected: 'русском',
339 description: 'Grammar test for languageprep case, русский -> русском'
342 word: 'немецкий',
343 grammarForm: 'languageprep',
344 expected: 'немецком',
345 description: 'Grammar test for languageprep case, немецкий -> немецком'
348 word: 'идиш',
349 grammarForm: 'languageprep',
350 expected: 'идише',
351 description: 'Grammar test for languageprep case, идиш -> идише'
354 word: 'эсперанто',
355 grammarForm: 'languageprep',
356 expected: 'эсперанто',
357 description: 'Grammar test for languageprep case, эсперанто -> эсперанто'
360 word: 'русский',
361 grammarForm: 'languageadverb',
362 expected: 'по-русски',
363 description: 'Grammar test for languageadverb case, русский -> по-русски'
366 word: 'немецкий',
367 grammarForm: 'languageadverb',
368 expected: 'по-немецки',
369 description: 'Grammar test for languageadverb case, немецкий -> по-немецки'
372 word: 'иврит',
373 grammarForm: 'languageadverb',
374 expected: 'на иврите',
375 description: 'Grammar test for languageadverb case, иврит -> на иврите'
378 word: 'эсперанто',
379 grammarForm: 'languageadverb',
380 expected: 'на эсперанто',
381 description: 'Grammar test for languageadverb case, эсперанто -> на эсперанто'
384 word: 'гуарани',
385 grammarForm: 'languageadverb',
386 expected: 'на языке гуарани',
387 description: 'Grammar test for languageadverb case, гуарани -> на языке гуарани'
391 hu: [
393 word: 'Wikipédiá',
394 grammarForm: 'rol',
395 expected: 'Wikipédiáról',
396 description: 'Grammar test for rol case'
399 word: 'Wikipédiá',
400 grammarForm: 'ba',
401 expected: 'Wikipédiába',
402 description: 'Grammar test for ba case'
405 word: 'Wikipédiá',
406 grammarForm: 'k',
407 expected: 'Wikipédiák',
408 description: 'Grammar test for k case'
412 ga: [
414 word: 'an Domhnach',
415 grammarForm: 'ainmlae',
416 expected: 'Dé Domhnaigh',
417 description: 'Grammar test for ainmlae case'
420 word: 'an Luan',
421 grammarForm: 'ainmlae',
422 expected: 'Dé Luain',
423 description: 'Grammar test for ainmlae case'
426 word: 'an Satharn',
427 grammarForm: 'ainmlae',
428 expected: 'Dé Sathairn',
429 description: 'Grammar test for ainmlae case'
433 uk: [
435 word: 'Вікіпедія',
436 grammarForm: 'genitive',
437 expected: 'Вікіпедії',
438 description: 'Grammar test for genitive case'
441 word: 'Віківиди',
442 grammarForm: 'genitive',
443 expected: 'Віківидів',
444 description: 'Grammar test for genitive case'
447 word: 'Вікіцитати',
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'
459 word: 'Вікіпедія',
460 grammarForm: 'accusative',
461 expected: 'Вікіпедію',
462 description: 'Grammar test for accusative case'
466 sl: [
468 word: 'word',
469 grammarForm: 'orodnik',
470 expected: 'z word',
471 description: 'Grammar test for orodnik case'
474 word: 'word',
475 grammarForm: 'mestnik',
476 expected: 'o word',
477 description: 'Grammar test for mestnik case'
481 os: [
483 word: 'бæстæ',
484 grammarForm: 'genitive',
485 expected: 'бæсты',
486 description: 'Grammar test for genitive case'
489 word: 'бæстæ',
490 grammarForm: 'allative',
491 expected: 'бæстæм',
492 description: 'Grammar test for allative case'
495 word: 'Тигр',
496 grammarForm: 'dative',
497 expected: 'Тигрæн',
498 description: 'Grammar test for dative case'
501 word: 'цъити',
502 grammarForm: 'dative',
503 expected: 'цъитийæн',
504 description: 'Grammar test for dative case'
507 word: 'лæппу',
508 grammarForm: 'genitive',
509 expected: 'лæппуйы',
510 description: 'Grammar test for genitive case'
513 word: '2011',
514 grammarForm: 'equative',
515 expected: '2011-ау',
516 description: 'Grammar test for equative case'
520 la: [
522 word: 'Translatio',
523 grammarForm: 'genitive',
524 expected: 'Translationis',
525 description: 'Grammar test for genitive case'
528 word: 'Translatio',
529 grammarForm: 'accusative',
530 expected: 'Translationem',
531 description: 'Grammar test for accusative case'
534 word: 'Translatio',
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 );
546 } );
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' );
553 } );
554 }( mediaWiki, jQuery ) );