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