" Test spell checking
" Note: this file uses latin1 encoding, but is used with utf-8 encoding.
source check.vim
CheckFeature spell
source screendump.vim
func TearDown()
set nospell
call delete('Xtest.aff')
call delete('Xtest.dic')
call delete('Xtest.latin1.add')
call delete('Xtest.latin1.add.spl')
call delete('Xtest.latin1.spl')
call delete('Xtest.latin1.sug')
endfunc
func Test_wrap_search()
new
call setline(1, ['The', '', 'A plong line with two zpelling mistakes', '', 'End'])
set spell wrapscan
normal ]s
call assert_equal('plong', expand('<cword>'))
normal ]s
call assert_equal('zpelling', expand('<cword>'))
normal ]s
call assert_equal('plong', expand('<cword>'))
bwipe!
set nospell
endfunc
func Test_curswant()
new
call setline(1, ['Another plong line', 'abcdefghijklmnopq'])
set spell wrapscan
normal 0]s
call assert_equal('plong', expand('<cword>'))
normal j
call assert_equal(9, getcurpos()[2])
normal 0[s
call assert_equal('plong', expand('<cword>'))
normal j
call assert_equal(9, getcurpos()[2])
normal 0]S
call assert_equal('plong', expand('<cword>'))
normal j
call assert_equal(9, getcurpos()[2])
normal 0[S
call assert_equal('plong', expand('<cword>'))
normal j
call assert_equal(9, getcurpos()[2])
normal 1G0
call assert_equal('plong', spellbadword()[0])
normal j
call assert_equal(9, getcurpos()[2])
bwipe!
set nospell
endfunc
func Test_z_equal_on_invalid_utf8_word()
split
set spell
call setline(1, "\xff")
norm z=
set nospell
bwipe!
endfunc
" Test spellbadword() with argument
func Test_spellbadword()
set spell
call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.'))
call assert_equal(['another', 'caps'], 'A sentence. another sentence'->spellbadword())
call assert_equal(['TheCamelWord', 'bad'], 'TheCamelWord asdf'->spellbadword())
set spelloptions=camel
call assert_equal(['asdf', 'bad'], 'TheCamelWord asdf'->spellbadword())
set spelloptions=
set spelllang=en
call assert_equal(['', ''], spellbadword('centre'))
call assert_equal(['', ''], spellbadword('center'))
set spelllang=en_us
call assert_equal(['centre', 'local'], spellbadword('centre'))
call assert_equal(['', ''], spellbadword('center'))
set spelllang=en_gb
call assert_equal(['', ''], spellbadword('centre'))
call assert_equal(['center', 'local'], spellbadword('center'))
" Create a small word list to test that spellbadword('...')
" can return ['...', 'rare'].
e Xwords
insert
foo
foobar/?
.
w!
mkspell! Xwords.spl Xwords
set spelllang=Xwords.spl
call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))
" Typo should be detected even without the 'spell' option.
set spelllang=en_gb nospell
call assert_equal(['', ''], spellbadword('centre'))
call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.'))
call assert_equal(['another', 'caps'], spellbadword('A sentence. another sentence'))
set spelllang=
call assert_fails("call spellbadword('maxch')", 'E756:')
call assert_fails("spelldump", 'E756:')
call delete('Xwords.spl')
call delete('Xwords')
set spelllang&
set spell&
endfunc
func Test_spellreall()
new
set spell
call assert_fails('spellrepall', 'E752:')
call setline(1, ['A speling mistake. The same speling mistake.',
\ 'Another speling mistake.'])
call feedkeys(']s1z=', 'tx')
call assert_equal('A spelling mistake. The same speling mistake.', getline(1))
call assert_equal('Another speling mistake.', getline(2))
spellrepall
call assert_equal('A spelling mistake. The same spelling mistake.', getline(1))
call assert_equal('Another spelling mistake.', getline(2))
call assert_fails('spellrepall', 'E753:')
set spell&
bwipe!
endfunc
" Test spellsuggest({word} [, {max} [, {capital}]])
func Test_spellsuggest()
" Verify suggestions are given even when spell checking is not enabled.
set nospell
call assert_equal(