robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:9.2.0987: heap-buffer-overflow in spell_suggest() (#41406)eaff5417be

master
50.8 KiB1643 linesraw
1" Test spell checking
2" Note: this file uses latin1 encoding, but is used with utf-8 encoding.
3
4source check.vim
5CheckFeature spell
6
7source screendump.vim
8source view_util.vim
9
10func TearDown()
11  set nospell
12  call delete('Xtest.aff')
13  call delete('Xtest.dic')
14  call delete('Xtest.latin1.add')
15  call delete('Xtest.latin1.add.spl')
16  call delete('Xtest.latin1.spl')
17  call delete('Xtest.latin1.sug')
18  " set 'encoding' to clear the word list
19  set encoding=utf-8
20endfunc
21
22func Test_wrap_search()
23  new
24  call setline(1, ['The', '', 'A plong line with two zpelling mistakes', '', 'End'])
25  set spell wrapscan
26  normal ]s
27  call assert_equal('plong', expand('<cword>'))
28  normal ]s
29  call assert_equal('zpelling', expand('<cword>'))
30  normal ]s
31  call assert_equal('plong', expand('<cword>'))
32  bwipe!
33  set nospell
34endfunc
35
36func Test_curswant()
37  new
38  call setline(1, ['Another plong line', 'abcdefghijklmnopq'])
39  set spell wrapscan
40  normal 0]s
41  call assert_equal('plong', expand('<cword>'))
42  normal j
43  call assert_equal(9, getcurpos()[2])
44  normal 0[s
45  call assert_equal('plong', expand('<cword>'))
46  normal j
47  call assert_equal(9, getcurpos()[2])
48
49  normal 0]S
50  call assert_equal('plong', expand('<cword>'))
51  normal j
52  call assert_equal(9, getcurpos()[2])
53  normal 0[S
54  call assert_equal('plong', expand('<cword>'))
55  normal j
56  call assert_equal(9, getcurpos()[2])
57
58  normal 1G0
59  call assert_equal('plong', spellbadword()[0])
60  normal j
61  call assert_equal(9, getcurpos()[2])
62
63  bwipe!
64  set nospell
65endfunc
66
67func Test_z_equal_on_invalid_utf8_word()
68  split
69  set spell
70  call setline(1, "\xff")
71  norm z=
72  set nospell
73  bwipe!
74endfunc
75
76func Test_z_equal_on_single_character()
77  " this was decrementing the index below zero
78  new
79  norm a0\�
80  norm zW
81  norm z=
82
83  bwipe!
84endfunc
85
86" Test spellbadword() with argument
87func Test_spellbadword()
88  set spell
89
90  call assert_equal(['bycycle', 'bad'],  spellbadword('My bycycle.'))
91  call assert_equal(['another', 'caps'], 'A sentence. another sentence'->spellbadword())
92
93  call assert_equal(['TheCamelWord', 'bad'], spellbadword('TheCamelWord asdf'))
94  set spelloptions=camel
95  call assert_equal(['asdf', 'bad'], spellbadword('TheCamelWord asdf'))
96  set spelloptions=
97
98  set spelllang=en
99  call assert_equal(['', ''],            spellbadword('centre'))
100  call assert_equal(['', ''],            spellbadword('center'))
101  set spelllang=en_us
102  call assert_equal(['centre', 'local'], spellbadword('centre'))
103  call assert_equal(['', ''],            spellbadword('center'))
104  set spelllang=en_gb
105  call assert_equal(['', ''],            spellbadword('centre'))
106  call assert_equal(['center', 'local'], spellbadword('center'))
107
108  " Create a small word list to test that spellbadword('...')
109  " can return ['...', 'rare'].
110  e Xwords
111  insert
112foo
113foobar/?
114.
115   w!
116   mkspell! Xwords.spl Xwords
117   set spelllang=Xwords.spl
118   call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))
119
120  " Typo should be detected even without the 'spell' option.
121  set spelllang=en_gb nospell
122  call assert_equal(['', ''], spellbadword('centre'))
123  call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.'))
124  call assert_equal(['another', 'caps'], spellbadword('A sentence. another sentence'))
125
126  set spelllang=
127  call assert_fails("call spellbadword('maxch')", 'E756:')
128  call assert_fails("spelldump", 'E756:')
129
130  call delete('Xwords.spl')
131  call delete('Xwords')
132  set spelllang&
133  set spell&
134endfunc
135
136func Test_spell_camelcase()
137  set spell spelloptions=camel
138  let words = [
139      \ 'UPPER',
140      \ 'lower',
141      \ 'mixedCase',
142      \ 'HTML',
143      \ 'XMLHttpRequest',
144      \ 'foo123bar',
145      \ '12345678',
146      \ 'HELLO123world',
147      \]
148
149  for word in words
150    call assert_equal(['', ''],  spellbadword(word))
151  endfor
152
153  set spell& spelloptions&
154endfunc
155
156func Test_spell_file_missing()
157  let s:spell_file_missing = 0
158  augroup TestSpellFileMissing
159    autocmd! SpellFileMissing * let s:spell_file_missing += 1
160  augroup END
161
162  set spell spelllang=ab_cd
163  let messages = GetMessages()
164  " This message is not shown in Nvim because of #3027
165  " call assert_equal('Warning: Cannot find word list "ab.utf-8.spl" or "ab.ascii.spl"', messages[-1])
166  call assert_equal(1, s:spell_file_missing)
167
168  new XTestSpellFileMissing
169  augroup TestSpellFileMissing
170    autocmd! SpellFileMissing * bwipe
171  augroup END
172  call assert_fails('set spell spelllang=ab_cd', 'E937:')
173
174  " clean up
175  augroup TestSpellFileMissing
176    autocmd! SpellFileMissing
177  augroup END
178  augroup! TestSpellFileMissing
179  unlet s:spell_file_missing
180  set spell& spelllang&
181  %bwipe!
182endfunc
183
184func Test_spell_file_missing_bwipe()
185  " this was using a window that was wiped out in a SpellFileMissing autocmd
186  set spelllang=xy
187  au SpellFileMissing * n0
188  set spell
189  au SpellFileMissing * bw
190  snext somefile
191
192  au! SpellFileMissing
193  bwipe!
194  set nospell spelllang=en
195endfunc
196
197func Test_spelldump()
198  " In case the spell file is not found avoid getting the download dialog, we
199  " would get stuck at the prompt.
200  let g:en_not_found = 0
201  augroup TestSpellFileMissing
202    au! SpellFileMissing * let g:en_not_found = 1
203  augroup END
204  set spell spelllang=en
205  spellrare! emacs
206  if g:en_not_found
207    call assert_report("Could not find English spell file")
208  else
209    spelldump
210
211    " Check assumption about region: 1: us, 2: au, 3: ca, 4: gb, 5: nz.
212    call assert_equal('/regions=usaucagbnz', getline(1))
213    call assert_notequal(0, search('^theater/1$'))    " US English only.
214    call assert_notequal(0, search('^theatre/2345$')) " AU, CA, GB or NZ English.
215
216    call assert_notequal(0, search('^emacs/?$'))      " ? for a rare word.
217    call assert_notequal(0, search('^the the/!$'))    " ! for a wrong word.
218  endif
219
220  " clean up
221  unlet g:en_not_found
222  augroup TestSpellFileMissing
223    autocmd! SpellFileMissing
224  augroup END
225  augroup! TestSpellFileMissing
226  bwipe
227  set spell&
228endfunc
229
230func Test_spelldump_bang()
231  new
232  call setline(1, 'This is a sample sentence.')
233  redraw
234
235  " In case the spell file is not found avoid getting the download dialog, we
236  " would get stuck at the prompt.
237  let g:en_not_found = 0
238  augroup TestSpellFileMissing
239    au! SpellFileMissing * let g:en_not_found = 1
240  augroup END
241
242  set spell
243
244  if g:en_not_found
245    call assert_report("Could not find English spell file")
246  else
247    redraw
248    spelldump!
249
250    " :spelldump! includes the number of times a word was found while updating
251    " the screen.
252    " Common word count starts at 10, regular word count starts at 0.
253    call assert_notequal(0, search("^is\t11$"))    " common word found once.
254    call assert_notequal(0, search("^the\t10$"))   " common word never found.
255    call assert_notequal(0, search("^sample\t1$")) " regular word found once.
256    call assert_equal(0, search("^screen\t"))      " regular word never found.
257  endif
258
259  " clean up
260  unlet g:en_not_found
261  augroup TestSpellFileMissing
262    autocmd! SpellFileMissing
263  augroup END
264  augroup! TestSpellFileMissing
265  %bwipe!
266  set spell&
267endfunc
268
269func Test_spelllang_inv_region()
270  set spell spelllang=en_xx
271  let messages = GetMessages()
272  call assert_equal('Warning: region xx not supported', messages[-1])
273  set spell& spelllang&
274endfunc
275
276func Test_compl_with_CTRL_X_CTRL_K_using_spell()
277  " When spell checking is enabled and 'dictionary' is empty,
278  " CTRL-X CTRL-K in insert mode completes using the spelling dictionary.
279  new
280  set spell spelllang=en dictionary=
281
282  set ignorecase
283  call feedkeys("Senglis\<c-x>\<c-k>\<esc>", 'tnx')
284  call assert_equal(['English'], getline(1, '$'))
285  call feedkeys("SEnglis\<c-x>\<c-k>\<esc>", 'tnx')
286  call assert_equal(['English'], getline(1, '$'))
287
288  set noignorecase
289  call feedkeys("Senglis\<c-x>\<c-k>\<esc>", 'tnx')
290  call assert_equal(['englis'], getline(1, '$'))
291  call feedkeys("SEnglis\<c-x>\<c-k>\<esc>", 'tnx')
292  call assert_equal(['English'], getline(1, '$'))
293
294  set spelllang=en_us
295  call feedkeys("Stheat\<c-x>\<c-k>\<esc>", 'tnx')
296  call assert_equal(['theater'], getline(1, '$'))
297  set spelllang=en_gb
298  call feedkeys("Stheat\<c-x>\<c-k>\<esc>", 'tnx')
299  call assert_equal(['theatre'], getline(1, '$'))
300
301  bwipe!
302  set spell& spelllang& dictionary& ignorecase&
303endfunc
304
305func Test_compl_with_CTRL_X_s()
306  new
307  set spell spelllang=en_us showmode
308  inoremap <buffer><F2> <Cmd>let g:msg = Screenline(&lines)<CR>
309
310  call feedkeys("STheatre\<C-X>s\<F2>\<C-Y>\<Esc>", 'tx')
311  call assert_equal(['Theater'], getline(1, '$'))
312  call assert_match('(^S^N^P)', g:msg)
313
314  bwipe!
315  set spell& spelllang& showmode&
316  unlet g:msg
317endfunc
318
319func Test_spellrepall()
320  new
321  set spell
322  call assert_fails('spellrepall', 'E752:')
323  call setline(1, ['A speling mistake. The same speling mistake.',
324        \                'Another speling mistake.'])
325  call feedkeys(']s1z=', 'tx')
326  call assert_equal('A spelling mistake. The same speling mistake.', getline(1))
327  call assert_equal('Another speling mistake.', getline(2))
328  spellrepall
329  call assert_equal('A spelling mistake. The same spelling mistake.', getline(1))
330  call assert_equal('Another spelling mistake.', getline(2))
331  call assert_fails('spellrepall', 'E753:')
332  set spell&
333  bwipe!
334endfunc
335
336func Test_spell_dump_word_length()
337  " this was running over MAXWLEN
338  new
339  noremap 0 0a0zW0000000
340  sil! norm 0z=0
341  sil norm 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
342  sil! norm 0z=0
343
344  bwipe!
345  nunmap 0
346endfunc
347
348" Test spellsuggest({word} [, {max} [, {capital}]])
349func Test_spellsuggest()
350  " Verify suggestions are given even when spell checking is not enabled.
351  set nospell
352  call assert_equal(['march', 'March'], spellsuggest('marrch', 2))
353
354  set spell
355
356  " With 1 argument.
357  call assert_equal(['march', 'March'], spellsuggest('marrch')[0:1])
358
359  " With 2 arguments.
360  call assert_equal(['march', 'March'], spellsuggest('marrch', 2))
361
362  " With 3 arguments.
363  call assert_equal(['march'], spellsuggest('marrch', 1, 0))
364  call assert_equal(['March'], spellsuggest('marrch', 1, 1))
365
366  " Test with digits and hyphen.
367  call assert_equal('Carbon-14', spellsuggest('Carbon-15')[0])
368
369  " Comment taken from spellsuggest.c explains the following test cases:
370  "
371  " If there are more UPPER than lower case letters suggest an
372  " ALLCAP word.  Otherwise, if the first letter is UPPER then
373  " suggest ONECAP.  Exception: "ALl" most likely should be "All",
374  " require three upper case letters.
375  call assert_equal(['THIRD', 'third'], spellsuggest('thIRD', 2))
376  call assert_equal(['third', 'THIRD'], spellsuggest('tHIrd', 2))
377  call assert_equal(['Third'], spellsuggest('THird', 1))
378  call assert_equal(['All'],      spellsuggest('ALl', 1))
379
380  " Special suggestion for repeated 'the the'.
381  call assert_inrange(0, 2, index(spellsuggest('the the',   3), 'the'))
382  call assert_inrange(0, 2, index(spellsuggest('the   the', 3), 'the'))
383  call assert_inrange(0, 2, index(spellsuggest('The the',   3), 'The'))
384
385  call assert_fails("call spellsuggest('maxch', [])", 'E745:')
386  call assert_fails("call spellsuggest('maxch', 2, [])", 'E745:')
387
388  set spelllang=
389  call assert_fails("call spellsuggest('maxch')", 'E756:')
390  set spelllang&
391
392  set spell&
393endfunc
394
395" Test 'spellsuggest' option with methods fast, best and double.
396func Test_spellsuggest_option_methods()
397  set spell
398
399  for e in ['utf-8']
400    exe 'set encoding=' .. e
401
402    set spellsuggest=fast
403    call assert_equal(['Stick', 'Stitch'], spellsuggest('Stich', 2), e)
404
405    " With best or double option, "Stitch" should become the top suggestion
406    " because of better phonetic matching.
407    set spellsuggest=best
408    call assert_equal(['Stitch', 'Stick'], spellsuggest('Stich', 2), e)
409
410    set spellsuggest=double
411    call assert_equal(['Stitch', 'Stick'], spellsuggest('Stich', 2), e)
412  endfor
413
414  set spell& spellsuggest& encoding&
415endfunc
416
417" Test 'spellsuggest' option with value file:{filename}
418func Test_spellsuggest_option_file()
419  set spell spellsuggest=file:Xspellsuggest
420  call writefile(['emacs/vim',
421        \         'theribal/terrible',
422        \         'teribal/terrrible',
423        \         'terribal'],
424        \         'Xspellsuggest')
425
426  call assert_equal(['vim'],      spellsuggest('emacs', 2))
427  call assert_equal(['terrible'], spellsuggest('theribal',2))
428
429  " If the suggestion is misspelled (*terrrible* with 3 r),
430  " it should not be proposed.
431  " The entry for "terribal" should be ignored because of missing slash.
432  call assert_equal([], spellsuggest('teribal', 2))
433  call assert_equal([], spellsuggest('terribal', 2))
434
435  set spell spellsuggest=best,file:Xspellsuggest
436  call assert_equal(['vim', 'Emacs'],       spellsuggest('emacs', 2))
437  call assert_equal(['terrible', 'tribal'], spellsuggest('theribal', 2))
438  call assert_equal(['tribal'],             spellsuggest('teribal', 1))
439  call assert_equal(['tribal'],             spellsuggest('terribal', 1))
440
441  call delete('Xspellsuggest')
442  call assert_fails("call spellsuggest('vim')", "E484: Can't open file Xspellsuggest")
443
444  set spellsuggest& spell&
445endfunc
446
447" Test 'spellsuggest' option with value {number}
448" to limit the number of suggestions
449func Test_spellsuggest_option_number()
450  set spell spellsuggest=2,best
451  new
452
453  " We limited the number of suggestions to 2, so selecting
454  " the 1st and 2nd suggestion should correct the word, but
455  " selecting a 3rd suggestion should do nothing.
456  call setline(1, 'A baord')
457  norm $1z=
458  call assert_equal('A board', getline(1))
459
460  call setline(1, 'A baord')
461  norm $2z=
462  call assert_equal('A bard', getline(1))
463
464  call setline(1, 'A baord')
465  norm $3z=
466  call assert_equal('A baord', getline(1))
467
468  let a = execute('norm $z=')
469  " Nvim: z= goes through vim.ui.select().
470  call assert_equal(
471  \    "\n"
472  \ .. "Change \"baord\" to:\n"
473  \ .. "1: \"board\"\n"
474  \ .. "2: \"bard\"\n"
475  \ , a)
476
477  set spell spellsuggest=0
478  call assert_equal("\nNo suggestions", execute('norm $z='))
479
480  " Unlike z=, function spellsuggest(...) should not be affected by the
481  " max number of suggestions (2) set by the 'spellsuggest' option.
482  call assert_equal(['board', 'bard', 'broad'], spellsuggest('baord', 3))
483
484  set spellsuggest& spell&
485  bwipe!
486endfunc
487
488" Test 'spellsuggest' option with value expr:{expr}
489func Test_spellsuggest_option_expr()
490  " A silly 'spellsuggest' function which makes suggestions all uppercase
491  " and makes the score of each suggestion the length of the suggested word.
492  " So shorter suggestions are preferred.
493  func MySuggest()
494    let spellsuggest_save = &spellsuggest
495    set spellsuggest=3,best
496    let result = map(spellsuggest(v:val, 3), "[toupper(v:val), len(v:val)]")
497    let &spellsuggest = spellsuggest_save
498    return result
499  endfunc
500
501  set spell spellsuggest=expr:MySuggest()
502  call assert_equal(['BARD', 'BOARD', 'BROAD'], spellsuggest('baord', 3))
503
504  new
505  call setline(1, 'baord')
506  let a = execute('norm z=')
507  " Nvim: z= goes through vim.ui.select().
508  call assert_equal(
509  \    "\n"
510  \ .. "Change \"baord\" to:\n"
511  \ .. "1: \"BARD\"\n"
512  \ .. "2: \"BOARD\"\n"
513  \ .. "3: \"BROAD\"\n"
514  \ , a)
515
516  " With verbose, z= should show the score i.e. word length with
517  " our SpellSuggest() function.
518  set verbose=1
519  let a = execute('norm z=')
520  call assert_equal(
521  \    "\n"
522  \ .. "Change \"baord\" to:\n"
523  \ .. "1: \"BARD\" (4 - 0)\n"
524  \ .. "2: \"BOARD\" (5 - 0)\n"
525  \ .. "3: \"BROAD\" (5 - 0)\n"
526  \ , a)
527
528  set spell& spellsuggest& verbose&
529  bwipe!
530endfunc
531
532" Test for 'spellsuggest' expr errors
533func Test_spellsuggest_expr_errors()
534  " 'spellsuggest'
535  func MySuggest()
536    return range(3)
537  endfunc
538  set spell spellsuggest=expr:MySuggest()
539  call assert_equal([], spellsuggest('baord', 3))
540
541  " Test for 'spellsuggest' expression returning a non-list value
542  func! MySuggest2()
543    return 'good'
544  endfunc
545  set spellsuggest=expr:MySuggest2()
546  call assert_equal([], spellsuggest('baord'))
547
548  " Test for 'spellsuggest' expression returning a list with dict values
549  func! MySuggest3()
550    return [[{}, {}]]
551  endfunc
552  set spellsuggest=expr:MySuggest3()
553  call assert_fails("call spellsuggest('baord')", 'E731:')
554
555  set nospell spellsuggest&
556  delfunc MySuggest
557  delfunc MySuggest2
558  delfunc MySuggest3
559endfunc
560
561func Test_spellsuggest_timeout()
562  set spellsuggest=timeout:30
563  set spellsuggest=timeout:-123
564  set spellsuggest=timeout:999999
565  call assert_fails('set spellsuggest=timeout', 'E474:')
566  call assert_fails('set spellsuggest=timeout:x', 'E474:')
567  call assert_fails('set spellsuggest=timeout:-x', 'E474:')
568  call assert_fails('set spellsuggest=timeout:--9', 'E474:')
569endfunc
570
571func Test_spellsuggest_visual_end_of_line()
572  let enc_save = &encoding
573  " set encoding=iso8859
574
575  " This was reading beyond the end of the line.
576  norm R00000000000
577  sil norm 0
578  sil! norm i00000)
579  sil! norm i00000)
580  call feedkeys("\<CR>")
581  norm z=
582
583  let &encoding = enc_save
584endfunc
585
586func Test_spellinfo()
587  throw 'Skipped: Nvim does not support enc=latin1'
588  new
589  let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
590
591  set enc=latin1 spell spelllang=en
592  call assert_match("^\nfile: " .. runtime .. "/spell/en.latin1.spl\n$", execute('spellinfo'))
593
594  set enc=cp1250 spell spelllang=en
595  call assert_match("^\nfile: " .. runtime .. "/spell/en.ascii.spl\n$", execute('spellinfo'))
596
597  set enc=utf-8 spell spelllang=en
598  call assert_match("^\nfile: " .. runtime .. "/spell/en.utf-8.spl\n$", execute('spellinfo'))
599
600  set enc=latin1 spell spelllang=en_us,en_nz
601  call assert_match("^\n" .
602                 \  "file: " .. runtime .. "/spell/en.latin1.spl\n" .
603                 \  "file: " .. runtime .. "/spell/en.latin1.spl\n$", execute('spellinfo'))
604
605  set spell spelllang=
606  call assert_fails('spellinfo', 'E756:')
607
608  set nospell spelllang=en
609  call assert_fails('spellinfo', 'E756:')
610
611  call assert_fails('set spelllang=foo/bar', 'E474:')
612  call assert_fails('set spelllang=foo\ bar', 'E474:')
613  call assert_fails("set spelllang=foo\\\nbar", 'E474:')
614  call assert_fails("set spelllang=foo\\\rbar", 'E474:')
615  call assert_fails("set spelllang=foo+bar", 'E474:')
616
617  set enc& spell& spelllang&
618  bwipe
619endfunc
620
621func Test_zz_basic()
622  call LoadAffAndDic(g:test_data_aff1, g:test_data_dic1)
623  call RunGoodBad("wrong OK puts. Test the end",
624        \ "bad: inputs comment ok Ok. test d\xE9\xF4l end the",
625        \["Comment", "deol", "d\xE9\xF4r", "input", "OK", "output", "outputs", "outtest", "put", "puts",
626        \  "test", "testen", "testn", "the end", "uk", "wrong"],
627        \[
628        \   ["bad", ["put", "uk", "OK"]],
629        \   ["inputs", ["input", "puts", "outputs"]],
630        \   ["comment", ["Comment", "outtest", "the end"]],
631        \   ["ok", ["OK", "uk", "put"]],
632        \   ["Ok", ["OK", "Uk", "Put"]],
633        \   ["test", ["Test", "testn", "testen"]],
634        \   ["d\xE9\xF4l", ["deol", "d\xE9\xF4r", "test"]],
635        \   ["end", ["put", "uk", "test"]],
636        \   ["the", ["put", "uk", "test"]],
637        \ ]
638        \ )
639
640  call assert_equal("gebletegek", soundfold('goobledygoook'))
641  call assert_equal("kepereneven", 'k�op�r�n�ven'->soundfold())
642  call assert_equal("everles gesvets etele", soundfold('oeverloos gezwets edale'))
643endfunc
644
645" Postponed prefixes
646func Test_zz_prefixes()
647  call LoadAffAndDic(g:test_data_aff2, g:test_data_dic1)
648  call RunGoodBad("puts",
649        \ "bad: inputs comment ok Ok end the. test d\xE9\xF4l",
650        \ ["Comment", "deol", "d\xE9\xF4r", "OK", "put", "input", "output", "puts", "outputs", "test", "outtest", "testen", "testn", "the end", "uk", "wrong"],
651        \ [
652        \   ["bad", ["put", "uk", "OK"]],
653        \   ["inputs", ["input", "puts", "outputs"]],
654        \   ["comment", ["Comment"]],
655        \   ["ok", ["OK", "uk", "put"]],
656        \   ["Ok", ["OK", "Uk", "Put"]],
657        \   ["end", ["put", "uk", "deol"]],
658        \   ["the", ["put", "uk", "test"]],
659        \   ["test", ["Test", "testn", "testen"]],
660        \   ["d\xE9\xF4l", ["deol", "d\xE9\xF4r", "test"]],
661        \ ])
662endfunc
663
664"Compound words
665func Test_zz_compound()
666  call LoadAffAndDic(g:test_data_aff3, g:test_data_dic3)
667  call RunGoodBad("foo m\xEF foobar foofoobar barfoo barbarfoo",
668        \ "bad: bar la foom\xEF barm\xEF m\xEFfoo m\xEFbar m\xEFm\xEF lala m\xEFla lam\xEF foola labar",
669        \ ["foo", "m\xEF"],
670        \ [
671        \   ["bad", ["foo", "m\xEF"]],
672        \   ["bar", ["barfoo", "foobar", "foo"]],
673        \   ["la", ["m\xEF", "foo"]],
674        \   ["foom\xEF", ["foo m\xEF", "foo", "foofoo"]],
675        \   ["barm\xEF", ["barfoo", "m\xEF", "barbar"]],
676        \   ["m\xEFfoo", ["m\xEF foo", "foo", "foofoo"]],
677        \   ["m\xEFbar", ["foobar", "barbar", "m\xEF"]],
678        \   ["m\xEFm\xEF", ["m\xEF m\xEF", "m\xEF"]],
679        \   ["lala", []],
680        \   ["m\xEFla", ["m\xEF", "m\xEF m\xEF"]],
681        \   ["lam\xEF", ["m\xEF", "m\xEF m\xEF"]],
682        \   ["foola", ["foo", "foobar", "foofoo"]],
683        \   ["labar", ["barbar", "foobar"]],
684        \ ])
685
686  call LoadAffAndDic(g:test_data_aff4, g:test_data_dic4)
687  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",
688        \ "bad: wordutilize pro borkborkborkborkborkbork tomatotomatotomato endstart endend startstart wordend wordstart preborkprebork  preborkpreborkbork startwordwordwordwordend borkpreborkpreborkbork utilsbork  startnouword",
689        \ ["bork", "prebork", "end", "pro-ok", "start", "tomato", "util", "utilize", "utils", "word", "nouword"],
690        \ [
691        \   ["bad", ["end", "bork", "word"]],
692        \   ["wordutilize", ["word utilize", "wordutils", "wordutil"]],
693        \   ["pro", ["bork", "word", "end"]],
694        \   ["borkborkborkborkborkbork", ["bork borkborkborkborkbork", "borkbork borkborkborkbork", "borkborkbork borkborkbork"]],
695        \   ["tomatotomatotomato", ["tomato tomatotomato", "tomatotomato tomato", "tomato tomato tomato"]],
696        \   ["endstart", ["end start", "start"]],
697        \   ["endend", ["end end", "end"]],
698        \   ["startstart", ["start start"]],
699        \   ["wordend", ["word end", "word", "wordword"]],
700        \   ["wordstart", ["word start", "bork start"]],
701        \   ["preborkprebork", ["prebork prebork", "preborkbork", "preborkborkbork"]],
702        \   ["preborkpreborkbork", ["prebork preborkbork", "preborkborkbork", "preborkborkborkbork"]],
703        \   ["startwordwordwordwordend", ["startwordwordwordword end", "startwordwordwordword", "start wordwordwordword end"]],
704        \   ["borkpreborkpreborkbork", ["bork preborkpreborkbork", "bork prebork preborkbork", "bork preborkprebork bork"]],
705        \   ["utilsbork", ["utilbork", "utils bork", "util bork"]],
706        \   ["startnouword", ["start nouword", "startword", "startborkword"]],
707        \ ])
708
709endfunc
710
711"Test affix flags with two characters
712func Test_zz_affix()
713  call LoadAffAndDic(g:test_data_aff5, g:test_data_dic5)
714  call RunGoodBad("fooa1 fooa\xE9 bar prebar barbork prebarbork  startprebar start end startend  startmiddleend nouend",
715        \ "bad: foo fooa2 prabar probarbirk middle startmiddle middleend endstart startprobar startnouend",
716        \ ["bar", "barbork", "end", "fooa1", "fooa\xE9", "nouend", "prebar", "prebarbork", "start"],
717        \ [
718        \   ["bad", ["bar", "end", "fooa1"]],
719        \   ["foo", ["fooa1", "fooa\xE9", "bar"]],
720        \   ["fooa2", ["fooa1", "fooa\xE9", "bar"]],
721        \   ["prabar", ["prebar", "bar", "bar bar"]],
722        \   ["probarbirk", ["prebarbork"]],
723        \   ["middle", []],
724        \   ["startmiddle", ["startmiddleend", "startmiddlebar"]],
725        \   ["middleend", []],
726        \   ["endstart", ["end start", "start"]],
727        \   ["startprobar", ["startprebar", "start prebar", "startbar"]],
728        \   ["startnouend", ["start nouend", "startend"]],
729        \ ])
730
731  call LoadAffAndDic(g:test_data_aff6, g:test_data_dic6)
732  call RunGoodBad("meea1 meea\xE9 bar prebar barbork prebarbork  leadprebar lead end leadend  leadmiddleend",
733        \  "bad: mee meea2 prabar probarbirk middle leadmiddle middleend endlead leadprobar",
734        \ ["bar", "barbork", "end", "lead", "meea1", "meea\xE9", "prebar", "prebarbork"],
735        \ [
736        \   ["bad", ["bar", "end", "lead"]],
737        \   ["mee", ["meea1", "meea\xE9", "bar"]],
738        \   ["meea2", ["meea1", "meea\xE9", "lead"]],
739        \   ["prabar", ["prebar", "bar", "leadbar"]],
740        \   ["probarbirk", ["prebarbork"]],
741        \   ["middle", []],
742        \   ["leadmiddle", ["leadmiddleend", "leadmiddlebar"]],
743        \   ["middleend", []],
744        \   ["endlead", ["end lead", "lead", "end end"]],
745        \   ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]],
746        \ ])
747
748  call LoadAffAndDic(g:test_data_aff7, g:test_data_dic7)
749  call RunGoodBad("meea1 meezero meea\xE9 bar prebar barmeat prebarmeat  leadprebar lead tail leadtail  leadmiddletail",
750        \ "bad: mee meea2 prabar probarmaat middle leadmiddle middletail taillead leadprobar",
751        \ ["bar", "barmeat", "lead", "meea1", "meea\xE9", "meezero", "prebar", "prebarmeat", "tail"],
752        \ [
753        \   ["bad", ["bar", "lead", "tail"]],
754        \   ["mee", ["meea1", "meea\xE9", "bar"]],
755        \   ["meea2", ["meea1", "meea\xE9", "lead"]],
756        \   ["prabar", ["prebar", "bar", "leadbar"]],
757        \   ["probarmaat", ["prebarmeat"]],
758        \   ["middle", []],
759        \   ["leadmiddle", ["leadmiddlebar"]],
760        \   ["middletail", []],
761        \   ["taillead", ["tail lead", "tail"]],
762        \   ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]],
763        \ ])
764endfunc
765
766func Test_zz_NOSLITSUGS()
767  call LoadAffAndDic(g:test_data_aff8, g:test_data_dic8)
768  call RunGoodBad("foo bar faabar", "bad: foobar barfoo",
769        \ ["bar", "faabar", "foo"],
770        \ [
771        \   ["bad", ["bar", "foo"]],
772        \   ["foobar", ["faabar", "foo bar", "bar"]],
773        \   ["barfoo", ["bar foo", "bar", "foo"]],
774        \ ])
775endfunc
776
777" Numbers
778func Test_zz_Numbers()
779  call LoadAffAndDic(g:test_data_aff9, g:test_data_dic9)
780  call RunGoodBad("0b1011 0777 1234 0x01ff", "",
781        \ ["bar", "foo"],
782        \ [
783        \ ])
784endfunc
785
786" Affix flags
787func Test_zz_affix_flags()
788  call LoadAffAndDic(g:test_data_aff10, g:test_data_dic10)
789  call RunGoodBad("drink drinkable drinkables drinktable drinkabletable",
790	\ "bad: drinks drinkstable drinkablestable",
791        \ ["drink", "drinkable", "drinkables", "table"],
792        \ [['bad', []],
793	\ ['drinks', ['drink']],
794	\ ['drinkstable', ['drinktable', 'drinkable', 'drink table']],
795        \ ['drinkablestable', ['drinkabletable', 'drinkables table', 'drinkable table']],
796	\ ])
797endfunc
798
799function FirstSpellWord()
800  call feedkeys("/^start:\n", 'tx')
801  normal ]smm
802  let [str, a] = spellbadword()
803  return str
804endfunc
805
806function SecondSpellWord()
807  normal `m]s
808  let [str, a] = spellbadword()
809  return str
810endfunc
811
812"Test with SAL instead of SOFO items; test automatic reloading
813func Test_zz_sal_and_addition()
814  throw 'skipped: Nvim does not support enc=latin1'
815  set enc=latin1
816  set spellfile=
817  call writefile(g:test_data_dic1, "Xtest.dic", 'D')
818  call writefile(g:test_data_aff_sal, "Xtest.aff", 'D')
819  mkspell! Xtest Xtest
820  set spl=Xtest.latin1.spl spell
821  call assert_equal('kbltykk', soundfold('goobledygoook'))
822  call assert_equal('kprnfn', soundfold('k�op�r�n�ven'))
823  call assert_equal('*fls kswts tl', soundfold('oeverloos gezwets edale'))
824
825  "also use an addition file
826  call writefile(["/regions=usgbnz", "elequint/2", "elekwint/3"], "Xtest.latin1.add", 'D')
827  mkspell! Xtest.latin1.add.spl Xtest.latin1.add
828
829  bwipe!
830  call setline(1, ["start: elequint test elekwint test elekwent asdf"])
831
832  set spellfile=Xtest.latin1.add
833  call assert_equal("elekwent", FirstSpellWord())
834
835  set spl=Xtest_us.latin1.spl
836  call assert_equal("elequint", FirstSpellWord())
837  call assert_equal("elekwint", SecondSpellWord())
838
839  set spl=Xtest_gb.latin1.spl
840  call assert_equal("elekwint", FirstSpellWord())
841  call assert_equal("elekwent", SecondSpellWord())
842
843  set spl=Xtest_nz.latin1.spl
844  call assert_equal("elequint", FirstSpellWord())
845  call assert_equal("elekwent", SecondSpellWord())
846
847  set spl=Xtest_ca.latin1.spl
848  call assert_equal("elequint", FirstSpellWord())
849  call assert_equal("elekwint", SecondSpellWord())
850
851  bwipe!
852  set spellfile=
853  set spl&
854endfunc
855
856func Test_spellfile_value()
857  set spellfile=Xdir/Xtest.latin1.add
858  set spellfile=Xdir/Xtest.utf-8.add,Xtest_other.add
859endfunc
860
861func Test_region_error()
862  messages clear
863  call writefile(["/regions=usgbnz", "elequint/0"], "Xtest.latin1.add", 'D')
864  mkspell! Xtest.latin1.add.spl Xtest.latin1.add
865  call assert_match('Invalid region nr in Xtest.latin1.add line 2: 0', execute('messages'))
866  call delete('Xtest.latin1.add.spl')
867endfunc
868
869" Check using z= in new buffer (crash fixed by patch 7.4a.028).
870func Test_zeq_crash()
871  new
872  set spell
873  call feedkeys('iasdz=:\"', 'tx')
874
875  bwipe!
876endfunc
877
878" Check that z= works even when 'nospell' is set.  This test uses one of the
879" tests in Test_spellsuggest_option_number() just to verify that z= basically
880" works and that "E756: Spell checking is not enabled" is not generated.
881func Test_zeq_nospell()
882  new
883  set nospell spellsuggest=1,best
884  call setline(1, 'A baord')
885  try
886    norm $1z=
887    call assert_equal('A board', getline(1))
888  catch
889    call assert_report("Caught exception: " . v:exception)
890  endtry
891  set spell& spellsuggest&
892  bwipe!
893endfunc
894
895" Check that "E756: Spell checking is not possible" is reported when z= is
896" executed and 'spelllang' is empty.
897func Test_zeq_no_spelllang()
898  new
899  set spelllang= spellsuggest=1,best
900  call setline(1, 'A baord')
901  call assert_fails('normal $1z=', 'E756:')
902  set spelllang& spellsuggest&
903  bwipe!
904endfunc
905
906" Check handling a word longer than MAXWLEN.
907func Test_spell_long_word()
908  set enc=utf-8
909  new
910  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")
911  set spell spelllang=en
912  redraw
913  redraw!
914  bwipe!
915  set nospell
916endfunc
917
918func Test_spellsuggest_too_deep()
919  " This was incrementing "depth" over MAXWLEN.
920  new
921  norm s000G00�000000000000
922  try
923    sil norm ..vzG................vvzG0     v z=
924  catch /E759:/
925  endtry
926  bwipe!
927endfunc
928
929func Test_spell_good_word_invalid()
930  " This was adding a word with a 0x02 byte, which causes havoc.
931  enew
932  norm o0
933  sil! norm rzzWs00/
934  2
935  sil! norm VzGprzzW
936  sil! norm z=
937
938  bwipe!
939endfunc
940
941func Test_spell_good_word_slash()
942  " This caused E1280.
943  new
944  norm afoo /
945  1
946  norm zG
947
948  bwipe!
949endfunc
950
951func LoadAffAndDic(aff_contents, dic_contents)
952  throw 'skipped: Nvim does not support enc=latin1'
953  set enc=latin1
954  set spellfile=
955  call writefile(a:aff_contents, "Xtest.aff")
956  call writefile(a:dic_contents, "Xtest.dic")
957  " Generate a .spl file from a .dic and .aff file.
958  mkspell! Xtest Xtest
959  " use that spell file
960  set spl=Xtest.latin1.spl spell
961endfunc
962
963func ListWords()
964  spelldump
965  %yank
966  quit
967  return split(@", "\n")
968endfunc
969
970func TestGoodBadBase()
971  exe '1;/^good:'
972  normal 0f:]s
973  let prevbad = ''
974  let result = []
975  while 1
976    let [bad, a] = spellbadword()
977    if bad == '' || bad == prevbad || bad == 'badend'
978      break
979    endif
980    let prevbad = bad
981    let lst = bad->spellsuggest(3)
982    normal mm
983
984    call add(result, [bad, lst])
985    normal `m]s
986  endwhile
987  return result
988endfunc
989
990func RunGoodBad(good, bad, expected_words, expected_bad_words)
991  bwipe!
992  call setline(1, ["good: ", a:good,  a:bad, " badend "])
993  let words = ListWords()
994  call assert_equal(a:expected_words, words[1:-1])
995  let bad_words = TestGoodBadBase()
996  call assert_equal(a:expected_bad_words, bad_words)
997  bwipe!
998endfunc
999
1000func Test_spell_screendump()
1001  CheckScreendump
1002
1003  let lines =<< trim END
1004       call test_override('alloc_lines', 1)
1005       call setline(1, [
1006             \ "This is some text without any spell errors.  Everything",
1007             \ "should just be black, nothing wrong here.",
1008             \ "",
1009             \ "This line has a sepll error. and missing caps.",
1010             \ "And and this is the the duplication.",
1011             \ "with missing caps here.",
1012             \ ])
1013       set spell spelllang=en_nz
1014  END
1015  call writefile(lines, 'XtestSpell', 'D')
1016  let buf = RunVimInTerminal('-S XtestSpell', {'rows': 8})
1017  call VerifyScreenDump(buf, 'Test_spell_1', {})
1018
1019  " clean up
1020  call StopVimInTerminal(buf)
1021endfunc
1022
1023func Test_spell_screendump_spellcap()
1024  CheckScreendump
1025
1026  let lines =<< trim END
1027       call test_override('alloc_lines', 1)
1028       call setline(1, [
1029             \ "   This line has a sepll error. and missing caps and trailing spaces.   ",
1030             \ "another missing cap here.",
1031             \ "",
1032             \ "and here.",
1033             \ "    ",
1034             \ "and here."
1035             \ ])
1036       set spell spelllang=en
1037  END
1038  call writefile(lines, 'XtestSpellCap', 'D')
1039  let buf = RunVimInTerminal('-S XtestSpellCap', {'rows': 8})
1040  call VerifyScreenDump(buf, 'Test_spell_2', {})
1041
1042  " After adding word missing Cap in next line is updated
1043  call term_sendkeys(buf, "3GANot\<Esc>")
1044  call VerifyScreenDump(buf, 'Test_spell_3', {})
1045
1046  " Deleting a full stop removes missing Cap in next line
1047  call term_sendkeys(buf, "5Gdd\<C-L>k$x")
1048  call VerifyScreenDump(buf, 'Test_spell_4', {})
1049
1050  " Undo also updates the next line (go to command line to remove message)
1051  call term_sendkeys(buf, "u:\<Esc>")
1052  call VerifyScreenDump(buf, 'Test_spell_5', {})
1053
1054  " Folding an empty line does not remove Cap in next line
1055  call term_sendkeys(buf, "uzfk:\<Esc>")
1056  call VerifyScreenDump(buf, 'Test_spell_6', {})
1057
1058  " Folding the end of a sentence does not remove Cap in next line
1059  " and editing a line does not remove Cap in current line
1060  call term_sendkeys(buf, "Jzfkk$x")
1061  call VerifyScreenDump(buf, 'Test_spell_7', {})
1062
1063  " Cap is correctly applied in the first row of a window
1064  call term_sendkeys(buf, "\<C-E>\<C-L>")
1065  call VerifyScreenDump(buf, 'Test_spell_8', {})
1066
1067  " Adding an empty line does not remove Cap in "mod_bot" area
1068  call term_sendkeys(buf, "zbO\<Esc>")
1069  call VerifyScreenDump(buf, 'Test_spell_9', {})
1070
1071  " Multiple empty lines does not remove Cap in the line after
1072  call term_sendkeys(buf, "O\<Esc>\<C-L>")
1073  call VerifyScreenDump(buf, 'Test_spell_10', {})
1074
1075  " clean up
1076  call StopVimInTerminal(buf)
1077endfunc
1078
1079func Test_spell_compatible()
1080  CheckScreendump
1081
1082  let lines =<< trim END
1083       call test_override('alloc_lines', 1)
1084       call setline(1, [
1085             \ "test "->repeat(20),
1086             \ "",
1087             \ "end",
1088             \ ])
1089       set spell cpo+=$
1090  END
1091  call writefile(lines, 'XtestSpellComp', 'D')
1092  let buf = RunVimInTerminal('-S XtestSpellComp', {'rows': 8})
1093
1094  call term_sendkeys(buf, "51|C")
1095  call VerifyScreenDump(buf, 'Test_spell_compatible_1', {})
1096
1097  call term_sendkeys(buf, "x")
1098  call VerifyScreenDump(buf, 'Test_spell_compatible_2', {})
1099
1100  " clean up
1101  call StopVimInTerminal(buf)
1102endfunc
1103
1104func Test_z_equal_with_large_count()
1105  split
1106  set spell
1107  call setline(1, "ff")
1108  norm 0z=337203685477580
1109  set nospell
1110  bwipe!
1111endfunc
1112
1113let g:test_data_aff1 = [
1114      \"SET ISO8859-1",
1115      \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ",
1116      \"",
1117      \"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",
1118      \"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",
1119      \"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",
1120      \"",
1121      \"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",
1122      \"SOFOTO   ebctefghejklnnepkrstevvkesebctefghejklnnepkrstevvkeseeeeeeeceeeeeeeedneeeeeeeeeeepseeeeeeeeceeeeeeeedneeeeeeeeeeep?",
1123      \"",
1124      \"MIDWORD\t'-",
1125      \"",
1126      \"KEP =",
1127      \"RAR ?",
1128      \"BAD !",
1129      \"",
1130      \"PFX I N 1",
1131      \"PFX I 0 in .",
1132      \"",
1133      \"PFX O Y 1",
1134      \"PFX O 0 out .",
1135      \"",
1136      \"SFX S Y 2",
1137      \"SFX S 0 s [^s]",
1138      \"SFX S 0 es s",
1139      \"",
1140      \"SFX N N 3",
1141      \"SFX N 0 en [^n]",
1142      \"SFX N 0 nen n",
1143      \"SFX N 0 n .",
1144      \"",
1145      \"REP 3",
1146      \"REP g ch",
1147      \"REP ch g",
1148      \"REP svp s.v.p.",
1149      \"",
1150      \"MAP 9",
1151      \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
1152      \"MAP e\xE8\xE9\xEA\xEB",
1153      \"MAP i\xEC\xED\xEE\xEF",
1154      \"MAP o\xF2\xF3\xF4\xF5\xF6",
1155      \"MAP u\xF9\xFA\xFB\xFC",
1156      \"MAP n\xF1",
1157      \"MAP c\xE7",
1158      \"MAP y\xFF\xFD",
1159      \"MAP s\xDF",
1160      \ ]
1161let g:test_data_dic1 = [
1162      \"123456",
1163      \"test/NO",
1164      \"# comment",
1165      \"wrong",
1166      \"Comment",
1167      \"OK",
1168      \"uk",
1169      \"put/ISO",
1170      \"the end",
1171      \"deol",
1172      \"d\xE9\xF4r",
1173      \ ]
1174let g:test_data_aff2 = [
1175      \"SET ISO8859-1",
1176      \"",
1177      \"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",
1178      \"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",
1179      \"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",
1180      \"",
1181      \"PFXPOSTPONE",
1182      \"",
1183      \"MIDWORD\t'-",
1184      \"",
1185      \"KEP =",
1186      \"RAR ?",
1187      \"BAD !",
1188      \"",
1189      \"PFX I N 1",
1190      \"PFX I 0 in .",
1191      \"",
1192      \"PFX O Y 1",
1193      \"PFX O 0 out [a-z]",
1194      \"",
1195      \"SFX S Y 2",
1196      \"SFX S 0 s [^s]",
1197      \"SFX S 0 es s",
1198      \"",
1199      \"SFX N N 3",
1200      \"SFX N 0 en [^n]",
1201      \"SFX N 0 nen n",
1202      \"SFX N 0 n .",
1203      \"",
1204      \"REP 3",
1205      \"REP g ch",
1206      \"REP ch g",
1207      \"REP svp s.v.p.",
1208      \"",
1209      \"MAP 9",
1210      \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
1211      \"MAP e\xE8\xE9\xEA\xEB",
1212      \"MAP i\xEC\xED\xEE\xEF",
1213      \"MAP o\xF2\xF3\xF4\xF5\xF6",
1214      \"MAP u\xF9\xFA\xFB\xFC",
1215      \"MAP n\xF1",
1216      \"MAP c\xE7",
1217      \"MAP y\xFF\xFD",
1218      \"MAP s\xDF",
1219      \ ]
1220let g:test_data_aff3 = [
1221      \"SET ISO8859-1",
1222      \"",
1223      \"COMPOUNDMIN 3",
1224      \"COMPOUNDRULE m*",
1225      \"NEEDCOMPOUND x",
1226      \ ]
1227let g:test_data_dic3 = [
1228      \"1234",
1229      \"foo/m",
1230      \"bar/mx",
1231      \"m\xEF/m",
1232      \"la/mx",
1233      \ ]
1234let g:test_data_aff4 = [
1235      \"SET ISO8859-1",
1236      \"",
1237      \"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",
1238      \"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",
1239      \"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",
1240      \"",
1241      \"COMPOUNDRULE m+",
1242      \"COMPOUNDRULE sm*e",
1243      \"COMPOUNDRULE sm+",
1244      \"COMPOUNDMIN 3",
1245      \"COMPOUNDWORDMAX 3",
1246      \"COMPOUNDFORBIDFLAG t",
1247      \"",
1248      \"COMPOUNDSYLMAX 5",
1249      \"SYLLABLE a\xE1e\xE9i\xEDo\xF3\xF6\xF5u\xFA\xFC\xFBy/aa/au/ea/ee/ei/ie/oa/oe/oo/ou/uu/ui",
1250      \"",
1251      \"MAP 9",
1252      \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
1253      \"MAP e\xE8\xE9\xEA\xEB",
1254      \"MAP i\xEC\xED\xEE\xEF",
1255      \"MAP o\xF2\xF3\xF4\xF5\xF6",
1256      \"MAP u\xF9\xFA\xFB\xFC",
1257      \"MAP n\xF1",
1258      \"MAP c\xE7",
1259      \"MAP y\xFF\xFD",
1260      \"MAP s\xDF",
1261      \"",
1262      \"NEEDAFFIX x",
1263      \"",
1264      \"PFXPOSTPONE",
1265      \"",
1266      \"MIDWORD '-",
1267      \"",
1268      \"SFX q N 1",
1269      \"SFX q   0    -ok .",
1270      \"",
1271      \"SFX a Y 2",
1272      \"SFX a 0 s .",
1273      \"SFX a 0 ize/t .",
1274      \"",
1275      \"PFX p N 1",
1276      \"PFX p 0 pre .",
1277      \"",
1278      \"PFX P N 1",
1279      \"PFX P 0 nou .",
1280      \ ]
1281let g:test_data_dic4 = [
1282      \"1234",
1283      \"word/mP",
1284      \"util/am",
1285      \"pro/xq",
1286      \"tomato/m",
1287      \"bork/mp",
1288      \"start/s",
1289      \"end/e",
1290      \ ]
1291let g:test_data_aff5 = [
1292      \"SET ISO8859-1",
1293      \"",
1294      \"FLAG long",
1295      \"",
1296      \"NEEDAFFIX !!",
1297      \"",
1298      \"COMPOUNDRULE ssmm*ee",
1299      \"",
1300      \"NEEDCOMPOUND xx",
1301      \"COMPOUNDPERMITFLAG pp",
1302      \"",
1303      \"SFX 13 Y 1",
1304      \"SFX 13 0 bork .",
1305      \"",
1306      \"SFX a1 Y 1",
1307      \"SFX a1 0 a1 .",
1308      \"",
1309      \"SFX a\xE9 Y 1",
1310      \"SFX a\xE9 0 a\xE9 .",
1311      \"",
1312      \"PFX zz Y 1",
1313      \"PFX zz 0 pre/pp .",
1314      \"",
1315      \"PFX yy Y 1",
1316      \"PFX yy 0 nou .",
1317      \ ]
1318let g:test_data_dic5 = [
1319      \"1234",
1320      \"foo/a1a\xE9!!",
1321      \"bar/zz13ee",
1322      \"start/ss",
1323      \"end/eeyy",
1324      \"middle/mmxx",
1325      \ ]
1326let g:test_data_aff6 = [
1327      \"SET ISO8859-1",
1328      \"",
1329      \"FLAG caplong",
1330      \"",
1331      \"NEEDAFFIX A!",
1332      \"",
1333      \"COMPOUNDRULE sMm*Ee",
1334      \"",
1335      \"NEEDCOMPOUND Xx",
1336      \"",
1337      \"COMPOUNDPERMITFLAG p",
1338      \"",
1339      \"SFX N3 Y 1",
1340      \"SFX N3 0 bork .",
1341      \"",
1342      \"SFX A1 Y 1",
1343      \"SFX A1 0 a1 .",
1344      \"",
1345      \"SFX A\xE9 Y 1",
1346      \"SFX A\xE9 0 a\xE9 .",
1347      \"",
1348      \"PFX Zz Y 1",
1349      \"PFX Zz 0 pre/p .",
1350      \ ]
1351let g:test_data_dic6 = [
1352      \"1234",
1353      \"mee/A1A\xE9A!",
1354      \"bar/ZzN3Ee",
1355      \"lead/s",
1356      \"end/Ee",
1357      \"middle/MmXx",
1358      \ ]
1359let g:test_data_aff7 = [
1360      \"SET ISO8859-1",
1361      \"",
1362      \"FLAG num",
1363      \"",
1364      \"NEEDAFFIX 9999",
1365      \"",
1366      \"COMPOUNDRULE 2,77*123",
1367      \"",
1368      \"NEEDCOMPOUND 1",
1369      \"COMPOUNDPERMITFLAG 432",
1370      \"",
1371      \"SFX 61003 Y 1",
1372      \"SFX 61003 0 meat .",
1373      \"",
1374      \"SFX 0 Y 1",
1375      \"SFX 0 0 zero .",
1376      \"",
1377      \"SFX 391 Y 1",
1378      \"SFX 391 0 a1 .",
1379      \"",
1380      \"SFX 111 Y 1",
1381      \"SFX 111 0 a\xE9 .",
1382      \"",
1383      \"PFX 17 Y 1",
1384      \"PFX 17 0 pre/432 .",
1385      \ ]
1386let g:test_data_dic7 = [
1387      \"1234",
1388      \"mee/0,391,111,9999",
1389      \"bar/17,61003,123",
1390      \"lead/2",
1391      \"tail/123",
1392      \"middle/77,1",
1393      \ ]
1394let g:test_data_aff8 = [
1395      \"SET ISO8859-1",
1396      \"",
1397      \"NOSPLITSUGS",
1398      \ ]
1399let g:test_data_dic8 = [
1400      \"1234",
1401      \"foo",
1402      \"bar",
1403      \"faabar",
1404      \ ]
1405let g:test_data_aff9 = [
1406      \ ]
1407let g:test_data_dic9 = [
1408      \"1234",
1409      \"foo",
1410      \"bar",
1411      \ ]
1412let g:test_data_aff10 = [
1413      \"COMPOUNDRULE se",
1414      \"COMPOUNDPERMITFLAG p",
1415      \"",
1416      \"SFX A Y 1",
1417      \"SFX A 0 able/Mp .",
1418      \"",
1419      \"SFX M Y 1",
1420      \"SFX M 0 s .",
1421      \ ]
1422let g:test_data_dic10 = [
1423      \"1234",
1424      \"drink/As",
1425      \"table/e",
1426      \ ]
1427let g:test_data_aff_sal = [
1428      \"SET ISO8859-1",
1429      \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ",
1430      \"",
1431      \"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",
1432      \"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",
1433      \"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",
1434      \"",
1435      \"MIDWORD\t'-",
1436      \"",
1437      \"KEP =",
1438      \"RAR ?",
1439      \"BAD !",
1440      \"",
1441      \"PFX I N 1",
1442      \"PFX I 0 in .",
1443      \"",
1444      \"PFX O Y 1",
1445      \"PFX O 0 out .",
1446      \"",
1447      \"SFX S Y 2",
1448      \"SFX S 0 s [^s]",
1449      \"SFX S 0 es s",
1450      \"",
1451      \"SFX N N 3",
1452      \"SFX N 0 en [^n]",
1453      \"SFX N 0 nen n",
1454      \"SFX N 0 n .",
1455      \"",
1456      \"REP 3",
1457      \"REP g ch",
1458      \"REP ch g",
1459      \"REP svp s.v.p.",
1460      \"",
1461      \"MAP 9",
1462      \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
1463      \"MAP e\xE8\xE9\xEA\xEB",
1464      \"MAP i\xEC\xED\xEE\xEF",
1465      \"MAP o\xF2\xF3\xF4\xF5\xF6",
1466      \"MAP u\xF9\xFA\xFB\xFC",
1467      \"MAP n\xF1",
1468      \"MAP c\xE7",
1469      \"MAP y\xFF\xFD",
1470      \"MAP s\xDF",
1471      \"",
1472      \"SAL AH(AEIOUY)-^         *H",
1473      \"SAL AR(AEIOUY)-^         *R",
1474      \"SAL A(HR)^               *",
1475      \"SAL A^                   *",
1476      \"SAL AH(AEIOUY)-          H",
1477      \"SAL AR(AEIOUY)-          R",
1478      \"SAL A(HR)                _",
1479      \"SAL \xC0^                   *",
1480      \"SAL \xC5^                   *",
1481      \"SAL BB-                  _",
1482      \"SAL B                    B",
1483      \"SAL CQ-                  _",
1484      \"SAL CIA                  X",
1485      \"SAL CH                   X",
1486      \"SAL C(EIY)-              S",
1487      \"SAL CK                   K",
1488      \"SAL COUGH^               KF",
1489      \"SAL CC<                  C",
1490      \"SAL C                    K",
1491      \"SAL DG(EIY)              K",
1492      \"SAL DD-                  _",
1493      \"SAL D                    T",
1494      \"SAL \xC9<                   E",
1495      \"SAL EH(AEIOUY)-^         *H",
1496      \"SAL ER(AEIOUY)-^         *R",
1497      \"SAL E(HR)^               *",
1498      \"SAL ENOUGH^$             *NF",
1499      \"SAL E^                   *",
1500      \"SAL EH(AEIOUY)-          H",
1501      \"SAL ER(AEIOUY)-          R",
1502      \"SAL E(HR)                _",
1503      \"SAL FF-                  _",
1504      \"SAL F                    F",
1505      \"SAL GN^                  N",
1506      \"SAL GN$                  N",
1507      \"SAL GNS$                 NS",
1508      \"SAL GNED$                N",
1509      \"SAL GH(AEIOUY)-          K",
1510      \"SAL GH                   _",
1511      \"SAL GG9                  K",
1512      \"SAL G                    K",
1513      \"SAL H                    H",
1514      \"SAL IH(AEIOUY)-^         *H",
1515      \"SAL IR(AEIOUY)-^         *R",
1516      \"SAL I(HR)^               *",
1517      \"SAL I^                   *",
1518      \"SAL ING6                 N",
1519      \"SAL IH(AEIOUY)-          H",
1520      \"SAL IR(AEIOUY)-          R",
1521      \"SAL I(HR)                _",
1522      \"SAL J                    K",
1523      \"SAL KN^                  N",
1524      \"SAL KK-                  _",
1525      \"SAL K                    K",
1526      \"SAL LAUGH^               LF",
1527      \"SAL LL-                  _",
1528      \"SAL L                    L",
1529      \"SAL MB$                  M",
1530      \"SAL MM                   M",
1531      \"SAL M                    M",
1532      \"SAL NN-                  _",
1533      \"SAL N                    N",
1534      \"SAL OH(AEIOUY)-^         *H",
1535      \"SAL OR(AEIOUY)-^         *R",
1536      \"SAL O(HR)^               *",
1537      \"SAL O^                   *",
1538      \"SAL OH(AEIOUY)-          H",
1539      \"SAL OR(AEIOUY)-          R",
1540      \"SAL O(HR)                _",
1541      \"SAL PH                   F",
1542      \"SAL PN^                  N",
1543      \"SAL PP-                  _",
1544      \"SAL P                    P",
1545      \"SAL Q                    K",
1546      \"SAL RH^                  R",
1547      \"SAL ROUGH^               RF",
1548      \"SAL RR-                  _",
1549      \"SAL R                    R",
1550      \"SAL SCH(EOU)-            SK",
1551      \"SAL SC(IEY)-             S",
1552      \"SAL SH                   X",
1553      \"SAL SI(AO)-              X",
1554      \"SAL SS-                  _",
1555      \"SAL S                    S",
1556      \"SAL TI(AO)-              X",
1557      \"SAL TH                   @",
1558      \"SAL TCH--                _",
1559      \"SAL TOUGH^               TF",
1560      \"SAL TT-                  _",
1561      \"SAL T                    T",
1562      \"SAL UH(AEIOUY)-^         *H",
1563      \"SAL UR(AEIOUY)-^         *R",
1564      \"SAL U(HR)^               *",
1565      \"SAL U^                   *",
1566      \"SAL UH(AEIOUY)-          H",
1567      \"SAL UR(AEIOUY)-          R",
1568      \"SAL U(HR)                _",
1569      \"SAL V^                   W",
1570      \"SAL V                    F",
1571      \"SAL WR^                  R",
1572      \"SAL WH^                  W",
1573      \"SAL W(AEIOU)-            W",
1574      \"SAL X^                   S",
1575      \"SAL X                    KS",
1576      \"SAL Y(AEIOU)-            Y",
1577      \"SAL ZZ-                  _",
1578      \"SAL Z                    S",
1579      \ ]
1580
1581func Test_suggest_spell_restore()
1582  norm! z=
1583  call assert_equal(0, &spell)
1584  set spelllang=
1585  sil! norm! z=
1586  call assert_equal(0, &spell)
1587  set spelllang=en
1588  call setline(1, ['1','2'])
1589  norm! vjz=
1590  call assert_equal(0, &spell)
1591  set spelllang&
1592  bwipe!
1593endfunc
1594
1595" A crafted .spl with a self-referential BY_INDEX node in the PREFIXTREE drove
1596" dump_prefixes() past its MAXWLEN-sized depth arrays (stack out-of-bounds
1597" write).  The tree parses cleanly (shared refs aren't recursed); the walk
1598" happens on :spelldump.  Reaching the assert means no OOB.  Same class as the
1599" tree_count_words() fix (9.2.0653).
1600func Test_spelldump_prefixtree_overflow()
1601  CheckUnix
1602  let save_rtp = &runtimepath
1603  call mkdir('Xrtp/spell', 'pR')
1604  " VIMspell + v50, SN_PREFCOND(prefixcnt=1), SN_END,
1605  " LWORDTREE word "a" with affixID=1 (so dump_prefixes runs),
1606  " empty KWORDTREE, PREFIXTREE child BY_INDEX -> nodeidx 0 (self-cycle), 'A'
1607  let spl = eval('0z56494D7370656C6C32030000000003000100FF00000004'
1608        \ .. '0161010220010000000000000002010100000041')
1609  call writefile(spl, 'Xrtp/spell/xx.utf-8.spl', 'b')
1610
1611  new
1612  set runtimepath+=./Xrtp
1613  set spelllang=xx
1614  set spell
1615  spelldump
1616  call assert_true(line('$') > 1)
1617
1618  set spell& spelllang&
1619  let &runtimepath = save_rtp
1620  bwipe!
1621  bwipe!
1622endfunc
1623
1624" This was using the cursor position from before a SpellFileMissing
1625" autocommand made the line shorter.
1626func Test_spell_file_missing_z_equal()
1627  new
1628  call setline(1, repeat('a', 40))
1629  call cursor(1, 30)
1630  set spelllang=xy
1631  au SpellFileMissing * call setline(1, 'ab')
1632
1633  " The language cannot be loaded, so z= reports E756; the invalid cursor
1634  " position was used before that error reached the script level.
1635  silent! norm! z=
1636  call assert_equal('ab', getline(1))
1637
1638  au! SpellFileMissing
1639  set nospell spelllang=en
1640  bwipe!
1641endfunc
1642
1643" vim: shiftwidth=2 sts=2 expandtab