Merge "[LockManager] Cleaned up DBLockManager and reduced code duplication."
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.language.test.js
1 var liveLangData = mw.language.data.values;
2 QUnit.module( 'mediawiki.language', QUnit.newMwEnvironment({
3 setup: function () {
4 // New independent copy for this test
5 mw.language.data = $.extend( {}, liveLangData, true );
6 },
7 teardown: function () {
8 // Restore original
9 mw.language.data = liveLangData;
10 }
11 }) );
12
13 QUnit.test( 'mw.language getData and setData', function ( assert ) {
14 QUnit.expect( 2 );
15
16 mw.language.setData( 'en', 'testkey', 'testvalue' );
17 assert.equal( mw.language.getData( 'en', 'testkey' ), 'testvalue', 'Getter setter test for mw.language' );
18 assert.equal( mw.language.getData( 'en', 'invalidkey' ), undefined, 'Getter setter test for mw.language with invalid key' );
19 } );
20
21 function grammarTest( langCode, test ) {
22 // The test works only if the content language is opt.language
23 // because it requires [lang].js to be loaded.
24 QUnit.test( 'Grammar test for lang=' + langCode, function ( assert ) {
25 QUnit.expect( test.length );
26
27 for ( var i = 0 ; i < test.length; i++ ) {
28 assert.equal(
29 mw.language.convertGrammar( test[i].word, test[i].grammarForm ),
30 test[i].expected,
31 test[i].description
32 );
33 }
34 });
35 }
36
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
227
228 hu: [
229 {
230 word: 'Wikipédiá',
231 grammarForm: 'rol',
232 expected: 'Wikipédiáról',
233 description: 'Grammar test for rol case'
234 },
235 {
236 word: 'Wikipédiá',
237 grammarForm: 'ba',
238 expected: 'Wikipédiába',
239 description: 'Grammar test for ba case'
240 },
241 {
242 word: 'Wikipédiá',
243 grammarForm: 'k',
244 expected: 'Wikipédiák',
245 description: 'Grammar test for k case'
246 }
247 ],
248
249 ga: [
250 {
251 word: 'an Domhnach',
252 grammarForm: 'ainmlae',
253 expected: 'Dé Domhnaigh',
254 description: 'Grammar test for ainmlae case'
255 },
256 {
257 word: 'an Luan',
258 grammarForm: 'ainmlae',
259 expected: 'Dé Luain',
260 description: 'Grammar test for ainmlae case'
261 },
262 {
263 word: 'an Satharn',
264 grammarForm: 'ainmlae',
265 expected: 'Dé Sathairn',
266 description: 'Grammar test for ainmlae case'
267 }
268 ],
269
270 uk: [
271 {
272 word: 'тесть',
273 grammarForm: 'genitive',
274 expected: 'тестя',
275 description: 'Grammar test for genitive case'
276 },
277 {
278 word: 'Вікіпедія',
279 grammarForm: 'genitive',
280 expected: 'Вікіпедії',
281 description: 'Grammar test for genitive case'
282 },
283 {
284 word: 'установка',
285 grammarForm: 'genitive',
286 expected: 'установки',
287 description: 'Grammar test for genitive case'
288 },
289 {
290 word: 'похоти',
291 grammarForm: 'genitive',
292 expected: 'похотей',
293 description: 'Grammar test for genitive case'
294 },
295 {
296 word: 'доводы',
297 grammarForm: 'genitive',
298 expected: 'доводов',
299 description: 'Grammar test for genitive case'
300 },
301 {
302 word: 'песчаник',
303 grammarForm: 'genitive',
304 expected: 'песчаника',
305 description: 'Grammar test for genitive case'
306 },
307 {
308 word: 'Вікіпедія',
309 grammarForm: 'accusative',
310 expected: 'Вікіпедію',
311 description: 'Grammar test for accusative case'
312 }
313 ],
314
315 sl: [
316 {
317 word: 'word',
318 grammarForm: 'orodnik',
319 expected: 'z word',
320 description: 'Grammar test for orodnik case'
321 },
322 {
323 word: 'word',
324 grammarForm: 'mestnik',
325 expected: 'o word',
326 description: 'Grammar test for mestnik case'
327 }
328 ],
329
330 os: [
331 {
332 word: 'бæстæ',
333 grammarForm: 'genitive',
334 expected: 'бæсты',
335 description: 'Grammar test for genitive case'
336 },
337 {
338 word: 'бæстæ',
339 grammarForm: 'allative',
340 expected: 'бæстæм',
341 description: 'Grammar test for allative case'
342 },
343 {
344 word: 'Тигр',
345 grammarForm: 'dative',
346 expected: 'Тигрæн',
347 description: 'Grammar test for dative case'
348 },
349 {
350 word: 'цъити',
351 grammarForm: 'dative',
352 expected: 'цъитийæн',
353 description: 'Grammar test for dative case'
354 },
355 {
356 word: 'лæппу',
357 grammarForm: 'genitive',
358 expected: 'лæппуйы',
359 description: 'Grammar test for genitive case'
360 },
361 {
362 word: '2011',
363 grammarForm: 'equative',
364 expected: '2011-ау',
365 description: 'Grammar test for equative case'
366 }
367 ],
368
369 la: [
370 {
371 word: 'Translatio',
372 grammarForm: 'genitive',
373 expected: 'Translationis',
374 description: 'Grammar test for genitive case'
375 },
376 {
377 word: 'Translatio',
378 grammarForm: 'accusative',
379 expected: 'Translationem',
380 description: 'Grammar test for accusative case'
381 },
382 {
383 word: 'Translatio',
384 grammarForm: 'ablative',
385 expected: 'Translatione',
386 description: 'Grammar test for ablative case'
387 }
388 ]
389 };
390
391 $.each( grammarTests, function ( langCode, test ) {
392 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
393 grammarTest( langCode, test );
394 }
395 });