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