blob: 146e421d030af93bbfe04d27a222534df03b42c6 [file] [log] [blame]
Bram Moolenaard3f78dc2017-02-25 14:21:10 +01001" Test spell checking
Bram Moolenaar5bcc5a12019-08-06 22:48:02 +02002" Note: this file uses latin1 encoding, but is used with utf-8 encoding.
Bram Moolenaard3f78dc2017-02-25 14:21:10 +01003
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02004source check.vim
5CheckFeature spell
Bram Moolenaard3f78dc2017-02-25 14:21:10 +01006
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02007source screendump.vim
8
Bram Moolenaar1a0f2002017-07-28 15:38:10 +02009func TearDown()
10 set nospell
11 call delete('Xtest.aff')
12 call delete('Xtest.dic')
13 call delete('Xtest.latin1.add')
14 call delete('Xtest.latin1.add.spl')
15 call delete('Xtest.latin1.spl')
16 call delete('Xtest.latin1.sug')
17endfunc
18
Bram Moolenaard3f78dc2017-02-25 14:21:10 +010019func Test_wrap_search()
20 new
21 call setline(1, ['The', '', 'A plong line with two zpelling mistakes', '', 'End'])
22 set spell wrapscan
23 normal ]s
24 call assert_equal('plong', expand('<cword>'))
25 normal ]s
26 call assert_equal('zpelling', expand('<cword>'))
27 normal ]s
28 call assert_equal('plong', expand('<cword>'))
29 bwipe!
30 set nospell
31endfunc
Bram Moolenaar5b276aa2017-04-22 23:49:52 +020032
Bram Moolenaarb73fa622017-12-21 20:27:47 +010033func Test_curswant()
34 new
35 call setline(1, ['Another plong line', 'abcdefghijklmnopq'])
36 set spell wrapscan
37 normal 0]s
38 call assert_equal('plong', expand('<cword>'))
39 normal j
40 call assert_equal(9, getcurpos()[2])
41 normal 0[s
42 call assert_equal('plong', expand('<cword>'))
43 normal j
44 call assert_equal(9, getcurpos()[2])
45
46 normal 0]S
47 call assert_equal('plong', expand('<cword>'))
48 normal j
49 call assert_equal(9, getcurpos()[2])
50 normal 0[S
51 call assert_equal('plong', expand('<cword>'))
52 normal j
53 call assert_equal(9, getcurpos()[2])
54
55 normal 1G0
56 call assert_equal('plong', spellbadword()[0])
57 normal j
58 call assert_equal(9, getcurpos()[2])
59
60 bwipe!
61 set nospell
62endfunc
63
Bram Moolenaar5b276aa2017-04-22 23:49:52 +020064func Test_z_equal_on_invalid_utf8_word()
65 split
66 set spell
67 call setline(1, "\xff")
68 norm z=
69 set nospell
70 bwipe!
71endfunc
Bram Moolenaar545cb792017-05-23 11:31:22 +020072
Bram Moolenaar872e4512018-07-20 23:36:26 +020073" Test spellbadword() with argument
74func Test_spellbadword()
75 set spell
76
77 call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.'))
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +020078 call assert_equal(['another', 'caps'], 'A sentence. another sentence'->spellbadword())
Bram Moolenaar872e4512018-07-20 23:36:26 +020079
80 set spelllang=en
81 call assert_equal(['', ''], spellbadword('centre'))
82 call assert_equal(['', ''], spellbadword('center'))
83 set spelllang=en_us
84 call assert_equal(['centre', 'local'], spellbadword('centre'))
85 call assert_equal(['', ''], spellbadword('center'))
86 set spelllang=en_gb
87 call assert_equal(['', ''], spellbadword('centre'))
88 call assert_equal(['center', 'local'], spellbadword('center'))
89
90 " Create a small word list to test that spellbadword('...')
91 " can return ['...', 'rare'].
92 e Xwords
93 insert
94foo
95foobar/?
96.
97 w!
98 mkspell! Xwords.spl Xwords
99 set spelllang=Xwords.spl
100 call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))
101
102 " Typo should not be detected without the 'spell' option.
103 set spelllang=en_gb nospell
104 call assert_equal(['', ''], spellbadword('centre'))
105 call assert_equal(['', ''], spellbadword('My bycycle.'))
106 call assert_equal(['', ''], spellbadword('A sentence. another sentence'))
107
108 call delete('Xwords.spl')
109 call delete('Xwords')
110 set spelllang&
111 set spell&
112endfunc
113
Bram Moolenaar545cb792017-05-23 11:31:22 +0200114func Test_spellreall()
115 new
116 set spell
117 call assert_fails('spellrepall', 'E752:')
118 call setline(1, ['A speling mistake. The same speling mistake.',
Bram Moolenaard2c061d2017-06-22 21:42:49 +0200119 \ 'Another speling mistake.'])
Bram Moolenaar545cb792017-05-23 11:31:22 +0200120 call feedkeys(']s1z=', 'tx')
121 call assert_equal('A spelling mistake. The same speling mistake.', getline(1))
122 call assert_equal('Another speling mistake.', getline(2))
123 spellrepall
124 call assert_equal('A spelling mistake. The same spelling mistake.', getline(1))
125 call assert_equal('Another spelling mistake.', getline(2))
126 call assert_fails('spellrepall', 'E753:')
127 set spell&
128 bwipe!
129endfunc
Bram Moolenaard2c061d2017-06-22 21:42:49 +0200130
Bram Moolenaar9049b682018-08-31 22:26:53 +0200131func Test_spellinfo()
132 new
Bram Moolenaarc25e7022019-10-10 14:08:26 +0200133 let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
Bram Moolenaar9049b682018-08-31 22:26:53 +0200134
135 set enc=latin1 spell spelllang=en
Bram Moolenaarc25e7022019-10-10 14:08:26 +0200136 call assert_match("^\nfile: " .. runtime .. "/spell/en.latin1.spl\n$", execute('spellinfo'))
Bram Moolenaar9049b682018-08-31 22:26:53 +0200137
138 set enc=cp1250 spell spelllang=en
Bram Moolenaarc25e7022019-10-10 14:08:26 +0200139 call assert_match("^\nfile: " .. runtime .. "/spell/en.ascii.spl\n$", execute('spellinfo'))
Bram Moolenaar9049b682018-08-31 22:26:53 +0200140
Bram Moolenaar30276f22019-01-24 17:59:39 +0100141 set enc=utf-8 spell spelllang=en
Bram Moolenaarc25e7022019-10-10 14:08:26 +0200142 call assert_match("^\nfile: " .. runtime .. "/spell/en.utf-8.spl\n$", execute('spellinfo'))
Bram Moolenaar9049b682018-08-31 22:26:53 +0200143
144 set enc=latin1 spell spelllang=en_us,en_nz
145 call assert_match("^\n" .
Bram Moolenaarc25e7022019-10-10 14:08:26 +0200146 \ "file: " .. runtime .. "/spell/en.latin1.spl\n" .
147 \ "file: " .. runtime.. "/spell/en.latin1.spl\n$", execute('spellinfo'))
Bram Moolenaar9049b682018-08-31 22:26:53 +0200148
149 set spell spelllang=
150 call assert_fails('spellinfo', 'E756:')
151
152 set nospell spelllang=en
153 call assert_fails('spellinfo', 'E756:')
154
Bram Moolenaar8f130ed2019-04-10 22:15:19 +0200155 call assert_fails('set spelllang=foo/bar', 'E474:')
156 call assert_fails('set spelllang=foo\ bar', 'E474:')
157 call assert_fails("set spelllang=foo\\\nbar", 'E474:')
158 call assert_fails("set spelllang=foo\\\rbar", 'E474:')
159 call assert_fails("set spelllang=foo+bar", 'E474:')
160
Bram Moolenaar9049b682018-08-31 22:26:53 +0200161 set enc& spell& spelllang&
162 bwipe
163endfunc
164
Bram Moolenaard2c061d2017-06-22 21:42:49 +0200165func Test_zz_basic()
166 call LoadAffAndDic(g:test_data_aff1, g:test_data_dic1)
167 call RunGoodBad("wrong OK puts. Test the end",
168 \ "bad: inputs comment ok Ok. test d\xE9\xF4l end the",
169 \["Comment", "deol", "d\xE9\xF4r", "input", "OK", "output", "outputs", "outtest", "put", "puts",
170 \ "test", "testen", "testn", "the end", "uk", "wrong"],
171 \[
172 \ ["bad", ["put", "uk", "OK"]],
173 \ ["inputs", ["input", "puts", "outputs"]],
174 \ ["comment", ["Comment", "outtest", "the end"]],
175 \ ["ok", ["OK", "uk", "put"]],
176 \ ["Ok", ["OK", "Uk", "Put"]],
177 \ ["test", ["Test", "testn", "testen"]],
178 \ ["d\xE9\xF4l", ["deol", "d\xE9\xF4r", "test"]],
179 \ ["end", ["put", "uk", "test"]],
180 \ ["the", ["put", "uk", "test"]],
181 \ ]
182 \ )
183
184 call assert_equal("gebletegek", soundfold('goobledygoook'))
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +0200185 call assert_equal("kepereneven", 'kóopërÿnôven'->soundfold())
Bram Moolenaard2c061d2017-06-22 21:42:49 +0200186 call assert_equal("everles gesvets etele", soundfold('oeverloos gezwets edale'))
187endfunc
188
189" Postponed prefixes
190func Test_zz_prefixes()
191 call LoadAffAndDic(g:test_data_aff2, g:test_data_dic1)
192 call RunGoodBad("puts",
193 \ "bad: inputs comment ok Ok end the. test d\xE9\xF4l",
194 \ ["Comment", "deol", "d\xE9\xF4r", "OK", "put", "input", "output", "puts", "outputs", "test", "outtest", "testen", "testn", "the end", "uk", "wrong"],
195 \ [
196 \ ["bad", ["put", "uk", "OK"]],
197 \ ["inputs", ["input", "puts", "outputs"]],
198 \ ["comment", ["Comment"]],
199 \ ["ok", ["OK", "uk", "put"]],
200 \ ["Ok", ["OK", "Uk", "Put"]],
201 \ ["end", ["put", "uk", "deol"]],
202 \ ["the", ["put", "uk", "test"]],
203 \ ["test", ["Test", "testn", "testen"]],
204 \ ["d\xE9\xF4l", ["deol", "d\xE9\xF4r", "test"]],
205 \ ])
206endfunc
207
208"Compound words
209func Test_zz_compound()
210 call LoadAffAndDic(g:test_data_aff3, g:test_data_dic3)
211 call RunGoodBad("foo m\xEF foobar foofoobar barfoo barbarfoo",
212 \ "bad: bar la foom\xEF barm\xEF m\xEFfoo m\xEFbar m\xEFm\xEF lala m\xEFla lam\xEF foola labar",
213 \ ["foo", "m\xEF"],
214 \ [
215 \ ["bad", ["foo", "m\xEF"]],
216 \ ["bar", ["barfoo", "foobar", "foo"]],
217 \ ["la", ["m\xEF", "foo"]],
218 \ ["foom\xEF", ["foo m\xEF", "foo", "foofoo"]],
219 \ ["barm\xEF", ["barfoo", "m\xEF", "barbar"]],
220 \ ["m\xEFfoo", ["m\xEF foo", "foo", "foofoo"]],
221 \ ["m\xEFbar", ["foobar", "barbar", "m\xEF"]],
222 \ ["m\xEFm\xEF", ["m\xEF m\xEF", "m\xEF"]],
223 \ ["lala", []],
224 \ ["m\xEFla", ["m\xEF", "m\xEF m\xEF"]],
225 \ ["lam\xEF", ["m\xEF", "m\xEF m\xEF"]],
226 \ ["foola", ["foo", "foobar", "foofoo"]],
227 \ ["labar", ["barbar", "foobar"]],
228 \ ])
229
230 call LoadAffAndDic(g:test_data_aff4, g:test_data_dic4)
231 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",
232 \ "bad: wordutilize pro borkborkborkborkborkbork tomatotomatotomato endstart endend startstart wordend wordstart preborkprebork preborkpreborkbork startwordwordwordwordend borkpreborkpreborkbork utilsbork startnouword",
233 \ ["bork", "prebork", "end", "pro-ok", "start", "tomato", "util", "utilize", "utils", "word", "nouword"],
234 \ [
235 \ ["bad", ["end", "bork", "word"]],
236 \ ["wordutilize", ["word utilize", "wordutils", "wordutil"]],
237 \ ["pro", ["bork", "word", "end"]],
238 \ ["borkborkborkborkborkbork", ["bork borkborkborkborkbork", "borkbork borkborkborkbork", "borkborkbork borkborkbork"]],
239 \ ["tomatotomatotomato", ["tomato tomatotomato", "tomatotomato tomato", "tomato tomato tomato"]],
240 \ ["endstart", ["end start", "start"]],
241 \ ["endend", ["end end", "end"]],
242 \ ["startstart", ["start start"]],
243 \ ["wordend", ["word end", "word", "wordword"]],
244 \ ["wordstart", ["word start", "bork start"]],
245 \ ["preborkprebork", ["prebork prebork", "preborkbork", "preborkborkbork"]],
246 \ ["preborkpreborkbork", ["prebork preborkbork", "preborkborkbork", "preborkborkborkbork"]],
247 \ ["startwordwordwordwordend", ["startwordwordwordword end", "startwordwordwordword", "start wordwordwordword end"]],
248 \ ["borkpreborkpreborkbork", ["bork preborkpreborkbork", "bork prebork preborkbork", "bork preborkprebork bork"]],
249 \ ["utilsbork", ["utilbork", "utils bork", "util bork"]],
250 \ ["startnouword", ["start nouword", "startword", "startborkword"]],
251 \ ])
252
253endfunc
254
255"Test affix flags with two characters
256func Test_zz_affix()
257 call LoadAffAndDic(g:test_data_aff5, g:test_data_dic5)
258 call RunGoodBad("fooa1 fooa\xE9 bar prebar barbork prebarbork startprebar start end startend startmiddleend nouend",
259 \ "bad: foo fooa2 prabar probarbirk middle startmiddle middleend endstart startprobar startnouend",
260 \ ["bar", "barbork", "end", "fooa1", "fooa\xE9", "nouend", "prebar", "prebarbork", "start"],
261 \ [
262 \ ["bad", ["bar", "end", "fooa1"]],
263 \ ["foo", ["fooa1", "fooa\xE9", "bar"]],
264 \ ["fooa2", ["fooa1", "fooa\xE9", "bar"]],
265 \ ["prabar", ["prebar", "bar", "bar bar"]],
266 \ ["probarbirk", ["prebarbork"]],
267 \ ["middle", []],
268 \ ["startmiddle", ["startmiddleend", "startmiddlebar"]],
269 \ ["middleend", []],
270 \ ["endstart", ["end start", "start"]],
271 \ ["startprobar", ["startprebar", "start prebar", "startbar"]],
272 \ ["startnouend", ["start nouend", "startend"]],
273 \ ])
274
275 call LoadAffAndDic(g:test_data_aff6, g:test_data_dic6)
276 call RunGoodBad("meea1 meea\xE9 bar prebar barbork prebarbork leadprebar lead end leadend leadmiddleend",
277 \ "bad: mee meea2 prabar probarbirk middle leadmiddle middleend endlead leadprobar",
278 \ ["bar", "barbork", "end", "lead", "meea1", "meea\xE9", "prebar", "prebarbork"],
279 \ [
280 \ ["bad", ["bar", "end", "lead"]],
281 \ ["mee", ["meea1", "meea\xE9", "bar"]],
282 \ ["meea2", ["meea1", "meea\xE9", "lead"]],
283 \ ["prabar", ["prebar", "bar", "leadbar"]],
284 \ ["probarbirk", ["prebarbork"]],
285 \ ["middle", []],
286 \ ["leadmiddle", ["leadmiddleend", "leadmiddlebar"]],
287 \ ["middleend", []],
288 \ ["endlead", ["end lead", "lead", "end end"]],
289 \ ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]],
290 \ ])
291
292 call LoadAffAndDic(g:test_data_aff7, g:test_data_dic7)
293 call RunGoodBad("meea1 meea\xE9 bar prebar barmeat prebarmeat leadprebar lead tail leadtail leadmiddletail",
294 \ "bad: mee meea2 prabar probarmaat middle leadmiddle middletail taillead leadprobar",
295 \ ["bar", "barmeat", "lead", "meea1", "meea\xE9", "prebar", "prebarmeat", "tail"],
296 \ [
297 \ ["bad", ["bar", "lead", "tail"]],
298 \ ["mee", ["meea1", "meea\xE9", "bar"]],
299 \ ["meea2", ["meea1", "meea\xE9", "lead"]],
300 \ ["prabar", ["prebar", "bar", "leadbar"]],
301 \ ["probarmaat", ["prebarmeat"]],
302 \ ["middle", []],
303 \ ["leadmiddle", ["leadmiddlebar"]],
304 \ ["middletail", []],
305 \ ["taillead", ["tail lead", "tail"]],
306 \ ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]],
307 \ ])
308endfunc
309
310func Test_zz_NOSLITSUGS()
311 call LoadAffAndDic(g:test_data_aff8, g:test_data_dic8)
312 call RunGoodBad("foo bar faabar", "bad: foobar barfoo",
313 \ ["bar", "faabar", "foo"],
314 \ [
315 \ ["bad", ["bar", "foo"]],
316 \ ["foobar", ["faabar", "foo bar", "bar"]],
317 \ ["barfoo", ["bar foo", "bar", "foo"]],
318 \ ])
319endfunc
320
321" Numbers
322func Test_zz_Numbers()
323 call LoadAffAndDic(g:test_data_aff9, g:test_data_dic9)
324 call RunGoodBad("0b1011 0777 1234 0x01ff", "",
325 \ ["bar", "foo"],
326 \ [
327 \ ])
328endfunc
329
330function FirstSpellWord()
331 call feedkeys("/^start:\n", 'tx')
332 normal ]smm
333 let [str, a] = spellbadword()
334 return str
335endfunc
336
337function SecondSpellWord()
338 normal `m]s
339 let [str, a] = spellbadword()
340 return str
341endfunc
342
343"Test with SAL instead of SOFO items; test automatic reloading
344func Test_zz_sal_and_addition()
345 set enc=latin1
346 set spellfile=
Bram Moolenaar1a0f2002017-07-28 15:38:10 +0200347 call writefile(g:test_data_dic1, "Xtest.dic")
Bram Moolenaard2c061d2017-06-22 21:42:49 +0200348 call writefile(g:test_data_aff_sal, "Xtest.aff")
349 mkspell! Xtest Xtest
350 set spl=Xtest.latin1.spl spell
351 call assert_equal('kbltykk', soundfold('goobledygoook'))
352 call assert_equal('kprnfn', soundfold('kóopërÿnôven'))
353 call assert_equal('*fls kswts tl', soundfold('oeverloos gezwets edale'))
354
355 "also use an addition file
356 call writefile(["/regions=usgbnz", "elequint/2", "elekwint/3"], "Xtest.latin1.add")
357 mkspell! Xtest.latin1.add.spl Xtest.latin1.add
358
359 bwipe!
360 call setline(1, ["start: elequint test elekwint test elekwent asdf"])
361
362 set spellfile=Xtest.latin1.add
363 call assert_equal("elekwent", FirstSpellWord())
364
365 set spl=Xtest_us.latin1.spl
366 call assert_equal("elequint", FirstSpellWord())
367 call assert_equal("elekwint", SecondSpellWord())
368
369 set spl=Xtest_gb.latin1.spl
370 call assert_equal("elekwint", FirstSpellWord())
371 call assert_equal("elekwent", SecondSpellWord())
372
373 set spl=Xtest_nz.latin1.spl
374 call assert_equal("elequint", FirstSpellWord())
375 call assert_equal("elekwent", SecondSpellWord())
376
377 set spl=Xtest_ca.latin1.spl
378 call assert_equal("elequint", FirstSpellWord())
379 call assert_equal("elekwint", SecondSpellWord())
380endfunc
381
Bram Moolenaar862f1e12019-04-10 22:33:41 +0200382func Test_spellfile_value()
383 set spellfile=Xdir/Xtest.latin1.add
384 set spellfile=Xdir/Xtest.utf-8.add,Xtest_other.add
385endfunc
386
Bram Moolenaaree03b942017-10-27 00:57:05 +0200387func Test_region_error()
388 messages clear
389 call writefile(["/regions=usgbnz", "elequint/0"], "Xtest.latin1.add")
390 mkspell! Xtest.latin1.add.spl Xtest.latin1.add
391 call assert_match('Invalid region nr in Xtest.latin1.add line 2: 0', execute('messages'))
392 call delete('Xtest.latin1.add')
393 call delete('Xtest.latin1.add.spl')
394endfunc
395
Bram Moolenaard2c061d2017-06-22 21:42:49 +0200396" Check using z= in new buffer (crash fixed by patch 7.4a.028).
397func Test_zeq_crash()
398 new
399 set maxmem=512 spell
400 call feedkeys('iasdz=:\"', 'tx')
401
402 bwipe!
403endfunc
404
Bram Moolenaar5bcc5a12019-08-06 22:48:02 +0200405" Check handling a word longer than MAXWLEN.
406func Test_spell_long_word()
407 set enc=utf-8
408 new
409 call setline(1, "d\xCC\xB4\xCC\xBD\xCD\x88\xCD\x94a\xCC\xB5\xCD\x84\xCD\x84\xCC\xA8\xCD\x9Cr\xCC\xB5\xCC\x8E\xCD\x85\xCD\x85k\xCC\xB6\xCC\x89\xCC\x9D \xCC\xB6\xCC\x83\xCC\x8F\xCC\xA4\xCD\x8Ef\xCC\xB7\xCC\x81\xCC\x80\xCC\xA9\xCC\xB0\xCC\xAC\xCC\xA2\xCD\x95\xCD\x87\xCD\x8D\xCC\x9E\xCD\x99\xCC\xAD\xCC\xAB\xCC\x97\xCC\xBBo\xCC\xB6\xCC\x84\xCC\x95\xCC\x8C\xCC\x8B\xCD\x9B\xCD\x9C\xCC\xAFr\xCC\xB7\xCC\x94\xCD\x83\xCD\x97\xCC\x8C\xCC\x82\xCD\x82\xCD\x80\xCD\x91\xCC\x80\xCC\xBE\xCC\x82\xCC\x8F\xCC\xA3\xCD\x85\xCC\xAE\xCD\x8D\xCD\x99\xCC\xBC\xCC\xAB\xCC\xA7\xCD\x88c\xCC\xB7\xCD\x83\xCC\x84\xCD\x92\xCC\x86\xCC\x83\xCC\x88\xCC\x92\xCC\x94\xCC\xBE\xCC\x9D\xCC\xAF\xCC\x98\xCC\x9D\xCC\xBB\xCD\x8E\xCC\xBB\xCC\xB3\xCC\xA3\xCD\x8E\xCD\x99\xCC\xA5\xCC\xAD\xCC\x99\xCC\xB9\xCC\xAE\xCC\xA5\xCC\x9E\xCD\x88\xCC\xAE\xCC\x9E\xCC\xA9\xCC\x97\xCC\xBC\xCC\x99\xCC\xA5\xCD\x87\xCC\x97\xCD\x8E\xCD\x94\xCC\x99\xCC\x9D\xCC\x96\xCD\x94\xCC\xAB\xCC\xA7\xCC\xA5\xCC\x98\xCC\xBB\xCC\xAF\xCC\xABe\xCC\xB7\xCC\x8E\xCC\x82\xCD\x86\xCD\x9B\xCC\x94\xCD\x83\xCC\x85\xCD\x8A\xCD\x8C\xCC\x8B\xCD\x92\xCD\x91\xCC\x8F\xCC\x81\xCD\x95\xCC\xA2\xCC\xB9\xCC\xB2\xCD\x9C\xCC\xB1\xCC\xA6\xCC\xB3\xCC\xAF\xCC\xAE\xCC\x9C\xCD\x99s\xCC\xB8\xCC\x8C\xCC\x8E\xCC\x87\xCD\x81\xCD\x82\xCC\x86\xCD\x8C\xCD\x8C\xCC\x8B\xCC\x84\xCC\x8C\xCD\x84\xCD\x9B\xCD\x86\xCC\x93\xCD\x90\xCC\x85\xCC\x94\xCD\x98\xCD\x84\xCD\x92\xCD\x8B\xCC\x90\xCC\x83\xCC\x8F\xCD\x84\xCD\x81\xCD\x9B\xCC\x90\xCD\x81\xCC\x8F\xCC\xBD\xCC\x88\xCC\xBF\xCC\x88\xCC\x84\xCC\x8E\xCD\x99\xCD\x94\xCC\x99\xCD\x99\xCC\xB0\xCC\xA8\xCC\xA3\xCC\xA8\xCC\x96\xCC\x99\xCC\xAE\xCC\xBC\xCC\x99\xCD\x9A\xCC\xB2\xCC\xB1\xCC\x9F\xCC\xBB\xCC\xA6\xCD\x85\xCC\xAA\xCD\x89\xCC\x9D\xCC\x99\xCD\x96\xCC\xB1\xCC\xB1\xCC\x99\xCC\xA6\xCC\xA5\xCD\x95\xCC\xB2\xCC\xA0\xCD\x99 within")
410 set spell spelllang=en
411 redraw
412 redraw!
413 bwipe!
414 set nospell
415endfunc
416
Bram Moolenaard2c061d2017-06-22 21:42:49 +0200417func LoadAffAndDic(aff_contents, dic_contents)
418 set enc=latin1
419 set spellfile=
420 call writefile(a:aff_contents, "Xtest.aff")
421 call writefile(a:dic_contents, "Xtest.dic")
422 " Generate a .spl file from a .dic and .aff file.
423 mkspell! Xtest Xtest
424 " use that spell file
425 set spl=Xtest.latin1.spl spell
426endfunc
427
428func ListWords()
429 spelldump
430 %yank
431 quit
432 return split(@", "\n")
433endfunc
434
435func TestGoodBadBase()
436 exe '1;/^good:'
437 normal 0f:]s
438 let prevbad = ''
439 let result = []
440 while 1
441 let [bad, a] = spellbadword()
442 if bad == '' || bad == prevbad || bad == 'badend'
443 break
444 endif
445 let prevbad = bad
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +0200446 let lst = bad->spellsuggest(3)
Bram Moolenaard2c061d2017-06-22 21:42:49 +0200447 normal mm
448
449 call add(result, [bad, lst])
450 normal `m]s
451 endwhile
452 return result
453endfunc
454
455func RunGoodBad(good, bad, expected_words, expected_bad_words)
456 bwipe!
457 call setline(1, ["good: ", a:good, a:bad, " badend "])
458 let words = ListWords()
459 call assert_equal(a:expected_words, words[1:-1])
460 let bad_words = TestGoodBadBase()
461 call assert_equal(a:expected_bad_words, bad_words)
462 bwipe!
463endfunc
464
Bram Moolenaar7751d1d2019-10-18 20:37:08 +0200465func Test_spell_screendump()
466 CheckScreendump
467
468 let lines =<< trim END
469 call setline(1, [
470 \ "This is some text without any spell errors. Everything",
471 \ "should just be black, nothing wrong here.",
472 \ "",
473 \ "This line has a sepll error. and missing caps.",
474 \ "And and this is the the duplication.",
475 \ "with missing caps here.",
476 \ ])
477 set spell spelllang=en_nz
478 END
479 call writefile(lines, 'XtestSpell')
480 let buf = RunVimInTerminal('-S XtestSpell', {'rows': 8})
481 call VerifyScreenDump(buf, 'Test_spell_1', {})
482
483 " clean up
484 call StopVimInTerminal(buf)
485 call delete('XtestSpell')
486endfunc
487
Bram Moolenaard2c061d2017-06-22 21:42:49 +0200488let g:test_data_aff1 = [
489 \"SET ISO8859-1",
490 \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ",
491 \"",
492 \"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",
493 \"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",
494 \"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",
495 \"",
496 \"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",
497 \"SOFOTO ebctefghejklnnepkrstevvkesebctefghejklnnepkrstevvkeseeeeeeeceeeeeeeedneeeeeeeeeeepseeeeeeeeceeeeeeeedneeeeeeeeeeep?",
498 \"",
499 \"MIDWORD\t'-",
500 \"",
501 \"KEP =",
502 \"RAR ?",
503 \"BAD !",
504 \"",
505 \"PFX I N 1",
506 \"PFX I 0 in .",
507 \"",
508 \"PFX O Y 1",
509 \"PFX O 0 out .",
510 \"",
511 \"SFX S Y 2",
512 \"SFX S 0 s [^s]",
513 \"SFX S 0 es s",
514 \"",
515 \"SFX N N 3",
516 \"SFX N 0 en [^n]",
517 \"SFX N 0 nen n",
518 \"SFX N 0 n .",
519 \"",
520 \"REP 3",
521 \"REP g ch",
522 \"REP ch g",
523 \"REP svp s.v.p.",
524 \"",
525 \"MAP 9",
526 \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
527 \"MAP e\xE8\xE9\xEA\xEB",
528 \"MAP i\xEC\xED\xEE\xEF",
529 \"MAP o\xF2\xF3\xF4\xF5\xF6",
530 \"MAP u\xF9\xFA\xFB\xFC",
531 \"MAP n\xF1",
532 \"MAP c\xE7",
533 \"MAP y\xFF\xFD",
534 \"MAP s\xDF",
535 \ ]
536let g:test_data_dic1 = [
537 \"123456",
538 \"test/NO",
539 \"# comment",
540 \"wrong",
541 \"Comment",
542 \"OK",
543 \"uk",
544 \"put/ISO",
545 \"the end",
546 \"deol",
547 \"d\xE9\xF4r",
548 \ ]
549let g:test_data_aff2 = [
550 \"SET ISO8859-1",
551 \"",
552 \"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",
553 \"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",
554 \"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",
555 \"",
556 \"PFXPOSTPONE",
557 \"",
558 \"MIDWORD\t'-",
559 \"",
560 \"KEP =",
561 \"RAR ?",
562 \"BAD !",
563 \"",
564 \"PFX I N 1",
565 \"PFX I 0 in .",
566 \"",
567 \"PFX O Y 1",
568 \"PFX O 0 out [a-z]",
569 \"",
570 \"SFX S Y 2",
571 \"SFX S 0 s [^s]",
572 \"SFX S 0 es s",
573 \"",
574 \"SFX N N 3",
575 \"SFX N 0 en [^n]",
576 \"SFX N 0 nen n",
577 \"SFX N 0 n .",
578 \"",
579 \"REP 3",
580 \"REP g ch",
581 \"REP ch g",
582 \"REP svp s.v.p.",
583 \"",
584 \"MAP 9",
585 \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
586 \"MAP e\xE8\xE9\xEA\xEB",
587 \"MAP i\xEC\xED\xEE\xEF",
588 \"MAP o\xF2\xF3\xF4\xF5\xF6",
589 \"MAP u\xF9\xFA\xFB\xFC",
590 \"MAP n\xF1",
591 \"MAP c\xE7",
592 \"MAP y\xFF\xFD",
593 \"MAP s\xDF",
594 \ ]
595let g:test_data_aff3 = [
596 \"SET ISO8859-1",
597 \"",
598 \"COMPOUNDMIN 3",
599 \"COMPOUNDRULE m*",
600 \"NEEDCOMPOUND x",
601 \ ]
602let g:test_data_dic3 = [
603 \"1234",
604 \"foo/m",
605 \"bar/mx",
606 \"m\xEF/m",
607 \"la/mx",
608 \ ]
609let g:test_data_aff4 = [
610 \"SET ISO8859-1",
611 \"",
612 \"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",
613 \"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",
614 \"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",
615 \"",
616 \"COMPOUNDRULE m+",
617 \"COMPOUNDRULE sm*e",
618 \"COMPOUNDRULE sm+",
619 \"COMPOUNDMIN 3",
620 \"COMPOUNDWORDMAX 3",
621 \"COMPOUNDFORBIDFLAG t",
622 \"",
623 \"COMPOUNDSYLMAX 5",
624 \"SYLLABLE a\xE1e\xE9i\xEDo\xF3\xF6\xF5u\xFA\xFC\xFBy/aa/au/ea/ee/ei/ie/oa/oe/oo/ou/uu/ui",
625 \"",
626 \"MAP 9",
627 \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
628 \"MAP e\xE8\xE9\xEA\xEB",
629 \"MAP i\xEC\xED\xEE\xEF",
630 \"MAP o\xF2\xF3\xF4\xF5\xF6",
631 \"MAP u\xF9\xFA\xFB\xFC",
632 \"MAP n\xF1",
633 \"MAP c\xE7",
634 \"MAP y\xFF\xFD",
635 \"MAP s\xDF",
636 \"",
637 \"NEEDAFFIX x",
638 \"",
639 \"PFXPOSTPONE",
640 \"",
641 \"MIDWORD '-",
642 \"",
643 \"SFX q N 1",
644 \"SFX q 0 -ok .",
645 \"",
646 \"SFX a Y 2",
647 \"SFX a 0 s .",
648 \"SFX a 0 ize/t .",
649 \"",
650 \"PFX p N 1",
651 \"PFX p 0 pre .",
652 \"",
653 \"PFX P N 1",
654 \"PFX P 0 nou .",
655 \ ]
656let g:test_data_dic4 = [
657 \"1234",
658 \"word/mP",
659 \"util/am",
660 \"pro/xq",
661 \"tomato/m",
662 \"bork/mp",
663 \"start/s",
664 \"end/e",
665 \ ]
666let g:test_data_aff5 = [
667 \"SET ISO8859-1",
668 \"",
669 \"FLAG long",
670 \"",
671 \"NEEDAFFIX !!",
672 \"",
673 \"COMPOUNDRULE ssmm*ee",
674 \"",
675 \"NEEDCOMPOUND xx",
676 \"COMPOUNDPERMITFLAG pp",
677 \"",
678 \"SFX 13 Y 1",
679 \"SFX 13 0 bork .",
680 \"",
681 \"SFX a1 Y 1",
682 \"SFX a1 0 a1 .",
683 \"",
684 \"SFX a\xE9 Y 1",
685 \"SFX a\xE9 0 a\xE9 .",
686 \"",
687 \"PFX zz Y 1",
688 \"PFX zz 0 pre/pp .",
689 \"",
690 \"PFX yy Y 1",
691 \"PFX yy 0 nou .",
692 \ ]
693let g:test_data_dic5 = [
694 \"1234",
695 \"foo/a1a\xE9!!",
696 \"bar/zz13ee",
697 \"start/ss",
698 \"end/eeyy",
699 \"middle/mmxx",
700 \ ]
701let g:test_data_aff6 = [
702 \"SET ISO8859-1",
703 \"",
704 \"FLAG caplong",
705 \"",
706 \"NEEDAFFIX A!",
707 \"",
708 \"COMPOUNDRULE sMm*Ee",
709 \"",
710 \"NEEDCOMPOUND Xx",
711 \"",
712 \"COMPOUNDPERMITFLAG p",
713 \"",
714 \"SFX N3 Y 1",
715 \"SFX N3 0 bork .",
716 \"",
717 \"SFX A1 Y 1",
718 \"SFX A1 0 a1 .",
719 \"",
720 \"SFX A\xE9 Y 1",
721 \"SFX A\xE9 0 a\xE9 .",
722 \"",
723 \"PFX Zz Y 1",
724 \"PFX Zz 0 pre/p .",
725 \ ]
726let g:test_data_dic6 = [
727 \"1234",
728 \"mee/A1A\xE9A!",
729 \"bar/ZzN3Ee",
730 \"lead/s",
731 \"end/Ee",
732 \"middle/MmXx",
733 \ ]
734let g:test_data_aff7 = [
735 \"SET ISO8859-1",
736 \"",
737 \"FLAG num",
738 \"",
739 \"NEEDAFFIX 9999",
740 \"",
741 \"COMPOUNDRULE 2,77*123",
742 \"",
743 \"NEEDCOMPOUND 1",
744 \"COMPOUNDPERMITFLAG 432",
745 \"",
746 \"SFX 61003 Y 1",
747 \"SFX 61003 0 meat .",
748 \"",
749 \"SFX 391 Y 1",
750 \"SFX 391 0 a1 .",
751 \"",
752 \"SFX 111 Y 1",
753 \"SFX 111 0 a\xE9 .",
754 \"",
755 \"PFX 17 Y 1",
756 \"PFX 17 0 pre/432 .",
757 \ ]
758let g:test_data_dic7 = [
759 \"1234",
760 \"mee/391,111,9999",
761 \"bar/17,61003,123",
762 \"lead/2",
763 \"tail/123",
764 \"middle/77,1",
765 \ ]
766let g:test_data_aff8 = [
767 \"SET ISO8859-1",
768 \"",
769 \"NOSPLITSUGS",
770 \ ]
771let g:test_data_dic8 = [
772 \"1234",
773 \"foo",
774 \"bar",
775 \"faabar",
776 \ ]
777let g:test_data_aff9 = [
778 \ ]
779let g:test_data_dic9 = [
780 \"1234",
781 \"foo",
782 \"bar",
783 \ ]
784let g:test_data_aff_sal = [
785 \"SET ISO8859-1",
786 \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ",
787 \"",
788 \"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",
789 \"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",
790 \"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",
791 \"",
792 \"MIDWORD\t'-",
793 \"",
794 \"KEP =",
795 \"RAR ?",
796 \"BAD !",
797 \"",
798 \"PFX I N 1",
799 \"PFX I 0 in .",
800 \"",
801 \"PFX O Y 1",
802 \"PFX O 0 out .",
803 \"",
804 \"SFX S Y 2",
805 \"SFX S 0 s [^s]",
806 \"SFX S 0 es s",
807 \"",
808 \"SFX N N 3",
809 \"SFX N 0 en [^n]",
810 \"SFX N 0 nen n",
811 \"SFX N 0 n .",
812 \"",
813 \"REP 3",
814 \"REP g ch",
815 \"REP ch g",
816 \"REP svp s.v.p.",
817 \"",
818 \"MAP 9",
819 \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
820 \"MAP e\xE8\xE9\xEA\xEB",
821 \"MAP i\xEC\xED\xEE\xEF",
822 \"MAP o\xF2\xF3\xF4\xF5\xF6",
823 \"MAP u\xF9\xFA\xFB\xFC",
824 \"MAP n\xF1",
825 \"MAP c\xE7",
826 \"MAP y\xFF\xFD",
827 \"MAP s\xDF",
828 \"",
829 \"SAL AH(AEIOUY)-^ *H",
830 \"SAL AR(AEIOUY)-^ *R",
831 \"SAL A(HR)^ *",
832 \"SAL A^ *",
833 \"SAL AH(AEIOUY)- H",
834 \"SAL AR(AEIOUY)- R",
835 \"SAL A(HR) _",
836 \"SAL \xC0^ *",
837 \"SAL \xC5^ *",
838 \"SAL BB- _",
839 \"SAL B B",
840 \"SAL CQ- _",
841 \"SAL CIA X",
842 \"SAL CH X",
843 \"SAL C(EIY)- S",
844 \"SAL CK K",
845 \"SAL COUGH^ KF",
846 \"SAL CC< C",
847 \"SAL C K",
848 \"SAL DG(EIY) K",
849 \"SAL DD- _",
850 \"SAL D T",
851 \"SAL \xC9< E",
852 \"SAL EH(AEIOUY)-^ *H",
853 \"SAL ER(AEIOUY)-^ *R",
854 \"SAL E(HR)^ *",
855 \"SAL ENOUGH^$ *NF",
856 \"SAL E^ *",
857 \"SAL EH(AEIOUY)- H",
858 \"SAL ER(AEIOUY)- R",
859 \"SAL E(HR) _",
860 \"SAL FF- _",
861 \"SAL F F",
862 \"SAL GN^ N",
863 \"SAL GN$ N",
864 \"SAL GNS$ NS",
865 \"SAL GNED$ N",
866 \"SAL GH(AEIOUY)- K",
867 \"SAL GH _",
868 \"SAL GG9 K",
869 \"SAL G K",
870 \"SAL H H",
871 \"SAL IH(AEIOUY)-^ *H",
872 \"SAL IR(AEIOUY)-^ *R",
873 \"SAL I(HR)^ *",
874 \"SAL I^ *",
875 \"SAL ING6 N",
876 \"SAL IH(AEIOUY)- H",
877 \"SAL IR(AEIOUY)- R",
878 \"SAL I(HR) _",
879 \"SAL J K",
880 \"SAL KN^ N",
881 \"SAL KK- _",
882 \"SAL K K",
883 \"SAL LAUGH^ LF",
884 \"SAL LL- _",
885 \"SAL L L",
886 \"SAL MB$ M",
887 \"SAL MM M",
888 \"SAL M M",
889 \"SAL NN- _",
890 \"SAL N N",
891 \"SAL OH(AEIOUY)-^ *H",
892 \"SAL OR(AEIOUY)-^ *R",
893 \"SAL O(HR)^ *",
894 \"SAL O^ *",
895 \"SAL OH(AEIOUY)- H",
896 \"SAL OR(AEIOUY)- R",
897 \"SAL O(HR) _",
898 \"SAL PH F",
899 \"SAL PN^ N",
900 \"SAL PP- _",
901 \"SAL P P",
902 \"SAL Q K",
903 \"SAL RH^ R",
904 \"SAL ROUGH^ RF",
905 \"SAL RR- _",
906 \"SAL R R",
907 \"SAL SCH(EOU)- SK",
908 \"SAL SC(IEY)- S",
909 \"SAL SH X",
910 \"SAL SI(AO)- X",
911 \"SAL SS- _",
912 \"SAL S S",
913 \"SAL TI(AO)- X",
914 \"SAL TH @",
915 \"SAL TCH-- _",
916 \"SAL TOUGH^ TF",
917 \"SAL TT- _",
918 \"SAL T T",
919 \"SAL UH(AEIOUY)-^ *H",
920 \"SAL UR(AEIOUY)-^ *R",
921 \"SAL U(HR)^ *",
922 \"SAL U^ *",
923 \"SAL UH(AEIOUY)- H",
924 \"SAL UR(AEIOUY)- R",
925 \"SAL U(HR) _",
926 \"SAL V^ W",
927 \"SAL V F",
928 \"SAL WR^ R",
929 \"SAL WH^ W",
930 \"SAL W(AEIOU)- W",
931 \"SAL X^ S",
932 \"SAL X KS",
933 \"SAL Y(AEIOU)- Y",
934 \"SAL ZZ- _",
935 \"SAL Z S",
936 \ ]