mediawiki.language.init: Ignore case of language code
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.language.test.js
1 ( function ( mw, $ ) {
2 'use strict';
3
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;
11 }
12 } ) );
13
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' );
20 } );
21
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 seperator 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' );
33 } );
34
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 );
40
41 for ( var i = 0; i < test.length; i++ ) {
42 assert.equal(
43 mw.language.convertGrammar( test[i].word, test[i].grammarForm ),
44 test[i].expected,
45 test[i].description
46 );
47 }
48 } );
49 }
50
51 // These tests run only for the current UI language.
52 var grammarTests = {
53 bs: [
54 {
55 word: 'word',
56 grammarForm: 'instrumental',
57 expected: 's word',
58 description: 'Grammar test for instrumental case'
59 },
60 {
61 word: 'word',
62 grammarForm: 'lokativ',
63 expected: 'o word',
64 description: 'Grammar test for lokativ case'
65 }
66 ],
67
68 he: [
69 {
70 word: 'ויקיפדיה',
71 grammarForm: 'prefixed',
72 expected: 'וויקיפדיה',
73 description: 'Duplicate the "Waw" if prefixed'
74 },
75 {
76 word: 'וולפגנג',
77 grammarForm: 'prefixed',
78 expected: 'וולפגנג',
79 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
80 },
81 {
82 word: 'הקובץ',
83 grammarForm: 'prefixed',
84 expected: 'קובץ',
85 description: 'Remove the "He" if prefixed'
86 },
87 {
88 word: 'Wikipedia',
89 grammarForm: 'תחילית',
90 expected: '־Wikipedia',
91 description: 'GAdd a hyphen (maqaf) before non-Hebrew letters'
92 },
93 {
94 word: '1995',
95 grammarForm: 'תחילית',
96 expected: '־1995',
97 description: 'Add a hyphen (maqaf) before numbers'
98 }
99 ],
100
101 hsb: [
102 {
103 word: 'word',
104 grammarForm: 'instrumental',
105 expected: 'z word',
106 description: 'Grammar test for instrumental case'
107 },
108 {
109 word: 'word',
110 grammarForm: 'lokatiw',
111 expected: 'wo word',
112 description: 'Grammar test for lokatiw case'
113 }
114 ],
115
116 dsb: [
117 {
118 word: 'word',
119 grammarForm: 'instrumental',
120 expected: 'z word',
121 description: 'Grammar test for instrumental case'
122 },
123 {
124 word: 'word',
125 grammarForm: 'lokatiw',
126 expected: 'wo word',
127 description: 'Grammar test for lokatiw case'
128 }
129 ],
130
131 hy: [
132 {
133 word: 'Մաունա',
134 grammarForm: 'genitive',
135 expected: 'Մաունայի',
136 description: 'Grammar test for genitive case'
137 },
138 {
139 word: 'հետո',
140 grammarForm: 'genitive',
141 expected: 'հետոյի',
142 description: 'Grammar test for genitive case'
143 },
144 {
145 word: 'գիրք',
146 grammarForm: 'genitive',
147 expected: 'գրքի',
148 description: 'Grammar test for genitive case'
149 },
150 {
151 word: 'ժամանակի',
152 grammarForm: 'genitive',
153 expected: 'ժամանակիի',
154 description: 'Grammar test for genitive case'
155 }
156 ],
157
158 fi: [
159 {
160 word: 'talo',
161 grammarForm: 'genitive',
162 expected: 'talon',
163 description: 'Grammar test for genitive case'
164 },
165 {
166 word: 'linux',
167 grammarForm: 'genitive',
168 expected: 'linuxin',
169 description: 'Grammar test for genitive case'
170 },
171 {
172 word: 'talo',
173 grammarForm: 'elative',
174 expected: 'talosta',
175 description: 'Grammar test for elative case'
176 },
177 {
178 word: 'pastöroitu',
179 grammarForm: 'partitive',
180 expected: 'pastöroitua',
181 description: 'Grammar test for partitive case'
182 },
183 {
184 word: 'talo',
185 grammarForm: 'partitive',
186 expected: 'taloa',
187 description: 'Grammar test for partitive case'
188 },
189 {
190 word: 'talo',
191 grammarForm: 'illative',
192 expected: 'taloon',
193 description: 'Grammar test for illative case'
194 },
195 {
196 word: 'linux',
197 grammarForm: 'inessive',
198 expected: 'linuxissa',
199 description: 'Grammar test for inessive case'
200 }
201 ],
202
203 ru: [
204 {
205 word: 'тесть',
206 grammarForm: 'genitive',
207 expected: 'тестя',
208 description: 'Grammar test for genitive case, тесть -> тестя'
209 },
210 {
211 word: 'привилегия',
212 grammarForm: 'genitive',
213 expected: 'привилегии',
214 description: 'Grammar test for genitive case, привилегия -> привилегии'
215 },
216 {
217 word: 'установка',
218 grammarForm: 'genitive',
219 expected: 'установки',
220 description: 'Grammar test for genitive case, установка -> установки'
221 },
222 {
223 word: 'похоти',
224 grammarForm: 'genitive',
225 expected: 'похотей',
226 description: 'Grammar test for genitive case, похоти -> похотей'
227 },
228 {
229 word: 'доводы',
230 grammarForm: 'genitive',
231 expected: 'доводов',
232 description: 'Grammar test for genitive case, доводы -> доводов'
233 },
234 {
235 word: 'песчаник',
236 grammarForm: 'genitive',
237 expected: 'песчаника',
238 description: 'Grammar test for genitive case, песчаник -> песчаника'
239 },
240 {
241 word: 'данные',
242 grammarForm: 'genitive',
243 expected: 'данных',
244 description: 'Grammar test for genitive case, данные -> данных'
245 },
246 {
247 word: 'тесть',
248 grammarForm: 'prepositional',
249 expected: 'тесте',
250 description: 'Grammar test for prepositional case, тесть -> тесте'
251 },
252 {
253 word: 'привилегия',
254 grammarForm: 'prepositional',
255 expected: 'привилегии',
256 description: 'Grammar test for prepositional case, привилегия -> привилегии'
257 },
258 {
259 word: 'установка',
260 grammarForm: 'prepositional',
261 expected: 'установке',
262 description: 'Grammar test for prepositional case, установка -> установке'
263 },
264 {
265 word: 'похоти',
266 grammarForm: 'prepositional',
267 expected: 'похотях',
268 description: 'Grammar test for prepositional case, похоти -> похотях'
269 },
270 {
271 word: 'доводы',
272 grammarForm: 'prepositional',
273 expected: 'доводах',
274 description: 'Grammar test for prepositional case, доводы -> доводах'
275 },
276 {
277 word: 'Викисклад',
278 grammarForm: 'prepositional',
279 expected: 'Викискладе',
280 description: 'Grammar test for prepositional case, Викисклад -> Викискладе'
281 },
282 {
283 word: 'Викисклад',
284 grammarForm: 'genitive',
285 expected: 'Викисклада',
286 description: 'Grammar test for genitive case, Викисклад -> Викисклада'
287 },
288 {
289 word: 'песчаник',
290 grammarForm: 'prepositional',
291 expected: 'песчанике',
292 description: 'Grammar test for prepositional case, песчаник -> песчанике'
293 },
294 {
295 word: 'данные',
296 grammarForm: 'prepositional',
297 expected: 'данных',
298 description: 'Grammar test for prepositional case, данные -> данных'
299 }
300 ],
301
302 hu: [
303 {
304 word: 'Wikipédiá',
305 grammarForm: 'rol',
306 expected: 'Wikipédiáról',
307 description: 'Grammar test for rol case'
308 },
309 {
310 word: 'Wikipédiá',
311 grammarForm: 'ba',
312 expected: 'Wikipédiába',
313 description: 'Grammar test for ba case'
314 },
315 {
316 word: 'Wikipédiá',
317 grammarForm: 'k',
318 expected: 'Wikipédiák',
319 description: 'Grammar test for k case'
320 }
321 ],
322
323 ga: [
324 {
325 word: 'an Domhnach',
326 grammarForm: 'ainmlae',
327 expected: 'Dé Domhnaigh',
328 description: 'Grammar test for ainmlae case'
329 },
330 {
331 word: 'an Luan',
332 grammarForm: 'ainmlae',
333 expected: 'Dé Luain',
334 description: 'Grammar test for ainmlae case'
335 },
336 {
337 word: 'an Satharn',
338 grammarForm: 'ainmlae',
339 expected: 'Dé Sathairn',
340 description: 'Grammar test for ainmlae case'
341 }
342 ],
343
344 uk: [
345 {
346 word: 'тесть',
347 grammarForm: 'genitive',
348 expected: 'тестя',
349 description: 'Grammar test for genitive case'
350 },
351 {
352 word: 'Вікіпедія',
353 grammarForm: 'genitive',
354 expected: 'Вікіпедії',
355 description: 'Grammar test for genitive case'
356 },
357 {
358 word: 'установка',
359 grammarForm: 'genitive',
360 expected: 'установки',
361 description: 'Grammar test for genitive case'
362 },
363 {
364 word: 'похоти',
365 grammarForm: 'genitive',
366 expected: 'похотей',
367 description: 'Grammar test for genitive case'
368 },
369 {
370 word: 'доводы',
371 grammarForm: 'genitive',
372 expected: 'доводов',
373 description: 'Grammar test for genitive case'
374 },
375 {
376 word: 'песчаник',
377 grammarForm: 'genitive',
378 expected: 'песчаника',
379 description: 'Grammar test for genitive case'
380 },
381 {
382 word: 'Вікіпедія',
383 grammarForm: 'accusative',
384 expected: 'Вікіпедію',
385 description: 'Grammar test for accusative case'
386 }
387 ],
388
389 sl: [
390 {
391 word: 'word',
392 grammarForm: 'orodnik',
393 expected: 'z word',
394 description: 'Grammar test for orodnik case'
395 },
396 {
397 word: 'word',
398 grammarForm: 'mestnik',
399 expected: 'o word',
400 description: 'Grammar test for mestnik case'
401 }
402 ],
403
404 os: [
405 {
406 word: 'бæстæ',
407 grammarForm: 'genitive',
408 expected: 'бæсты',
409 description: 'Grammar test for genitive case'
410 },
411 {
412 word: 'бæстæ',
413 grammarForm: 'allative',
414 expected: 'бæстæм',
415 description: 'Grammar test for allative case'
416 },
417 {
418 word: 'Тигр',
419 grammarForm: 'dative',
420 expected: 'Тигрæн',
421 description: 'Grammar test for dative case'
422 },
423 {
424 word: 'цъити',
425 grammarForm: 'dative',
426 expected: 'цъитийæн',
427 description: 'Grammar test for dative case'
428 },
429 {
430 word: 'лæппу',
431 grammarForm: 'genitive',
432 expected: 'лæппуйы',
433 description: 'Grammar test for genitive case'
434 },
435 {
436 word: '2011',
437 grammarForm: 'equative',
438 expected: '2011-ау',
439 description: 'Grammar test for equative case'
440 }
441 ],
442
443 la: [
444 {
445 word: 'Translatio',
446 grammarForm: 'genitive',
447 expected: 'Translationis',
448 description: 'Grammar test for genitive case'
449 },
450 {
451 word: 'Translatio',
452 grammarForm: 'accusative',
453 expected: 'Translationem',
454 description: 'Grammar test for accusative case'
455 },
456 {
457 word: 'Translatio',
458 grammarForm: 'ablative',
459 expected: 'Translatione',
460 description: 'Grammar test for ablative case'
461 }
462 ]
463 };
464
465 $.each( grammarTests, function ( langCode, test ) {
466 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
467 grammarTest( langCode, test );
468 }
469 } );
470
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' );
476 } );
477 }( mediaWiki, jQuery ) );