blob: bb2c354a3d62e01b6d34ef5427f3bb1fe38da62b [file] [log] [blame]
Bram Moolenaaraa970ab2020-08-02 16:10:39 +02001" Test for spell checking with 'encoding' set to utf-8
2
3source check.vim
4CheckFeature spell
5
6scriptencoding utf-8
7
8func TearDown()
9 set nospell
10 call delete('Xtest.aff')
11 call delete('Xtest.dic')
12 call delete('Xtest.utf-8.add')
13 call delete('Xtest.utf-8.add.spl')
14 call delete('Xtest.utf-8.spl')
15 call delete('Xtest.utf-8.sug')
zeertzjq288ed232022-07-04 11:03:07 +010016 " set 'encoding' to clear the word list
17 set encoding=utf-8
Bram Moolenaaraa970ab2020-08-02 16:10:39 +020018endfunc
19
20let g:test_data_aff1 = [
21 \"SET ISO8859-1",
22 \"TRY esianrtolcdugmphbyfvkwjkqxz-ëéèêïîäàâöüû'ESIANRTOLCDUGMPHBYFVKWJKQXZ",
23 \"",
24 \"FOL àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ",
25 \"LOW àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ",
26 \"UPP ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßÿ",
27 \"",
28 \"SOFOFROM abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xBF",
29 \"SOFOTO ebctefghejklnnepkrstevvkesebctefghejklnnepkrstevvkeseeeeeeeceeeeeeeedneeeeeeeeeeepseeeeeeeeceeeeeeeedneeeeeeeeeeep?",
30 \"",
31 \"MIDWORD\t'-",
32 \"",
33 \"KEP =",
34 \"RAR ?",
35 \"BAD !",
36 \"",
37 \"PFX I N 1",
38 \"PFX I 0 in .",
39 \"",
40 \"PFX O Y 1",
41 \"PFX O 0 out .",
42 \"",
43 \"SFX S Y 2",
44 \"SFX S 0 s [^s]",
45 \"SFX S 0 es s",
46 \"",
47 \"SFX N N 3",
48 \"SFX N 0 en [^n]",
49 \"SFX N 0 nen n",
50 \"SFX N 0 n .",
51 \"",
52 \"REP 3",
53 \"REP g ch",
54 \"REP ch g",
55 \"REP svp s.v.p.",
56 \"",
57 \"MAP 9",
58 \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
59 \"MAP e\xE8\xE9\xEA\xEB",
60 \"MAP i\xEC\xED\xEE\xEF",
61 \"MAP o\xF2\xF3\xF4\xF5\xF6",
62 \"MAP u\xF9\xFA\xFB\xFC",
63 \"MAP n\xF1",
64 \"MAP c\xE7",
65 \"MAP y\xFF\xFD",
66 \"MAP s\xDF"
67 \ ]
68let g:test_data_dic1 = [
69 \"123456",
70 \"test/NO",
71 \"# comment",
72 \"wrong",
73 \"Comment",
74 \"OK",
75 \"uk",
76 \"put/ISO",
77 \"the end",
78 \"deol",
79 \"d\xE9\xF4r",
80 \ ]
81let g:test_data_aff2 = [
82 \"SET ISO8859-1",
83 \"",
84 \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
85 \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
86 \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF",
87 \"",
88 \"PFXPOSTPONE",
89 \"",
90 \"MIDWORD\t'-",
91 \"",
92 \"KEP =",
93 \"RAR ?",
94 \"BAD !",
95 \"",
96 \"PFX I N 1",
97 \"PFX I 0 in .",
98 \"",
99 \"PFX O Y 1",
100 \"PFX O 0 out [a-z]",
101 \"",
102 \"SFX S Y 2",
103 \"SFX S 0 s [^s]",
104 \"SFX S 0 es s",
105 \"",
106 \"SFX N N 3",
107 \"SFX N 0 en [^n]",
108 \"SFX N 0 nen n",
109 \"SFX N 0 n .",
110 \"",
111 \"REP 3",
112 \"REP g ch",
113 \"REP ch g",
114 \"REP svp s.v.p.",
115 \"",
116 \"MAP 9",
117 \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
118 \"MAP e\xE8\xE9\xEA\xEB",
119 \"MAP i\xEC\xED\xEE\xEF",
120 \"MAP o\xF2\xF3\xF4\xF5\xF6",
121 \"MAP u\xF9\xFA\xFB\xFC",
122 \"MAP n\xF1",
123 \"MAP c\xE7",
124 \"MAP y\xFF\xFD",
125 \"MAP s\xDF",
126 \ ]
127let g:test_data_aff3 = [
128 \"SET ISO8859-1",
129 \"",
130 \"COMPOUNDMIN 3",
131 \"COMPOUNDRULE m*",
132 \"NEEDCOMPOUND x",
133 \ ]
134let g:test_data_dic3 = [
135 \"1234",
136 \"foo/m",
137 \"bar/mx",
138 \"m\xEF/m",
139 \"la/mx",
140 \ ]
141let g:test_data_aff4 = [
142 \"SET ISO8859-1",
143 \"",
144 \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
145 \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
146 \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF",
147 \"",
148 \"COMPOUNDRULE m+",
149 \"COMPOUNDRULE sm*e",
150 \"COMPOUNDRULE sm+",
151 \"COMPOUNDMIN 3",
152 \"COMPOUNDWORDMAX 3",
153 \"COMPOUNDFORBIDFLAG t",
154 \"",
155 \"COMPOUNDSYLMAX 5",
156 \"SYLLABLE a\xE1e\xE9i\xEDo\xF3\xF6\xF5u\xFA\xFC\xFBy/aa/au/ea/ee/ei/ie/oa/oe/oo/ou/uu/ui",
157 \"",
158 \"MAP 9",
159 \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
160 \"MAP e\xE8\xE9\xEA\xEB",
161 \"MAP i\xEC\xED\xEE\xEF",
162 \"MAP o\xF2\xF3\xF4\xF5\xF6",
163 \"MAP u\xF9\xFA\xFB\xFC",
164 \"MAP n\xF1",
165 \"MAP c\xE7",
166 \"MAP y\xFF\xFD",
167 \"MAP s\xDF",
168 \"",
169 \"NEEDAFFIX x",
170 \"",
171 \"PFXPOSTPONE",
172 \"",
173 \"MIDWORD '-",
174 \"",
175 \"SFX q N 1",
176 \"SFX q 0 -ok .",
177 \"",
178 \"SFX a Y 2",
179 \"SFX a 0 s .",
180 \"SFX a 0 ize/t .",
181 \"",
182 \"PFX p N 1",
183 \"PFX p 0 pre .",
184 \"",
185 \"PFX P N 1",
186 \"PFX P 0 nou .",
187 \ ]
188let g:test_data_dic4 = [
189 \"1234",
190 \"word/mP",
191 \"util/am",
192 \"pro/xq",
193 \"tomato/m",
194 \"bork/mp",
195 \"start/s",
196 \"end/e",
197 \ ]
198let g:test_data_aff5 = [
199 \"SET ISO8859-1",
200 \"",
201 \"FLAG long",
202 \"",
203 \"NEEDAFFIX !!",
204 \"",
205 \"COMPOUNDRULE ssmm*ee",
206 \"",
207 \"NEEDCOMPOUND xx",
208 \"COMPOUNDPERMITFLAG pp",
209 \"",
210 \"SFX 13 Y 1",
211 \"SFX 13 0 bork .",
212 \"",
213 \"SFX a1 Y 1",
214 \"SFX a1 0 a1 .",
215 \"",
216 \"SFX a\xE9 Y 1",
217 \"SFX a\xE9 0 a\xE9 .",
218 \"",
219 \"PFX zz Y 1",
220 \"PFX zz 0 pre/pp .",
221 \"",
222 \"PFX yy Y 1",
223 \"PFX yy 0 nou .",
224 \ ]
225let g:test_data_dic5 = [
226 \"1234",
227 \"foo/a1a\xE9!!",
228 \"bar/zz13ee",
229 \"start/ss",
230 \"end/eeyy",
231 \"middle/mmxx",
232 \ ]
233let g:test_data_aff6 = [
234 \"SET ISO8859-1",
235 \"",
236 \"FLAG caplong",
237 \"",
238 \"NEEDAFFIX A!",
239 \"",
240 \"COMPOUNDRULE sMm*Ee",
241 \"",
242 \"NEEDCOMPOUND Xx",
243 \"",
244 \"COMPOUNDPERMITFLAG p",
245 \"",
246 \"SFX N3 Y 1",
247 \"SFX N3 0 bork .",
248 \"",
249 \"SFX A1 Y 1",
250 \"SFX A1 0 a1 .",
251 \"",
252 \"SFX A\xE9 Y 1",
253 \"SFX A\xE9 0 a\xE9 .",
254 \"",
255 \"PFX Zz Y 1",
256 \"PFX Zz 0 pre/p .",
257 \ ]
258let g:test_data_dic6 = [
259 \"1234",
260 \"mee/A1A\xE9A!",
261 \"bar/ZzN3Ee",
262 \"lead/s",
263 \"end/Ee",
264 \"middle/MmXx",
265 \ ]
266let g:test_data_aff7 = [
267 \"SET ISO8859-1",
268 \"",
269 \"FLAG num",
270 \"",
271 \"NEEDAFFIX 9999",
272 \"",
273 \"COMPOUNDRULE 2,77*123",
274 \"",
275 \"NEEDCOMPOUND 1",
276 \"COMPOUNDPERMITFLAG 432",
277 \"",
278 \"SFX 61003 Y 1",
279 \"SFX 61003 0 meat .",
280 \"",
281 \"SFX 0 Y 1",
282 \"SFX 0 0 zero .",
283 \"",
284 \"SFX 391 Y 1",
285 \"SFX 391 0 a1 .",
286 \"",
287 \"SFX 111 Y 1",
288 \"SFX 111 0 a\xE9 .",
289 \"",
290 \"PFX 17 Y 1",
291 \"PFX 17 0 pre/432 .",
292 \ ]
293let g:test_data_dic7 = [
294 \"1234",
295 \"mee/0,391,111,9999",
296 \"bar/17,61003,123",
297 \"lead/2",
298 \"tail/123",
299 \"middle/77,1",
300 \ ]
301let g:test_data_aff8 = [
302 \"SET ISO8859-1",
303 \"",
304 \"NOSPLITSUGS",
305 \ ]
306let g:test_data_dic8 = [
307 \"1234",
308 \"foo",
309 \"bar",
310 \"faabar",
311 \ ]
312let g:test_data_aff9 = [
313 \ ]
314let g:test_data_dic9 = [
315 \"1234",
316 \"foo",
317 \"bar",
318 \ ]
319let g:test_data_aff10 = [
320 \"COMPOUNDRULE se",
321 \"COMPOUNDPERMITFLAG p",
322 \"",
323 \"SFX A Y 1",
324 \"SFX A 0 able/Mp .",
325 \"",
326 \"SFX M Y 1",
327 \"SFX M 0 s .",
328 \ ]
329let g:test_data_dic10 = [
330 \"1234",
331 \"drink/As",
332 \"table/e",
333 \ ]
334let g:test_data_aff_sal = [
335 \"SET ISO8859-1",
336 \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ",
337 \"",
338 \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
339 \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
340 \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF",
341 \"",
342 \"MIDWORD\t'-",
343 \"",
344 \"KEP =",
345 \"RAR ?",
346 \"BAD !",
347 \"",
348 \"PFX I N 1",
349 \"PFX I 0 in .",
350 \"",
351 \"PFX O Y 1",
352 \"PFX O 0 out .",
353 \"",
354 \"SFX S Y 2",
355 \"SFX S 0 s [^s]",
356 \"SFX S 0 es s",
357 \"",
358 \"SFX N N 3",
359 \"SFX N 0 en [^n]",
360 \"SFX N 0 nen n",
361 \"SFX N 0 n .",
362 \"",
363 \"REP 3",
364 \"REP g ch",
365 \"REP ch g",
366 \"REP svp s.v.p.",
367 \"",
368 \"MAP 9",
369 \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
370 \"MAP e\xE8\xE9\xEA\xEB",
371 \"MAP i\xEC\xED\xEE\xEF",
372 \"MAP o\xF2\xF3\xF4\xF5\xF6",
373 \"MAP u\xF9\xFA\xFB\xFC",
374 \"MAP n\xF1",
375 \"MAP c\xE7",
376 \"MAP y\xFF\xFD",
377 \"MAP s\xDF",
378 \"",
379 \"SAL AH(AEIOUY)-^ *H",
380 \"SAL AR(AEIOUY)-^ *R",
381 \"SAL A(HR)^ *",
382 \"SAL A^ *",
383 \"SAL AH(AEIOUY)- H",
384 \"SAL AR(AEIOUY)- R",
385 \"SAL A(HR) _",
386 \"SAL \xC0^ *",
387 \"SAL \xC5^ *",
388 \"SAL BB- _",
389 \"SAL B B",
390 \"SAL CQ- _",
391 \"SAL CIA X",
392 \"SAL CH X",
393 \"SAL C(EIY)- S",
394 \"SAL CK K",
395 \"SAL COUGH^ KF",
396 \"SAL CC< C",
397 \"SAL C K",
398 \"SAL DG(EIY) K",
399 \"SAL DD- _",
400 \"SAL D T",
401 \"SAL \xC9< E",
402 \"SAL EH(AEIOUY)-^ *H",
403 \"SAL ER(AEIOUY)-^ *R",
404 \"SAL E(HR)^ *",
405 \"SAL ENOUGH^$ *NF",
406 \"SAL E^ *",
407 \"SAL EH(AEIOUY)- H",
408 \"SAL ER(AEIOUY)- R",
409 \"SAL E(HR) _",
410 \"SAL FF- _",
411 \"SAL F F",
412 \"SAL GN^ N",
413 \"SAL GN$ N",
414 \"SAL GNS$ NS",
415 \"SAL GNED$ N",
416 \"SAL GH(AEIOUY)- K",
417 \"SAL GH _",
418 \"SAL GG9 K",
419 \"SAL G K",
420 \"SAL H H",
421 \"SAL IH(AEIOUY)-^ *H",
422 \"SAL IR(AEIOUY)-^ *R",
423 \"SAL I(HR)^ *",
424 \"SAL I^ *",
425 \"SAL ING6 N",
426 \"SAL IH(AEIOUY)- H",
427 \"SAL IR(AEIOUY)- R",
428 \"SAL I(HR) _",
429 \"SAL J K",
430 \"SAL KN^ N",
431 \"SAL KK- _",
432 \"SAL K K",
433 \"SAL LAUGH^ LF",
434 \"SAL LL- _",
435 \"SAL L L",
436 \"SAL MB$ M",
437 \"SAL MM M",
438 \"SAL M M",
439 \"SAL NN- _",
440 \"SAL N N",
441 \"SAL OH(AEIOUY)-^ *H",
442 \"SAL OR(AEIOUY)-^ *R",
443 \"SAL O(HR)^ *",
444 \"SAL O^ *",
445 \"SAL OH(AEIOUY)- H",
446 \"SAL OR(AEIOUY)- R",
447 \"SAL O(HR) _",
448 \"SAL PH F",
449 \"SAL PN^ N",
450 \"SAL PP- _",
451 \"SAL P P",
452 \"SAL Q K",
453 \"SAL RH^ R",
454 \"SAL ROUGH^ RF",
455 \"SAL RR- _",
456 \"SAL R R",
457 \"SAL SCH(EOU)- SK",
458 \"SAL SC(IEY)- S",
459 \"SAL SH X",
460 \"SAL SI(AO)- X",
461 \"SAL SS- _",
462 \"SAL S S",
463 \"SAL TI(AO)- X",
464 \"SAL TH @",
465 \"SAL TCH-- _",
466 \"SAL TOUGH^ TF",
467 \"SAL TT- _",
468 \"SAL T T",
469 \"SAL UH(AEIOUY)-^ *H",
470 \"SAL UR(AEIOUY)-^ *R",
471 \"SAL U(HR)^ *",
472 \"SAL U^ *",
473 \"SAL UH(AEIOUY)- H",
474 \"SAL UR(AEIOUY)- R",
475 \"SAL U(HR) _",
476 \"SAL V^ W",
477 \"SAL V F",
478 \"SAL WR^ R",
479 \"SAL WH^ W",
480 \"SAL W(AEIOU)- W",
481 \"SAL X^ S",
482 \"SAL X KS",
483 \"SAL Y(AEIOU)- Y",
484 \"SAL ZZ- _",
485 \"SAL Z S",
486 \ ]
487
488func LoadAffAndDic(aff_contents, dic_contents)
Bram Moolenaaraa970ab2020-08-02 16:10:39 +0200489 set spellfile=
490 call writefile(a:aff_contents, "Xtest.aff")
491 call writefile(a:dic_contents, "Xtest.dic")
492 " Generate a .spl file from a .dic and .aff file.
493 mkspell! Xtest Xtest
494 " use that spell file
495 set spl=Xtest.utf-8.spl spell
496endfunc
497
498func ListWords()
499 spelldump
500 %yank
501 quit
502 return split(@", "\n")
503endfunc
504
505func TestGoodBadBase()
506 exe '1;/^good:'
507 normal 0f:]s
508 let prevbad = ''
509 let result = []
510 while 1
511 let [bad, a] = spellbadword()
512 if bad == '' || bad == prevbad || bad == 'badend'
513 break
514 endif
515 let prevbad = bad
516 let lst = bad->spellsuggest(3)
517 normal mm
518
519 call add(result, [bad, lst])
520 normal `m]s
521 endwhile
522 return result
523endfunc
524
525func RunGoodBad(good, bad, expected_words, expected_bad_words)
526 %bwipe!
527 call setline(1, ['', "good: ", a:good, a:bad, " badend "])
528 let words = ListWords()
529 call assert_equal(a:expected_words, words[1:-1])
530 let bad_words = TestGoodBadBase()
531 call assert_equal(a:expected_bad_words, bad_words)
532 %bwipe!
533endfunc
534
535func Test_spell_basic()
536 call LoadAffAndDic(g:test_data_aff1, g:test_data_dic1)
537 call RunGoodBad("wrong OK puts. Test the end",
538 \ "bad: inputs comment ok Ok. test d\u00E9\u00F4l end the",
539 \["Comment", "deol", "d\u00E9\u00F4r", "input", "OK", "output", "outputs", "outtest", "put", "puts",
540 \ "test", "testen", "testn", "the end", "uk", "wrong"],
541 \[
542 \ ["bad", ["put", "uk", "OK"]],
543 \ ["inputs", ["input", "puts", "outputs"]],
544 \ ["comment", ["Comment", "outtest", "the end"]],
545 \ ["ok", ["OK", "uk", "put"]],
546 \ ["Ok", ["OK", "Uk", "Put"]],
547 \ ["test", ["Test", "testn", "testen"]],
548 \ ["d\u00E9\u00F4l", ["deol", "d\u00E9\u00F4r", "test"]],
549 \ ["end", ["put", "uk", "test"]],
550 \ ["the", ["put", "uk", "test"]],
551 \ ]
552 \ )
553
554 call assert_equal("gebletegek", soundfold('goobledygoook'))
555 call assert_equal("kepereneven", 'kóopërÿnôven'->soundfold())
556 call assert_equal("everles gesvets etele", soundfold('oeverloos gezwets edale'))
557endfunc
558
559" Postponed prefixes
560func Test_spell_prefixes()
561 call LoadAffAndDic(g:test_data_aff2, g:test_data_dic1)
562 call RunGoodBad("puts",
563 \ "bad: inputs comment ok Ok end the. test d\u00E9\u00F4l",
564 \ ["Comment", "deol", "d\u00E9\u00F4r", "OK", "put", "input", "output", "puts", "outputs", "test", "outtest", "testen", "testn", "the end", "uk", "wrong"],
565 \ [
566 \ ["bad", ["put", "uk", "OK"]],
567 \ ["inputs", ["input", "puts", "outputs"]],
568 \ ["comment", ["Comment"]],
569 \ ["ok", ["OK", "uk", "put"]],
570 \ ["Ok", ["OK", "Uk", "Put"]],
571 \ ["end", ["put", "uk", "deol"]],
572 \ ["the", ["put", "uk", "test"]],
573 \ ["test", ["Test", "testn", "testen"]],
574 \ ["d\u00E9\u00F4l", ["deol", "d\u00E9\u00F4r", "test"]],
575 \ ])
576endfunc
577
578"Compound words
579func Test_spell_compound()
580 call LoadAffAndDic(g:test_data_aff3, g:test_data_dic3)
581 call RunGoodBad("foo m\u00EF foobar foofoobar barfoo barbarfoo",
582 \ "bad: bar la foom\u00EF barm\u00EF m\u00EFfoo m\u00EFbar m\u00EFm\u00EF lala m\u00EFla lam\u00EF foola labar",
583 \ ["foo", "m\u00EF"],
584 \ [
585 \ ["bad", ["foo", "m\u00EF"]],
586 \ ["bar", ["barfoo", "foobar", "foo"]],
587 \ ["la", ["m\u00EF", "foo"]],
588 \ ["foom\u00EF", ["foo m\u00EF", "foo", "foofoo"]],
589 \ ["barm\u00EF", ["barfoo", "m\u00EF", "barbar"]],
590 \ ["m\u00EFfoo", ["m\u00EF foo", "foo", "foofoo"]],
591 \ ["m\u00EFbar", ["foobar", "barbar", "m\u00EF"]],
592 \ ["m\u00EFm\u00EF", ["m\u00EF m\u00EF", "m\u00EF"]],
593 \ ["lala", []],
594 \ ["m\u00EFla", ["m\u00EF", "m\u00EF m\u00EF"]],
595 \ ["lam\u00EF", ["m\u00EF", "m\u00EF m\u00EF"]],
596 \ ["foola", ["foo", "foobar", "foofoo"]],
597 \ ["labar", ["barbar", "foobar"]],
598 \ ])
599
600 call LoadAffAndDic(g:test_data_aff4, g:test_data_dic4)
601 call RunGoodBad("word util bork prebork start end wordutil wordutils pro-ok bork borkbork borkborkbork borkborkborkbork borkborkborkborkbork tomato tomatotomato startend startword startwordword startwordend startwordwordend startwordwordwordend prebork preborkbork preborkborkbork nouword",
602 \ "bad: wordutilize pro borkborkborkborkborkbork tomatotomatotomato endstart endend startstart wordend wordstart preborkprebork preborkpreborkbork startwordwordwordwordend borkpreborkpreborkbork utilsbork startnouword",
603 \ ["bork", "prebork", "end", "pro-ok", "start", "tomato", "util", "utilize", "utils", "word", "nouword"],
604 \ [
605 \ ["bad", ["end", "bork", "word"]],
606 \ ["wordutilize", ["word utilize", "wordutils", "wordutil"]],
607 \ ["pro", ["bork", "word", "end"]],
608 \ ["borkborkborkborkborkbork", ["bork borkborkborkborkbork", "borkbork borkborkborkbork", "borkborkbork borkborkbork"]],
609 \ ["tomatotomatotomato", ["tomato tomatotomato", "tomatotomato tomato", "tomato tomato tomato"]],
610 \ ["endstart", ["end start", "start"]],
611 \ ["endend", ["end end", "end"]],
612 \ ["startstart", ["start start"]],
613 \ ["wordend", ["word end", "word", "wordword"]],
614 \ ["wordstart", ["word start", "bork start"]],
615 \ ["preborkprebork", ["prebork prebork", "preborkbork", "preborkborkbork"]],
616 \ ["preborkpreborkbork", ["prebork preborkbork", "preborkborkbork", "preborkborkborkbork"]],
617 \ ["startwordwordwordwordend", ["startwordwordwordword end", "startwordwordwordword", "start wordwordwordword end"]],
618 \ ["borkpreborkpreborkbork", ["bork preborkpreborkbork", "bork prebork preborkbork", "bork preborkprebork bork"]],
619 \ ["utilsbork", ["utilbork", "utils bork", "util bork"]],
620 \ ["startnouword", ["start nouword", "startword", "startborkword"]],
621 \ ])
622
623endfunc
624
625" Test affix flags with two characters
626func Test_spell_affix()
627 call LoadAffAndDic(g:test_data_aff5, g:test_data_dic5)
628 call RunGoodBad("fooa1 fooa\u00E9 bar prebar barbork prebarbork startprebar start end startend startmiddleend nouend",
629 \ "bad: foo fooa2 prabar probarbirk middle startmiddle middleend endstart startprobar startnouend",
630 \ ["bar", "barbork", "end", "fooa1", "fooa\u00E9", "nouend", "prebar", "prebarbork", "start"],
631 \ [
632 \ ["bad", ["bar", "end", "fooa1"]],
Bram Moolenaar6d24b4f2022-05-23 12:01:50 +0100633 \ ["foo", ["fooa1", "bar", "end"]],
Bram Moolenaaraa970ab2020-08-02 16:10:39 +0200634 \ ["fooa2", ["fooa1", "fooa\u00E9", "bar"]],
635 \ ["prabar", ["prebar", "bar", "bar bar"]],
636 \ ["probarbirk", ["prebarbork"]],
637 \ ["middle", []],
638 \ ["startmiddle", ["startmiddleend", "startmiddlebar"]],
639 \ ["middleend", []],
640 \ ["endstart", ["end start", "start"]],
641 \ ["startprobar", ["startprebar", "start prebar", "startbar"]],
642 \ ["startnouend", ["start nouend", "startend"]],
643 \ ])
644
645 call LoadAffAndDic(g:test_data_aff6, g:test_data_dic6)
646 call RunGoodBad("meea1 meea\u00E9 bar prebar barbork prebarbork leadprebar lead end leadend leadmiddleend",
647 \ "bad: mee meea2 prabar probarbirk middle leadmiddle middleend endlead leadprobar",
648 \ ["bar", "barbork", "end", "lead", "meea1", "meea\u00E9", "prebar", "prebarbork"],
649 \ [
650 \ ["bad", ["bar", "end", "lead"]],
Bram Moolenaar6d24b4f2022-05-23 12:01:50 +0100651 \ ["mee", ["meea1", "bar", "end"]],
Bram Moolenaaraa970ab2020-08-02 16:10:39 +0200652 \ ["meea2", ["meea1", "meea\u00E9", "lead"]],
653 \ ["prabar", ["prebar", "bar", "leadbar"]],
654 \ ["probarbirk", ["prebarbork"]],
655 \ ["middle", []],
656 \ ["leadmiddle", ["leadmiddleend", "leadmiddlebar"]],
657 \ ["middleend", []],
658 \ ["endlead", ["end lead", "lead", "end end"]],
659 \ ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]],
660 \ ])
661
662 call LoadAffAndDic(g:test_data_aff7, g:test_data_dic7)
663 call RunGoodBad("meea1 meezero meea\u00E9 bar prebar barmeat prebarmeat leadprebar lead tail leadtail leadmiddletail",
664 \ "bad: mee meea2 prabar probarmaat middle leadmiddle middletail taillead leadprobar",
665 \ ["bar", "barmeat", "lead", "meea1", "meea\u00E9", "meezero", "prebar", "prebarmeat", "tail"],
666 \ [
667 \ ["bad", ["bar", "lead", "tail"]],
Bram Moolenaar6d24b4f2022-05-23 12:01:50 +0100668 \ ["mee", ["meea1", "bar", "lead"]],
Bram Moolenaaraa970ab2020-08-02 16:10:39 +0200669 \ ["meea2", ["meea1", "meea\u00E9", "lead"]],
670 \ ["prabar", ["prebar", "bar", "leadbar"]],
671 \ ["probarmaat", ["prebarmeat"]],
672 \ ["middle", []],
673 \ ["leadmiddle", ["leadmiddlebar"]],
674 \ ["middletail", []],
675 \ ["taillead", ["tail lead", "tail"]],
676 \ ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]],
677 \ ])
678endfunc
679
680func Test_spell_NOSLITSUGS()
681 call LoadAffAndDic(g:test_data_aff8, g:test_data_dic8)
682 call RunGoodBad("foo bar faabar", "bad: foobar barfoo",
683 \ ["bar", "faabar", "foo"],
684 \ [
685 \ ["bad", ["bar", "foo"]],
686 \ ["foobar", ["faabar", "foo bar", "bar"]],
687 \ ["barfoo", ["bar foo", "bar", "foo"]],
688 \ ])
689endfunc
690
691" Numbers
692func Test_spell_Numbers()
693 call LoadAffAndDic(g:test_data_aff9, g:test_data_dic9)
694 call RunGoodBad("0b1011 0777 1234 0x01ff", "",
695 \ ["bar", "foo"],
696 \ [
697 \ ])
698endfunc
699
700" Affix flags
701func Test_spell_affix_flags()
702 call LoadAffAndDic(g:test_data_aff10, g:test_data_dic10)
703 call RunGoodBad("drink drinkable drinkables drinktable drinkabletable",
704 \ "bad: drinks drinkstable drinkablestable",
705 \ ["drink", "drinkable", "drinkables", "table"],
706 \ [['bad', []],
707 \ ['drinks', ['drink']],
708 \ ['drinkstable', ['drinktable', 'drinkable', 'drink table']],
709 \ ['drinkablestable', ['drinkabletable', 'drinkables table', 'drinkable table']],
710 \ ])
711endfunc
712
713function FirstSpellWord()
714 call feedkeys("/^start:\n", 'tx')
715 normal ]smm
716 let [str, a] = spellbadword()
717 return str
718endfunc
719
720function SecondSpellWord()
721 normal `m]s
722 let [str, a] = spellbadword()
723 return str
724endfunc
725
726" Test with SAL instead of SOFO items; test automatic reloading
727func Test_spell_sal_and_addition()
728 set spellfile=
Bram Moolenaar56564962022-10-10 22:39:42 +0100729 call writefile(g:test_data_dic1, "Xtest.dic", 'D')
730 call writefile(g:test_data_aff_sal, "Xtest.aff", 'D')
Bram Moolenaaraa970ab2020-08-02 16:10:39 +0200731 mkspell! Xtest Xtest
732 set spl=Xtest.utf-8.spl spell
733 call assert_equal('kbltykk', soundfold('goobledygoook'))
734 call assert_equal('kprnfn', soundfold('kóopërÿnôven'))
735 call assert_equal('*fls kswts tl', soundfold('oeverloos gezwets edale'))
736
737 "also use an addition file
Bram Moolenaar56564962022-10-10 22:39:42 +0100738 call writefile(["/regions=usgbnz", "elequint/2", "elekwint/3"], "Xtest.utf-8.add", 'D')
Bram Moolenaaraa970ab2020-08-02 16:10:39 +0200739 mkspell! Xtest.utf-8.add.spl Xtest.utf-8.add
740
741 bwipe!
742 call setline(1, ["start: elequint test elekwint test elekwent asdf"])
743
744 set spellfile=Xtest.utf-8.add
745 call assert_equal("elekwent", FirstSpellWord())
746
747 set spl=Xtest_us.utf-8.spl
748 call assert_equal("elequint", FirstSpellWord())
749 call assert_equal("elekwint", SecondSpellWord())
750
751 set spl=Xtest_gb.utf-8.spl
752 call assert_equal("elekwint", FirstSpellWord())
753 call assert_equal("elekwent", SecondSpellWord())
754
755 set spl=Xtest_nz.utf-8.spl
756 call assert_equal("elequint", FirstSpellWord())
757 call assert_equal("elekwent", SecondSpellWord())
758
759 set spl=Xtest_ca.utf-8.spl
760 call assert_equal("elequint", FirstSpellWord())
761 call assert_equal("elekwint", SecondSpellWord())
Bram Moolenaar6d24b4f2022-05-23 12:01:50 +0100762
zeertzjq288ed232022-07-04 11:03:07 +0100763 bwipe!
Bram Moolenaar6d24b4f2022-05-23 12:01:50 +0100764 set spellfile=
765 set spl&
Bram Moolenaaraa970ab2020-08-02 16:10:39 +0200766endfunc
767
768func Test_spellfile_value()
769 set spellfile=Xdir/Xtest.utf-8.add
770 set spellfile=Xdir/Xtest.utf-8.add,Xtest_other.add
Bram Moolenaar6d24b4f2022-05-23 12:01:50 +0100771 set spellfile=
Bram Moolenaaraa970ab2020-08-02 16:10:39 +0200772endfunc
773
Bram Moolenaare275ba42021-10-06 13:41:07 +0100774func Test_no_crash_with_weird_text()
775 new
776 let lines =<< trim END
777 r<sfile>
778 €
779
780
781 €
782 END
783 call setline(1, lines)
Bram Moolenaar95afae62022-07-01 22:44:19 +0100784 try
785 exe "%norm \<C-v>ez=>\<C-v>wzG"
786 catch /E1280:/
787 let caught = 'yes'
788 endtry
789 call assert_equal('yes', caught)
Bram Moolenaare275ba42021-10-06 13:41:07 +0100790
791 bwipe!
792endfunc
793
Bram Moolenaar7c824682022-05-08 22:32:58 +0100794" Invalid bytes may cause trouble when creating the word list.
795func Test_check_for_valid_word()
796 call assert_fails("spellgood! 0\xac", 'E1280:')
797endfunc
798
Bram Moolenaar6d24b4f2022-05-23 12:01:50 +0100799" This was going over the end of the word
800func Test_word_index()
801 new
802 norm R0
803 spellgood! fl0
804 sil norm z=
805
806 bwipe!
Bram Moolenaar6d24b4f2022-05-23 12:01:50 +0100807 call delete('Xtmpfile')
808endfunc
809
Bram Moolenaar2813f382022-06-09 19:54:24 +0100810func Test_check_empty_line()
811 " This was using freed memory
812 enew
813 spellgood! fl
814 norm z=
815 norm yy
816 sil! norm P]svc
817 norm P]s
818
Bram Moolenaar2813f382022-06-09 19:54:24 +0100819 bwipe!
820endfunc
821
Bram Moolenaar1eead4c2022-07-30 11:39:57 +0100822func Test_spell_suggest_too_long()
823 " this was creating a word longer than MAXWLEN
824 new
825 call setline(1, 'a' .. repeat("\u0333", 150))
826 norm! z=
827 bwipe!
828endfunc
829
Bram Moolenaare275ba42021-10-06 13:41:07 +0100830
Bram Moolenaaraa970ab2020-08-02 16:10:39 +0200831" vim: shiftwidth=2 sts=2 expandtab