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