869ebe455b35593d18a79d3188d4da0e376385d5
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.language.test.js
1 ( function ( mw, $ ) {
2
3 QUnit.module( 'mediawiki.language', QUnit.newMwEnvironment({
4 setup: function () {
5 this.liveLangData = mw.language.data.values;
6 mw.language.data.values = $.extend( true, {}, this.liveLangData );
7 },
8 teardown: function () {
9 mw.language.data.values = this.liveLangData;
10 }
11 }) );
12
13 QUnit.test( 'mw.language getData and setData', 2, function ( assert ) {
14 mw.language.setData( 'en', 'testkey', 'testvalue' );
15 assert.equal( mw.language.getData( 'en', 'testkey' ), 'testvalue', 'Getter setter test for mw.language' );
16 assert.equal( mw.language.getData( 'en', 'invalidkey' ), undefined, 'Getter setter test for mw.language with invalid key' );
17 } );
18
19 function grammarTest( langCode, test ) {
20 // The test works only if the content language is opt.language
21 // because it requires [lang].js to be loaded.
22 QUnit.test( 'Grammar test for lang=' + langCode, function ( assert ) {
23 QUnit.expect( test.length );
24
25 for ( var i = 0 ; i < test.length; i++ ) {
26 assert.equal(
27 mw.language.convertGrammar( test[i].word, test[i].grammarForm ),
28 test[i].expected,
29 test[i].description
30 );
31 }
32 });
33 }
34
35 var grammarTests = {
36 bs: [
37 {
38 word: 'word',
39 grammarForm: 'instrumental',
40 expected: 's word',
41 description: 'Grammar test for instrumental case'
42 },
43 {
44 word: 'word',
45 grammarForm: 'lokativ',
46 expected: 'o word',
47 description: 'Grammar test for lokativ case'
48 }
49 ],
50
51 he: [
52 {
53 word: 'ויקיפדיה',
54 grammarForm: 'prefixed',
55 expected: 'וויקיפדיה',
56 description: 'Duplicate the "Waw" if prefixed'
57 },
58 {
59 word: 'וולפגנג',
60 grammarForm: 'prefixed',
61 expected: 'וולפגנג',
62 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
63 },
64 {
65 word: 'הקובץ',
66 grammarForm: 'prefixed',
67 expected: 'קובץ',
68 description: 'Remove the "He" if prefixed'
69 },
70 {
71 word: 'Wikipedia',
72 grammarForm: 'תחילית',
73 expected: '־Wikipedia',
74 description: 'GAdd a hyphen (maqaf) before non-Hebrew letters'
75 },
76 {
77 word: '1995',
78 grammarForm: 'תחילית',
79 expected: '־1995',
80 description: 'Add a hyphen (maqaf) before numbers'
81 }
82 ],
83
84 hsb: [
85 {
86 word: 'word',
87 grammarForm: 'instrumental',
88 expected: 'z word',
89 description: 'Grammar test for instrumental case'
90 },
91 {
92 word: 'word',
93 grammarForm: 'lokatiw',
94 expected: 'wo word',
95 description: 'Grammar test for lokatiw case'
96 }
97 ],
98
99 dsb: [
100 {
101 word: 'word',
102 grammarForm: 'instrumental',
103 expected: 'z word',
104 description: 'Grammar test for instrumental case'
105 },
106 {
107 word: 'word',
108 grammarForm: 'lokatiw',
109 expected: 'wo word',
110 description: 'Grammar test for lokatiw case'
111 }
112 ],
113
114 hy: [
115 {
116 word: 'Մաունա',
117 grammarForm: 'genitive',
118 expected: 'Մաունայի',
119 description: 'Grammar test for genitive case'
120 },
121 {
122 word: 'հետո',
123 grammarForm: 'genitive',
124 expected: 'հետոյի',
125 description: 'Grammar test for genitive case'
126 },
127 {
128 word: 'գիրք',
129 grammarForm: 'genitive',
130 expected: 'գրքի',
131 description: 'Grammar test for genitive case'
132 },
133 {
134 word: 'ժամանակի',
135 grammarForm: 'genitive',
136 expected: 'ժամանակիի',
137 description: 'Grammar test for genitive case'
138 }
139 ],
140
141 fi: [
142 {
143 word: 'talo',
144 grammarForm: 'genitive',
145 expected: 'talon',
146 description: 'Grammar test for genitive case'
147 },
148 {
149 word: 'linux',
150 grammarForm: 'genitive',
151 expected: 'linuxin',
152 description: 'Grammar test for genitive case'
153 },
154 {
155 word: 'talo',
156 grammarForm: 'elative',
157 expected: 'talosta',
158 description: 'Grammar test for elative case'
159 },
160 {
161 word: 'pastöroitu',
162 grammarForm: 'partitive',
163 expected: 'pastöroitua',
164 description: 'Grammar test for partitive case'
165 },
166 {
167 word: 'talo',
168 grammarForm: 'partitive',
169 expected: 'taloa',
170 description: 'Grammar test for partitive case'
171 },
172 {
173 word: 'talo',
174 grammarForm: 'illative',
175 expected: 'taloon',
176 description: 'Grammar test for illative case'
177 },
178 {
179 word: 'linux',
180 grammarForm: 'inessive',
181 expected: 'linuxissa',
182 description: 'Grammar test for inessive case'
183 }
184 ],
185
186 ru: [
187 {
188 word: 'тесть',
189 grammarForm: 'genitive',
190 expected: 'тестя',
191 description: 'Grammar test for genitive case'
192 },
193 {
194 word: 'привилегия',
195 grammarForm: 'genitive',
196 expected: 'привилегии',
197 description: 'Grammar test for genitive case'
198 },
199 {
200 word: 'установка',
201 grammarForm: 'genitive',
202 expected: 'установки',
203 description: 'Grammar test for genitive case'
204 },
205 {
206 word: 'похоти',
207 grammarForm: 'genitive',
208 expected: 'похотей',
209 description: 'Grammar test for genitive case'
210 },
211 {
212 word: 'доводы',
213 grammarForm: 'genitive',
214 expected: 'доводов',
215 description: 'Grammar test for genitive case'
216 },
217 {
218 word: 'песчаник',
219 grammarForm: 'genitive',
220 expected: 'песчаника',
221 description: 'Grammar test for genitive case'
222 }
223 ],
224
225
226 hu: [
227 {
228 word: 'Wikipédiá',
229 grammarForm: 'rol',
230 expected: 'Wikipédiáról',
231 description: 'Grammar test for rol case'
232 },
233 {
234 word: 'Wikipédiá',
235 grammarForm: 'ba',
236 expected: 'Wikipédiába',
237 description: 'Grammar test for ba case'
238 },
239 {
240 word: 'Wikipédiá',
241 grammarForm: 'k',
242 expected: 'Wikipédiák',
243 description: 'Grammar test for k case'
244 }
245 ],
246
247 ga: [
248 {
249 word: 'an Domhnach',
250 grammarForm: 'ainmlae',
251 expected: 'Dé Domhnaigh',
252 description: 'Grammar test for ainmlae case'
253 },
254 {
255 word: 'an Luan',
256 grammarForm: 'ainmlae',
257 expected: 'Dé Luain',
258 description: 'Grammar test for ainmlae case'
259 },
260 {
261 word: 'an Satharn',
262 grammarForm: 'ainmlae',
263 expected: 'Dé Sathairn',
264 description: 'Grammar test for ainmlae case'
265 }
266 ],
267
268 uk: [
269 {
270 word: 'тесть',
271 grammarForm: 'genitive',
272 expected: 'тестя',
273 description: 'Grammar test for genitive case'
274 },
275 {
276 word: 'Вікіпедія',
277 grammarForm: 'genitive',
278 expected: 'Вікіпедії',
279 description: 'Grammar test for genitive case'
280 },
281 {
282 word: 'установка',
283 grammarForm: 'genitive',
284 expected: 'установки',
285 description: 'Grammar test for genitive case'
286 },
287 {
288 word: 'похоти',
289 grammarForm: 'genitive',
290 expected: 'похотей',
291 description: 'Grammar test for genitive case'
292 },
293 {
294 word: 'доводы',
295 grammarForm: 'genitive',
296 expected: 'доводов',
297 description: 'Grammar test for genitive case'
298 },
299 {
300 word: 'песчаник',
301 grammarForm: 'genitive',
302 expected: 'песчаника',
303 description: 'Grammar test for genitive case'
304 },
305 {
306 word: 'Вікіпедія',
307 grammarForm: 'accusative',
308 expected: 'Вікіпедію',
309 description: 'Grammar test for accusative case'
310 }
311 ],
312
313 sl: [
314 {
315 word: 'word',
316 grammarForm: 'orodnik',
317 expected: 'z word',
318 description: 'Grammar test for orodnik case'
319 },
320 {
321 word: 'word',
322 grammarForm: 'mestnik',
323 expected: 'o word',
324 description: 'Grammar test for mestnik case'
325 }
326 ],
327
328 os: [
329 {
330 word: 'бæстæ',
331 grammarForm: 'genitive',
332 expected: 'бæсты',
333 description: 'Grammar test for genitive case'
334 },
335 {
336 word: 'бæстæ',
337 grammarForm: 'allative',
338 expected: 'бæстæм',
339 description: 'Grammar test for allative case'
340 },
341 {
342 word: 'Тигр',
343 grammarForm: 'dative',
344 expected: 'Тигрæн',
345 description: 'Grammar test for dative case'
346 },
347 {
348 word: 'цъити',
349 grammarForm: 'dative',
350 expected: 'цъитийæн',
351 description: 'Grammar test for dative case'
352 },
353 {
354 word: 'лæппу',
355 grammarForm: 'genitive',
356 expected: 'лæппуйы',
357 description: 'Grammar test for genitive case'
358 },
359 {
360 word: '2011',
361 grammarForm: 'equative',
362 expected: '2011-ау',
363 description: 'Grammar test for equative case'
364 }
365 ],
366
367 la: [
368 {
369 word: 'Translatio',
370 grammarForm: 'genitive',
371 expected: 'Translationis',
372 description: 'Grammar test for genitive case'
373 },
374 {
375 word: 'Translatio',
376 grammarForm: 'accusative',
377 expected: 'Translationem',
378 description: 'Grammar test for accusative case'
379 },
380 {
381 word: 'Translatio',
382 grammarForm: 'ablative',
383 expected: 'Translatione',
384 description: 'Grammar test for ablative case'
385 }
386 ]
387 };
388
389 $.each( grammarTests, function ( langCode, test ) {
390 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
391 grammarTest( langCode, test );
392 }
393 });
394 }( mediaWiki, jQuery ) );