108cc374dSBram Moolenaar" Test for commands that operate on the spellfile. 208cc374dSBram Moolenaar 308cc374dSBram Moolenaarsource shared.vim 408cc374dSBram Moolenaarsource check.vim 508cc374dSBram Moolenaar 608cc374dSBram MoolenaarCheckFeature spell 708cc374dSBram MoolenaarCheckFeature syntax 808cc374dSBram Moolenaar 908cc374dSBram Moolenaarfunc Test_spell_normal() 1008cc374dSBram Moolenaar new 1108cc374dSBram Moolenaar call append(0, ['1 good', '2 goood', '3 goood']) 1208cc374dSBram Moolenaar set spell spellfile=./Xspellfile.add spelllang=en 1308cc374dSBram Moolenaar let oldlang=v:lang 1408cc374dSBram Moolenaar lang C 1508cc374dSBram Moolenaar 1608cc374dSBram Moolenaar " Test for zg 1708cc374dSBram Moolenaar 1 1808cc374dSBram Moolenaar norm! ]s 1908cc374dSBram Moolenaar call assert_equal('2 goood', getline('.')) 2008cc374dSBram Moolenaar norm! zg 2108cc374dSBram Moolenaar 1 2208cc374dSBram Moolenaar let a=execute('unsilent :norm! ]s') 2308cc374dSBram Moolenaar call assert_equal('1 good', getline('.')) 2408cc374dSBram Moolenaar call assert_equal('search hit BOTTOM, continuing at TOP', a[1:]) 2508cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 2608cc374dSBram Moolenaar call assert_equal('goood', cnt[0]) 2708cc374dSBram Moolenaar 288a9bc95eSBram Moolenaar " zg should fail in operator-pending mode 298a9bc95eSBram Moolenaar call assert_beeps('norm! czg') 308a9bc95eSBram Moolenaar 318a9bc95eSBram Moolenaar " zg fails in visual mode when not able to get the visual text 328a9bc95eSBram Moolenaar call assert_beeps('norm! ggVjzg') 338a9bc95eSBram Moolenaar norm! V 348a9bc95eSBram Moolenaar 358a9bc95eSBram Moolenaar " zg fails for a non-identifier word 368a9bc95eSBram Moolenaar call append(line('$'), '###') 378a9bc95eSBram Moolenaar call assert_fails('norm! Gzg', 'E349:') 388a9bc95eSBram Moolenaar $d 398a9bc95eSBram Moolenaar 4008cc374dSBram Moolenaar " Test for zw 4108cc374dSBram Moolenaar 2 4208cc374dSBram Moolenaar norm! $zw 4308cc374dSBram Moolenaar 1 4408cc374dSBram Moolenaar norm! ]s 4508cc374dSBram Moolenaar call assert_equal('2 goood', getline('.')) 4608cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 4708cc374dSBram Moolenaar call assert_equal('#oood', cnt[0]) 4808cc374dSBram Moolenaar call assert_equal('goood/!', cnt[1]) 4908cc374dSBram Moolenaar 5008cc374dSBram Moolenaar " Test for :spellrare 5108cc374dSBram Moolenaar spellrare rare 5208cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 5308cc374dSBram Moolenaar call assert_equal(['#oood', 'goood/!', 'rare/?'], cnt) 5408cc374dSBram Moolenaar 5508cc374dSBram Moolenaar " Make sure :spellundo works for rare words. 5608cc374dSBram Moolenaar spellundo rare 5708cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 5808cc374dSBram Moolenaar call assert_equal(['#oood', 'goood/!', '#are/?'], cnt) 5908cc374dSBram Moolenaar 6008cc374dSBram Moolenaar " Test for zg in visual mode 6108cc374dSBram Moolenaar let a=execute('unsilent :norm! V$zg') 6208cc374dSBram Moolenaar call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) 6308cc374dSBram Moolenaar 1 6408cc374dSBram Moolenaar norm! ]s 6508cc374dSBram Moolenaar call assert_equal('3 goood', getline('.')) 6608cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 6708cc374dSBram Moolenaar call assert_equal('2 goood', cnt[3]) 6808cc374dSBram Moolenaar " Remove "2 good" from spellfile 6908cc374dSBram Moolenaar 2 7008cc374dSBram Moolenaar let a=execute('unsilent norm! V$zw') 7108cc374dSBram Moolenaar call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) 7208cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 7308cc374dSBram Moolenaar call assert_equal('2 goood/!', cnt[4]) 7408cc374dSBram Moolenaar 7508cc374dSBram Moolenaar " Test for zG 7608cc374dSBram Moolenaar let a=execute('unsilent norm! V$zG') 7708cc374dSBram Moolenaar call assert_match("Word '2 goood' added to .*", a) 7808cc374dSBram Moolenaar let fname=matchstr(a, 'to\s\+\zs\f\+$') 7908cc374dSBram Moolenaar let cnt=readfile(fname) 8008cc374dSBram Moolenaar call assert_equal('2 goood', cnt[0]) 8108cc374dSBram Moolenaar 8208cc374dSBram Moolenaar " Test for zW 8308cc374dSBram Moolenaar let a=execute('unsilent norm! V$zW') 8408cc374dSBram Moolenaar call assert_match("Word '2 goood' added to .*", a) 8508cc374dSBram Moolenaar let cnt=readfile(fname) 8608cc374dSBram Moolenaar call assert_equal('# goood', cnt[0]) 8708cc374dSBram Moolenaar call assert_equal('2 goood/!', cnt[1]) 8808cc374dSBram Moolenaar 8908cc374dSBram Moolenaar " Test for zuW 9008cc374dSBram Moolenaar let a=execute('unsilent norm! V$zuW') 9108cc374dSBram Moolenaar call assert_match("Word '2 goood' removed from .*", a) 9208cc374dSBram Moolenaar let cnt=readfile(fname) 9308cc374dSBram Moolenaar call assert_equal('# goood', cnt[0]) 9408cc374dSBram Moolenaar call assert_equal('# goood/!', cnt[1]) 9508cc374dSBram Moolenaar 9608cc374dSBram Moolenaar " Test for zuG 9708cc374dSBram Moolenaar let a=execute('unsilent norm! $zG') 9808cc374dSBram Moolenaar call assert_match("Word 'goood' added to .*", a) 9908cc374dSBram Moolenaar let cnt=readfile(fname) 10008cc374dSBram Moolenaar call assert_equal('# goood', cnt[0]) 10108cc374dSBram Moolenaar call assert_equal('# goood/!', cnt[1]) 10208cc374dSBram Moolenaar call assert_equal('goood', cnt[2]) 10308cc374dSBram Moolenaar let a=execute('unsilent norm! $zuG') 10408cc374dSBram Moolenaar let cnt=readfile(fname) 10508cc374dSBram Moolenaar call assert_match("Word 'goood' removed from .*", a) 10608cc374dSBram Moolenaar call assert_equal('# goood', cnt[0]) 10708cc374dSBram Moolenaar call assert_equal('# goood/!', cnt[1]) 10808cc374dSBram Moolenaar call assert_equal('#oood', cnt[2]) 10908cc374dSBram Moolenaar " word not found in wordlist 11008cc374dSBram Moolenaar let a=execute('unsilent norm! V$zuG') 11108cc374dSBram Moolenaar let cnt=readfile(fname) 11208cc374dSBram Moolenaar call assert_match("", a) 11308cc374dSBram Moolenaar call assert_equal('# goood', cnt[0]) 11408cc374dSBram Moolenaar call assert_equal('# goood/!', cnt[1]) 11508cc374dSBram Moolenaar call assert_equal('#oood', cnt[2]) 11608cc374dSBram Moolenaar 11708cc374dSBram Moolenaar " Test for zug 11808cc374dSBram Moolenaar call delete('./Xspellfile.add') 11908cc374dSBram Moolenaar 2 12008cc374dSBram Moolenaar let a=execute('unsilent norm! $zg') 12108cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 12208cc374dSBram Moolenaar call assert_equal('goood', cnt[0]) 12308cc374dSBram Moolenaar let a=execute('unsilent norm! $zug') 12408cc374dSBram Moolenaar call assert_match("Word 'goood' removed from \./Xspellfile.add", a) 12508cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 12608cc374dSBram Moolenaar call assert_equal('#oood', cnt[0]) 12708cc374dSBram Moolenaar " word not in wordlist 12808cc374dSBram Moolenaar let a=execute('unsilent norm! V$zug') 12908cc374dSBram Moolenaar call assert_match('', a) 13008cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 13108cc374dSBram Moolenaar call assert_equal('#oood', cnt[0]) 13208cc374dSBram Moolenaar 13308cc374dSBram Moolenaar " Test for zuw 13408cc374dSBram Moolenaar call delete('./Xspellfile.add') 13508cc374dSBram Moolenaar 2 13608cc374dSBram Moolenaar let a=execute('unsilent norm! Vzw') 13708cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 13808cc374dSBram Moolenaar call assert_equal('2 goood/!', cnt[0]) 13908cc374dSBram Moolenaar let a=execute('unsilent norm! Vzuw') 14008cc374dSBram Moolenaar call assert_match("Word '2 goood' removed from \./Xspellfile.add", a) 14108cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 14208cc374dSBram Moolenaar call assert_equal('# goood/!', cnt[0]) 14308cc374dSBram Moolenaar " word not in wordlist 14408cc374dSBram Moolenaar let a=execute('unsilent norm! $zug') 14508cc374dSBram Moolenaar call assert_match('', a) 14608cc374dSBram Moolenaar let cnt=readfile('./Xspellfile.add') 14708cc374dSBram Moolenaar call assert_equal('# goood/!', cnt[0]) 14808cc374dSBram Moolenaar 14908cc374dSBram Moolenaar " add second entry to spellfile setting 15008cc374dSBram Moolenaar set spellfile=./Xspellfile.add,./Xspellfile2.add 15108cc374dSBram Moolenaar call delete('./Xspellfile.add') 15208cc374dSBram Moolenaar 2 15308cc374dSBram Moolenaar let a=execute('unsilent norm! $2zg') 15408cc374dSBram Moolenaar let cnt=readfile('./Xspellfile2.add') 15508cc374dSBram Moolenaar call assert_match("Word 'goood' added to ./Xspellfile2.add", a) 15608cc374dSBram Moolenaar call assert_equal('goood', cnt[0]) 15708cc374dSBram Moolenaar 15808cc374dSBram Moolenaar " Test for :spellgood! 15908cc374dSBram Moolenaar let temp = execute(':spe!0/0') 16008cc374dSBram Moolenaar call assert_match('Invalid region', temp) 16108cc374dSBram Moolenaar let spellfile = matchstr(temp, 'Invalid region nr in \zs.*\ze line \d: 0') 16208cc374dSBram Moolenaar call assert_equal(['# goood', '# goood/!', '#oood', '0/0'], readfile(spellfile)) 16308cc374dSBram Moolenaar 16408cc374dSBram Moolenaar " Test for :spellrare! 16508cc374dSBram Moolenaar :spellrare! raare 16608cc374dSBram Moolenaar call assert_equal(['# goood', '# goood/!', '#oood', '0/0', 'raare/?'], readfile(spellfile)) 16708cc374dSBram Moolenaar call delete(spellfile) 16808cc374dSBram Moolenaar 16908cc374dSBram Moolenaar " clean up 17008cc374dSBram Moolenaar exe "lang" oldlang 17108cc374dSBram Moolenaar call delete("./Xspellfile.add") 17208cc374dSBram Moolenaar call delete("./Xspellfile2.add") 17308cc374dSBram Moolenaar call delete("./Xspellfile.add.spl") 17408cc374dSBram Moolenaar call delete("./Xspellfile2.add.spl") 17508cc374dSBram Moolenaar 17608cc374dSBram Moolenaar " zux -> no-op 17708cc374dSBram Moolenaar 2 17808cc374dSBram Moolenaar norm! $zux 17908cc374dSBram Moolenaar call assert_equal([], glob('Xspellfile.add',0,1)) 18008cc374dSBram Moolenaar call assert_equal([], glob('Xspellfile2.add',0,1)) 18108cc374dSBram Moolenaar 182c0f8823eSBram Moolenaar set spellfile= spell& spelllang& 18308cc374dSBram Moolenaar bw! 18408cc374dSBram Moolenaarendfunc 1856d91bcb4SBram Moolenaar 186fc2a47ffSBram Moolenaar" Spell file content test. Write 'content' to the spell file prefixed by the 187fc2a47ffSBram Moolenaar" spell file header and then enable spell checking. If 'emsg' is not empty, 188fc2a47ffSBram Moolenaar" then check for error. 189fc2a47ffSBram Moolenaarfunc Spellfile_Test(content, emsg) 190fc2a47ffSBram Moolenaar let splfile = './Xtest/spell/Xtest.utf-8.spl' 191fc2a47ffSBram Moolenaar " Add the spell file header and version (VIMspell2) 192fc2a47ffSBram Moolenaar let v = 0z56494D7370656C6C32 + a:content 193fc2a47ffSBram Moolenaar call writefile(v, splfile, 'b') 19464e2db6dSBram Moolenaar 19564e2db6dSBram Moolenaar " 'encoding' is set before each test to clear the previously loaded suggest 19664e2db6dSBram Moolenaar " file from memory. 19764e2db6dSBram Moolenaar set encoding=utf-8 19864e2db6dSBram Moolenaar 199fc2a47ffSBram Moolenaar set runtimepath=./Xtest 200fc2a47ffSBram Moolenaar set spelllang=Xtest 201fc2a47ffSBram Moolenaar if a:emsg != '' 202fc2a47ffSBram Moolenaar call assert_fails('set spell', a:emsg) 203fc2a47ffSBram Moolenaar else 204fc2a47ffSBram Moolenaar " FIXME: With some invalid spellfile contents, there are no error 205fc2a47ffSBram Moolenaar " messages. So don't know how to check for the test result. 206fc2a47ffSBram Moolenaar set spell 207fc2a47ffSBram Moolenaar endif 208fc2a47ffSBram Moolenaar set nospell spelllang& rtp& 209fc2a47ffSBram Moolenaarendfunc 210fc2a47ffSBram Moolenaar 211fc2a47ffSBram Moolenaar" Test for spell file format errors. 212fc2a47ffSBram Moolenaar" The spell file format is described in spellfile.c 213c0f8823eSBram Moolenaarfunc Test_spellfile_format_error() 214c0f8823eSBram Moolenaar let save_rtp = &rtp 215c0f8823eSBram Moolenaar call mkdir('Xtest/spell', 'p') 216fc2a47ffSBram Moolenaar let splfile = './Xtest/spell/Xtest.utf-8.spl' 217c0f8823eSBram Moolenaar 218c0f8823eSBram Moolenaar " empty spell file 219fc2a47ffSBram Moolenaar call writefile([], splfile) 220c0f8823eSBram Moolenaar set runtimepath=./Xtest 221c0f8823eSBram Moolenaar set spelllang=Xtest 222c0f8823eSBram Moolenaar call assert_fails('set spell', 'E757:') 223c0f8823eSBram Moolenaar set nospell spelllang& 224c0f8823eSBram Moolenaar 225c0f8823eSBram Moolenaar " invalid file ID 226fc2a47ffSBram Moolenaar call writefile(0z56494D, splfile, 'b') 227c0f8823eSBram Moolenaar set runtimepath=./Xtest 228c0f8823eSBram Moolenaar set spelllang=Xtest 229c0f8823eSBram Moolenaar call assert_fails('set spell', 'E757:') 230c0f8823eSBram Moolenaar set nospell spelllang& 231c0f8823eSBram Moolenaar 232c0f8823eSBram Moolenaar " missing version number 233fc2a47ffSBram Moolenaar call writefile(0z56494D7370656C6C, splfile, 'b') 234c0f8823eSBram Moolenaar set runtimepath=./Xtest 235c0f8823eSBram Moolenaar set spelllang=Xtest 236c0f8823eSBram Moolenaar call assert_fails('set spell', 'E771:') 237c0f8823eSBram Moolenaar set nospell spelllang& 238c0f8823eSBram Moolenaar 239c0f8823eSBram Moolenaar " invalid version number 240fc2a47ffSBram Moolenaar call writefile(0z56494D7370656C6C7A, splfile, 'b') 241c0f8823eSBram Moolenaar set runtimepath=./Xtest 242c0f8823eSBram Moolenaar set spelllang=Xtest 243c0f8823eSBram Moolenaar call assert_fails('set spell', 'E772:') 244c0f8823eSBram Moolenaar set nospell spelllang& 245c0f8823eSBram Moolenaar 246c0f8823eSBram Moolenaar " no sections 247fc2a47ffSBram Moolenaar call Spellfile_Test(0z, 'E758:') 248c0f8823eSBram Moolenaar 249c0f8823eSBram Moolenaar " missing section length 250fc2a47ffSBram Moolenaar call Spellfile_Test(0z00, 'E758:') 251c0f8823eSBram Moolenaar 252c0f8823eSBram Moolenaar " unsupported required section 253fc2a47ffSBram Moolenaar call Spellfile_Test(0z7A0100000004, 'E770:') 254c0f8823eSBram Moolenaar 255c0f8823eSBram Moolenaar " unsupported not-required section 256fc2a47ffSBram Moolenaar call Spellfile_Test(0z7A0000000004, 'E758:') 257c0f8823eSBram Moolenaar 258c0f8823eSBram Moolenaar " SN_REGION: invalid number of region names 259fc2a47ffSBram Moolenaar call Spellfile_Test(0z0000000000FF, 'E759:') 260c0f8823eSBram Moolenaar 261c0f8823eSBram Moolenaar " SN_CHARFLAGS: missing <charflagslen> length 262fc2a47ffSBram Moolenaar call Spellfile_Test(0z010000000004, 'E758:') 263c0f8823eSBram Moolenaar 264c0f8823eSBram Moolenaar " SN_CHARFLAGS: invalid <charflagslen> length 265fc2a47ffSBram Moolenaar call Spellfile_Test(0z0100000000010201, '') 266c0f8823eSBram Moolenaar 267c0f8823eSBram Moolenaar " SN_CHARFLAGS: charflagslen == 0 and folcharslen != 0 268fc2a47ffSBram Moolenaar call Spellfile_Test(0z01000000000400000101, 'E759:') 269c0f8823eSBram Moolenaar 270c0f8823eSBram Moolenaar " SN_CHARFLAGS: missing <folcharslen> length 271fc2a47ffSBram Moolenaar call Spellfile_Test(0z01000000000100, 'E758:') 272c0f8823eSBram Moolenaar 273c0f8823eSBram Moolenaar " SN_PREFCOND: invalid prefcondcnt 274fc2a47ffSBram Moolenaar call Spellfile_Test(0z03000000000100, 'E759:') 275c0f8823eSBram Moolenaar 276c0f8823eSBram Moolenaar " SN_PREFCOND: invalid condlen 277fc2a47ffSBram Moolenaar call Spellfile_Test(0z0300000000020001, 'E759:') 278c0f8823eSBram Moolenaar 279c0f8823eSBram Moolenaar " SN_REP: invalid repcount 280fc2a47ffSBram Moolenaar call Spellfile_Test(0z04000000000100, 'E758:') 281c0f8823eSBram Moolenaar 282c0f8823eSBram Moolenaar " SN_REP: missing rep 283fc2a47ffSBram Moolenaar call Spellfile_Test(0z0400000000020004, 'E758:') 284c0f8823eSBram Moolenaar 285c0f8823eSBram Moolenaar " SN_REP: zero repfromlen 286fc2a47ffSBram Moolenaar call Spellfile_Test(0z040000000003000100, 'E759:') 287c0f8823eSBram Moolenaar 288c0f8823eSBram Moolenaar " SN_REP: invalid reptolen 289fc2a47ffSBram Moolenaar call Spellfile_Test(0z0400000000050001014101, '') 290c0f8823eSBram Moolenaar 291c0f8823eSBram Moolenaar " SN_REP: zero reptolen 292fc2a47ffSBram Moolenaar call Spellfile_Test(0z0400000000050001014100, 'E759:') 293fc2a47ffSBram Moolenaar 294fc2a47ffSBram Moolenaar " SN_SAL: missing salcount 295fc2a47ffSBram Moolenaar call Spellfile_Test(0z05000000000102, 'E758:') 296fc2a47ffSBram Moolenaar 297fc2a47ffSBram Moolenaar " SN_SAL: missing salfromlen 298fc2a47ffSBram Moolenaar call Spellfile_Test(0z050000000003080001, 'E758:') 299fc2a47ffSBram Moolenaar 300fc2a47ffSBram Moolenaar " SN_SAL: missing saltolen 301fc2a47ffSBram Moolenaar call Spellfile_Test(0z0500000000050400010161, 'E758:') 302fc2a47ffSBram Moolenaar 303fc2a47ffSBram Moolenaar " SN_WORDS: non-NUL terminated word 304fc2a47ffSBram Moolenaar call Spellfile_Test(0z0D000000000376696D, 'E758:') 305fc2a47ffSBram Moolenaar 306fc2a47ffSBram Moolenaar " SN_WORDS: very long word 307fc2a47ffSBram Moolenaar let v = eval('0z0D000000012C' .. repeat('41', 300)) 308fc2a47ffSBram Moolenaar call Spellfile_Test(v, 'E759:') 309fc2a47ffSBram Moolenaar 310fc2a47ffSBram Moolenaar " SN_SOFO: missing sofofromlen 311fc2a47ffSBram Moolenaar call Spellfile_Test(0z06000000000100, 'E758:') 312fc2a47ffSBram Moolenaar 313fc2a47ffSBram Moolenaar " SN_SOFO: missing sofotolen 314fc2a47ffSBram Moolenaar call Spellfile_Test(0z06000000000400016100, 'E758:') 315fc2a47ffSBram Moolenaar 316fc2a47ffSBram Moolenaar " SN_SOFO: missing sofoto 317fc2a47ffSBram Moolenaar call Spellfile_Test(0z0600000000050001610000, 'E759:') 318fc2a47ffSBram Moolenaar 31964e2db6dSBram Moolenaar " SN_SOFO: empty sofofrom and sofoto 32064e2db6dSBram Moolenaar call Spellfile_Test(0z06000000000400000000FF000000000000000000000000, '') 32164e2db6dSBram Moolenaar 32296fdf434SBram Moolenaar " SN_SOFO: multi-byte characters in sofofrom and sofoto 32396fdf434SBram Moolenaar call Spellfile_Test(0z0600000000080002CF810002CF82FF000000000000000000000000, '') 32496fdf434SBram Moolenaar 325fc2a47ffSBram Moolenaar " SN_COMPOUND: compmax is less than 2 326fc2a47ffSBram Moolenaar call Spellfile_Test(0z08000000000101, 'E759:') 327fc2a47ffSBram Moolenaar 328fc2a47ffSBram Moolenaar " SN_COMPOUND: missing compsylmax and other options 329fc2a47ffSBram Moolenaar call Spellfile_Test(0z0800000000020401, 'E759:') 330fc2a47ffSBram Moolenaar 331fc2a47ffSBram Moolenaar " SN_COMPOUND: missing compoptions 332fc2a47ffSBram Moolenaar call Spellfile_Test(0z080000000005040101, 'E758:') 333fc2a47ffSBram Moolenaar 33464e2db6dSBram Moolenaar " SN_COMPOUND: missing comppattern 33564e2db6dSBram Moolenaar call Spellfile_Test(0z08000000000704010100000001, 'E758:') 33664e2db6dSBram Moolenaar 33764e2db6dSBram Moolenaar " SN_COMPOUND: incorrect comppatlen 33864e2db6dSBram Moolenaar call Spellfile_Test(0z080000000007040101000000020165, 'E758:') 33964e2db6dSBram Moolenaar 340fc2a47ffSBram Moolenaar " SN_INFO: missing info 341fc2a47ffSBram Moolenaar call Spellfile_Test(0z0F0000000005040101, '') 342fc2a47ffSBram Moolenaar 343fc2a47ffSBram Moolenaar " SN_MIDWORD: missing midword 344fc2a47ffSBram Moolenaar call Spellfile_Test(0z0200000000040102, '') 345fc2a47ffSBram Moolenaar 346fc2a47ffSBram Moolenaar " SN_MAP: missing midword 347fc2a47ffSBram Moolenaar call Spellfile_Test(0z0700000000040102, '') 348fc2a47ffSBram Moolenaar 34964e2db6dSBram Moolenaar " SN_MAP: empty map string 35064e2db6dSBram Moolenaar call Spellfile_Test(0z070000000000FF000000000000000000000000, '') 35164e2db6dSBram Moolenaar 35264e2db6dSBram Moolenaar " SN_MAP: duplicate multibyte character 35364e2db6dSBram Moolenaar call Spellfile_Test(0z070000000004DC81DC81, 'E783:') 35464e2db6dSBram Moolenaar 355fc2a47ffSBram Moolenaar " SN_SYLLABLE: missing SYLLABLE item 356fc2a47ffSBram Moolenaar call Spellfile_Test(0z0900000000040102, '') 357fc2a47ffSBram Moolenaar 358fc2a47ffSBram Moolenaar " SN_SYLLABLE: More than SY_MAXLEN size 359fc2a47ffSBram Moolenaar let v = eval('0z090000000022612F' .. repeat('62', 32)) 360fc2a47ffSBram Moolenaar call Spellfile_Test(v, '') 361fc2a47ffSBram Moolenaar 362fc2a47ffSBram Moolenaar " LWORDTREE: missing 363fc2a47ffSBram Moolenaar call Spellfile_Test(0zFF, 'E758:') 364fc2a47ffSBram Moolenaar 365fc2a47ffSBram Moolenaar " LWORDTREE: missing tree node 366fc2a47ffSBram Moolenaar call Spellfile_Test(0zFF00000004, 'E758:') 367fc2a47ffSBram Moolenaar 368fc2a47ffSBram Moolenaar " LWORDTREE: missing tree node value 369fc2a47ffSBram Moolenaar call Spellfile_Test(0zFF0000000402, 'E758:') 370fc2a47ffSBram Moolenaar 37164e2db6dSBram Moolenaar " LWORDTREE: incorrect sibling node count 37264e2db6dSBram Moolenaar call Spellfile_Test(0zFF00000001040000000000000000, 'E759:') 37364e2db6dSBram Moolenaar 374fc2a47ffSBram Moolenaar " KWORDTREE: missing tree node 375fc2a47ffSBram Moolenaar call Spellfile_Test(0zFF0000000000000004, 'E758:') 376fc2a47ffSBram Moolenaar 377fc2a47ffSBram Moolenaar " PREFIXTREE: missing tree node 378fc2a47ffSBram Moolenaar call Spellfile_Test(0zFF000000000000000000000004, 'E758:') 379fc2a47ffSBram Moolenaar 38064e2db6dSBram Moolenaar " PREFIXTREE: incorrect prefcondnr 38164e2db6dSBram Moolenaar call Spellfile_Test(0zFF000000000000000000000002010200000020, 'E759:') 38264e2db6dSBram Moolenaar 38364e2db6dSBram Moolenaar " PREFIXTREE: invalid nodeidx 38464e2db6dSBram Moolenaar call Spellfile_Test(0zFF00000000000000000000000201010000, 'E759:') 38564e2db6dSBram Moolenaar 386fc2a47ffSBram Moolenaar let &rtp = save_rtp 387fc2a47ffSBram Moolenaar call delete('Xtest', 'rf') 388fc2a47ffSBram Moolenaarendfunc 389fc2a47ffSBram Moolenaar 390fc2a47ffSBram Moolenaar" Test for format errors in suggest file 391fc2a47ffSBram Moolenaarfunc Test_sugfile_format_error() 392fc2a47ffSBram Moolenaar let save_rtp = &rtp 393fc2a47ffSBram Moolenaar call mkdir('Xtest/spell', 'p') 394fc2a47ffSBram Moolenaar let splfile = './Xtest/spell/Xtest.utf-8.spl' 395fc2a47ffSBram Moolenaar let sugfile = './Xtest/spell/Xtest.utf-8.sug' 396fc2a47ffSBram Moolenaar 397fc2a47ffSBram Moolenaar " create an empty spell file with a suggest timestamp 398fc2a47ffSBram Moolenaar call writefile(0z56494D7370656C6C320B00000000080000000000000044FF000000000000000000000000, splfile, 'b') 399fc2a47ffSBram Moolenaar 400fc2a47ffSBram Moolenaar " 'encoding' is set before each test to clear the previously loaded suggest 401fc2a47ffSBram Moolenaar " file from memory. 402fc2a47ffSBram Moolenaar 403fc2a47ffSBram Moolenaar " empty suggest file 404fc2a47ffSBram Moolenaar set encoding=utf-8 405fc2a47ffSBram Moolenaar call writefile([], sugfile) 406c0f8823eSBram Moolenaar set runtimepath=./Xtest 407c0f8823eSBram Moolenaar set spelllang=Xtest 408fc2a47ffSBram Moolenaar set spell 409fc2a47ffSBram Moolenaar call assert_fails("let s = spellsuggest('abc')", 'E778:') 410fc2a47ffSBram Moolenaar set nospell spelllang& 411fc2a47ffSBram Moolenaar 412fc2a47ffSBram Moolenaar " zero suggest version 413fc2a47ffSBram Moolenaar set encoding=utf-8 414fc2a47ffSBram Moolenaar call writefile(0z56494D73756700, sugfile) 415fc2a47ffSBram Moolenaar set runtimepath=./Xtest 416fc2a47ffSBram Moolenaar set spelllang=Xtest 417fc2a47ffSBram Moolenaar set spell 418fc2a47ffSBram Moolenaar call assert_fails("let s = spellsuggest('abc')", 'E779:') 419fc2a47ffSBram Moolenaar set nospell spelllang& 420fc2a47ffSBram Moolenaar 421fc2a47ffSBram Moolenaar " unsupported suggest version 422fc2a47ffSBram Moolenaar set encoding=utf-8 423fc2a47ffSBram Moolenaar call writefile(0z56494D7375671F, sugfile) 424fc2a47ffSBram Moolenaar set runtimepath=./Xtest 425fc2a47ffSBram Moolenaar set spelllang=Xtest 426fc2a47ffSBram Moolenaar set spell 427fc2a47ffSBram Moolenaar call assert_fails("let s = spellsuggest('abc')", 'E780:') 428fc2a47ffSBram Moolenaar set nospell spelllang& 429fc2a47ffSBram Moolenaar 430fc2a47ffSBram Moolenaar " missing suggest timestamp 431fc2a47ffSBram Moolenaar set encoding=utf-8 432fc2a47ffSBram Moolenaar call writefile(0z56494D73756701, sugfile) 433fc2a47ffSBram Moolenaar set runtimepath=./Xtest 434fc2a47ffSBram Moolenaar set spelllang=Xtest 435fc2a47ffSBram Moolenaar set spell 436fc2a47ffSBram Moolenaar call assert_fails("let s = spellsuggest('abc')", 'E781:') 437fc2a47ffSBram Moolenaar set nospell spelllang& 438fc2a47ffSBram Moolenaar 439fc2a47ffSBram Moolenaar " incorrect suggest timestamp 440fc2a47ffSBram Moolenaar set encoding=utf-8 441fc2a47ffSBram Moolenaar call writefile(0z56494D7375670100000000000000FF, sugfile) 442fc2a47ffSBram Moolenaar set runtimepath=./Xtest 443fc2a47ffSBram Moolenaar set spelllang=Xtest 444fc2a47ffSBram Moolenaar set spell 445fc2a47ffSBram Moolenaar call assert_fails("let s = spellsuggest('abc')", 'E781:') 446fc2a47ffSBram Moolenaar set nospell spelllang& 447fc2a47ffSBram Moolenaar 448fc2a47ffSBram Moolenaar " missing suggest wordtree 449fc2a47ffSBram Moolenaar set encoding=utf-8 450fc2a47ffSBram Moolenaar call writefile(0z56494D737567010000000000000044, sugfile) 451fc2a47ffSBram Moolenaar set runtimepath=./Xtest 452fc2a47ffSBram Moolenaar set spelllang=Xtest 453fc2a47ffSBram Moolenaar set spell 454fc2a47ffSBram Moolenaar call assert_fails("let s = spellsuggest('abc')", 'E782:') 455c0f8823eSBram Moolenaar set nospell spelllang& 456c0f8823eSBram Moolenaar 457b9fc192fSBram Moolenaar " invalid suggest word count in SUGTABLE 458b9fc192fSBram Moolenaar set encoding=utf-8 459b9fc192fSBram Moolenaar call writefile(0z56494D7375670100000000000000440000000022, sugfile) 460b9fc192fSBram Moolenaar set runtimepath=./Xtest 461b9fc192fSBram Moolenaar set spelllang=Xtest 462b9fc192fSBram Moolenaar set spell 463b9fc192fSBram Moolenaar call assert_fails("let s = spellsuggest('abc')", 'E782:') 464b9fc192fSBram Moolenaar set nospell spelllang& 465b9fc192fSBram Moolenaar 466b9fc192fSBram Moolenaar " missing sugline in SUGTABLE 467b9fc192fSBram Moolenaar set encoding=utf-8 468b9fc192fSBram Moolenaar call writefile(0z56494D7375670100000000000000440000000000000005, sugfile) 469b9fc192fSBram Moolenaar set runtimepath=./Xtest 470b9fc192fSBram Moolenaar set spelllang=Xtest 471b9fc192fSBram Moolenaar set spell 472b9fc192fSBram Moolenaar call assert_fails("let s = spellsuggest('abc')", 'E782:') 473b9fc192fSBram Moolenaar set nospell spelllang& 474b9fc192fSBram Moolenaar 475c0f8823eSBram Moolenaar let &rtp = save_rtp 476c0f8823eSBram Moolenaar call delete('Xtest', 'rf') 477c0f8823eSBram Moolenaarendfunc 478c0f8823eSBram Moolenaar 479fc2a47ffSBram Moolenaar" Test for using :mkspell to create a spell file from a list of words 480fc2a47ffSBram Moolenaarfunc Test_wordlist_dic() 481fc2a47ffSBram Moolenaar " duplicate encoding 482fc2a47ffSBram Moolenaar let lines =<< trim [END] 483fc2a47ffSBram Moolenaar # This is an example word list 484fc2a47ffSBram Moolenaar 485fc2a47ffSBram Moolenaar /encoding=latin1 486fc2a47ffSBram Moolenaar /encoding=latin1 487fc2a47ffSBram Moolenaar example 488fc2a47ffSBram Moolenaar [END] 489fc2a47ffSBram Moolenaar call writefile(lines, 'Xwordlist.dic') 490fc2a47ffSBram Moolenaar let output = execute('mkspell Xwordlist.spl Xwordlist.dic') 491fc2a47ffSBram Moolenaar call assert_match('Duplicate /encoding= line ignored in Xwordlist.dic line 4: /encoding=latin1', output) 492fc2a47ffSBram Moolenaar 493fc2a47ffSBram Moolenaar " multiple encoding for a word 494fc2a47ffSBram Moolenaar let lines =<< trim [END] 495fc2a47ffSBram Moolenaar example 496fc2a47ffSBram Moolenaar /encoding=latin1 497fc2a47ffSBram Moolenaar example 498fc2a47ffSBram Moolenaar [END] 499fc2a47ffSBram Moolenaar call writefile(lines, 'Xwordlist.dic') 500fc2a47ffSBram Moolenaar let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') 501fc2a47ffSBram Moolenaar call assert_match('/encoding= line after word ignored in Xwordlist.dic line 2: /encoding=latin1', output) 502fc2a47ffSBram Moolenaar 503fc2a47ffSBram Moolenaar " unsupported encoding for a word 504fc2a47ffSBram Moolenaar let lines =<< trim [END] 505fc2a47ffSBram Moolenaar /encoding=Xtest 506fc2a47ffSBram Moolenaar example 507fc2a47ffSBram Moolenaar [END] 508fc2a47ffSBram Moolenaar call writefile(lines, 'Xwordlist.dic') 509fc2a47ffSBram Moolenaar let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') 510fc2a47ffSBram Moolenaar call assert_match('Conversion in Xwordlist.dic not supported: from Xtest to utf-8', output) 511fc2a47ffSBram Moolenaar 512fc2a47ffSBram Moolenaar " duplicate region 513fc2a47ffSBram Moolenaar let lines =<< trim [END] 514fc2a47ffSBram Moolenaar /regions=usca 515fc2a47ffSBram Moolenaar /regions=usca 516fc2a47ffSBram Moolenaar example 517fc2a47ffSBram Moolenaar [END] 518fc2a47ffSBram Moolenaar call writefile(lines, 'Xwordlist.dic') 519fc2a47ffSBram Moolenaar let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') 520fc2a47ffSBram Moolenaar call assert_match('Duplicate /regions= line ignored in Xwordlist.dic line 2: regions=usca', output) 521fc2a47ffSBram Moolenaar 522fc2a47ffSBram Moolenaar " maximum regions 523fc2a47ffSBram Moolenaar let lines =<< trim [END] 524fc2a47ffSBram Moolenaar /regions=uscauscauscauscausca 525fc2a47ffSBram Moolenaar example 526fc2a47ffSBram Moolenaar [END] 527fc2a47ffSBram Moolenaar call writefile(lines, 'Xwordlist.dic') 528fc2a47ffSBram Moolenaar let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') 529fc2a47ffSBram Moolenaar call assert_match('Too many regions in Xwordlist.dic line 1: uscauscauscauscausca', output) 530fc2a47ffSBram Moolenaar 531fc2a47ffSBram Moolenaar " unsupported '/' value 532fc2a47ffSBram Moolenaar let lines =<< trim [END] 533fc2a47ffSBram Moolenaar /test=abc 534fc2a47ffSBram Moolenaar example 535fc2a47ffSBram Moolenaar [END] 536fc2a47ffSBram Moolenaar call writefile(lines, 'Xwordlist.dic') 537fc2a47ffSBram Moolenaar let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') 538fc2a47ffSBram Moolenaar call assert_match('/ line ignored in Xwordlist.dic line 1: /test=abc', output) 539fc2a47ffSBram Moolenaar 540fc2a47ffSBram Moolenaar " unsupported flag 541fc2a47ffSBram Moolenaar let lines =<< trim [END] 542fc2a47ffSBram Moolenaar example/+ 543fc2a47ffSBram Moolenaar [END] 544fc2a47ffSBram Moolenaar call writefile(lines, 'Xwordlist.dic') 545fc2a47ffSBram Moolenaar let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') 546fc2a47ffSBram Moolenaar call assert_match('Unrecognized flags in Xwordlist.dic line 1: +', output) 547fc2a47ffSBram Moolenaar 548fc2a47ffSBram Moolenaar " non-ascii word 549fc2a47ffSBram Moolenaar call writefile(["ʀʀ"], 'Xwordlist.dic') 550fc2a47ffSBram Moolenaar let output = execute('mkspell! -ascii Xwordlist.spl Xwordlist.dic') 551fc2a47ffSBram Moolenaar call assert_match('Ignored 1 words with non-ASCII characters', output) 552fc2a47ffSBram Moolenaar 55364e2db6dSBram Moolenaar " keep case of a word 55464e2db6dSBram Moolenaar let lines =<< trim [END] 55564e2db6dSBram Moolenaar example/= 55664e2db6dSBram Moolenaar [END] 55764e2db6dSBram Moolenaar call writefile(lines, 'Xwordlist.dic') 55864e2db6dSBram Moolenaar let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') 55964e2db6dSBram Moolenaar call assert_match('Compressed keep-case:', output) 56064e2db6dSBram Moolenaar 561fc2a47ffSBram Moolenaar call delete('Xwordlist.spl') 562fc2a47ffSBram Moolenaar call delete('Xwordlist.dic') 563fc2a47ffSBram Moolenaarendfunc 564fc2a47ffSBram Moolenaar 565fc2a47ffSBram Moolenaar" Test for the :mkspell command 566fc2a47ffSBram Moolenaarfunc Test_mkspell() 567fc2a47ffSBram Moolenaar call assert_fails('mkspell Xtest_us.spl', 'E751:') 56896fdf434SBram Moolenaar call assert_fails('mkspell Xtest.spl abc', 'E484:') 569fc2a47ffSBram Moolenaar call assert_fails('mkspell a b c d e f g h i j k', 'E754:') 570fc2a47ffSBram Moolenaar 57196fdf434SBram Moolenaar " create a .aff file but not the .dic file 57296fdf434SBram Moolenaar call writefile([], 'Xtest.aff') 57396fdf434SBram Moolenaar call assert_fails('mkspell Xtest.spl Xtest', 'E484:') 57496fdf434SBram Moolenaar call delete('Xtest.aff') 57596fdf434SBram Moolenaar 576fc2a47ffSBram Moolenaar call writefile([], 'Xtest.spl') 577fc2a47ffSBram Moolenaar call writefile([], 'Xtest.dic') 578fc2a47ffSBram Moolenaar call assert_fails('mkspell Xtest.spl Xtest.dic', 'E13:') 579fc2a47ffSBram Moolenaar call delete('Xtest.spl') 580fc2a47ffSBram Moolenaar call delete('Xtest.dic') 581fc2a47ffSBram Moolenaar 582fc2a47ffSBram Moolenaar call mkdir('Xtest.spl') 583fc2a47ffSBram Moolenaar call assert_fails('mkspell! Xtest.spl Xtest.dic', 'E17:') 584fc2a47ffSBram Moolenaar call delete('Xtest.spl', 'rf') 585fc2a47ffSBram Moolenaar 5865a6cfb3fSDominique Pelle " can't write the .spl file as its directory does not exist 5875a6cfb3fSDominique Pelle call writefile([], 'Xtest.aff') 5885a6cfb3fSDominique Pelle call writefile([], 'Xtest.dic') 5895a6cfb3fSDominique Pelle call assert_fails('mkspell DOES_NOT_EXIT/Xtest.spl Xtest.dic', 'E484:') 5905a6cfb3fSDominique Pelle call delete('Xtest.aff') 5915a6cfb3fSDominique Pelle call delete('Xtest.dic') 5925a6cfb3fSDominique Pelle 593fc2a47ffSBram Moolenaar call assert_fails('mkspell en en_US abc_xyz', 'E755:') 594fc2a47ffSBram Moolenaarendfunc 595fc2a47ffSBram Moolenaar 596c8ec5fe5SBram Moolenaar" Tests for :mkspell with a .dic and .aff file 597c8ec5fe5SBram Moolenaarfunc Test_aff_file_format_error() 598b9fc192fSBram Moolenaar " FIXME: For some reason, the :mkspell command below doesn't fail on the 599b9fc192fSBram Moolenaar " MS-Windows CI build. Disable this test on MS-Windows for now. 600b9fc192fSBram Moolenaar CheckNotMSWindows 601b9fc192fSBram Moolenaar 602c8ec5fe5SBram Moolenaar " No word count in .dic file 603c8ec5fe5SBram Moolenaar call writefile([], 'Xtest.dic') 604c8ec5fe5SBram Moolenaar call writefile([], 'Xtest.aff') 605c8ec5fe5SBram Moolenaar call assert_fails('mkspell! Xtest.spl Xtest', 'E760:') 606c8ec5fe5SBram Moolenaar 607b9fc192fSBram Moolenaar " create a .dic file for the tests below 608c8ec5fe5SBram Moolenaar call writefile(['1', 'work'], 'Xtest.dic') 609b9fc192fSBram Moolenaar 610b9fc192fSBram Moolenaar " Invalid encoding in .aff file 611c8ec5fe5SBram Moolenaar call writefile(['# comment', 'SET Xinvalidencoding'], 'Xtest.aff') 612c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 613c8ec5fe5SBram Moolenaar call assert_match('Conversion in Xtest.aff not supported: from xinvalidencoding', output) 614c8ec5fe5SBram Moolenaar 615c8ec5fe5SBram Moolenaar " Invalid flag in .aff file 616c8ec5fe5SBram Moolenaar call writefile(['FLAG xxx'], 'Xtest.aff') 617c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 618c8ec5fe5SBram Moolenaar call assert_match('Invalid value for FLAG in Xtest.aff line 1: xxx', output) 619c8ec5fe5SBram Moolenaar 620c8ec5fe5SBram Moolenaar " set FLAGS after using flag for an affix 621c8ec5fe5SBram Moolenaar call writefile(['SFX L Y 1', 'SFX L 0 re [^x]', 'FLAG long'], 'Xtest.aff') 622c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 623c8ec5fe5SBram Moolenaar call assert_match('FLAG after using flags in Xtest.aff line 3: long', output) 624c8ec5fe5SBram Moolenaar 625c8ec5fe5SBram Moolenaar " INFO in affix file 626c8ec5fe5SBram Moolenaar let save_encoding = &encoding 627c8ec5fe5SBram Moolenaar call mkdir('Xrtp/spell', 'p') 628c8ec5fe5SBram Moolenaar call writefile(['1', 'work'], 'Xrtp/spell/Xtest.dic') 629c8ec5fe5SBram Moolenaar call writefile(['NAME klingon', 'VERSION 1.4', 'AUTHOR Spock'], 630c8ec5fe5SBram Moolenaar \ 'Xrtp/spell/Xtest.aff') 631c8ec5fe5SBram Moolenaar silent mkspell! Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest 632c8ec5fe5SBram Moolenaar let save_rtp = &rtp 633c8ec5fe5SBram Moolenaar set runtimepath=./Xrtp 634c8ec5fe5SBram Moolenaar set spelllang=Xtest 635c8ec5fe5SBram Moolenaar set spell 636c8ec5fe5SBram Moolenaar let output = split(execute('spellinfo'), "\n") 637c8ec5fe5SBram Moolenaar call assert_equal("NAME klingon", output[1]) 638c8ec5fe5SBram Moolenaar call assert_equal("VERSION 1.4", output[2]) 639c8ec5fe5SBram Moolenaar call assert_equal("AUTHOR Spock", output[3]) 640c8ec5fe5SBram Moolenaar let &rtp = save_rtp 641c8ec5fe5SBram Moolenaar call delete('Xrtp', 'rf') 642c8ec5fe5SBram Moolenaar set spell& spelllang& spellfile& 643c8ec5fe5SBram Moolenaar %bw! 644c8ec5fe5SBram Moolenaar " 'encoding' must be set again to clear the spell file in memory 645c8ec5fe5SBram Moolenaar let &encoding = save_encoding 646c8ec5fe5SBram Moolenaar 647c8ec5fe5SBram Moolenaar " COMPOUNDFORBIDFLAG flag after PFX in an affix file 648c8ec5fe5SBram Moolenaar call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDFLAG c', 'COMPOUNDFORBIDFLAG x'], 649c8ec5fe5SBram Moolenaar \ 'Xtest.aff') 650c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 651c8ec5fe5SBram Moolenaar call assert_match('Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in Xtest.aff line 4', output) 652c8ec5fe5SBram Moolenaar 653c8ec5fe5SBram Moolenaar " COMPOUNDPERMITFLAG flag after PFX in an affix file 654c8ec5fe5SBram Moolenaar call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDPERMITFLAG c'], 655c8ec5fe5SBram Moolenaar \ 'Xtest.aff') 656c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 657c8ec5fe5SBram Moolenaar call assert_match('Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in Xtest.aff line 3', output) 658c8ec5fe5SBram Moolenaar 659c8ec5fe5SBram Moolenaar " Wrong COMPOUNDRULES flag value in an affix file 660c8ec5fe5SBram Moolenaar call writefile(['COMPOUNDRULES a'], 'Xtest.aff') 661c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 662c8ec5fe5SBram Moolenaar call assert_match('Wrong COMPOUNDRULES value in Xtest.aff line 1: a', output) 663c8ec5fe5SBram Moolenaar 664c8ec5fe5SBram Moolenaar " Wrong COMPOUNDWORDMAX flag value in an affix file 665c8ec5fe5SBram Moolenaar call writefile(['COMPOUNDWORDMAX 0'], 'Xtest.aff') 666c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 667c8ec5fe5SBram Moolenaar call assert_match('Wrong COMPOUNDWORDMAX value in Xtest.aff line 1: 0', output) 668c8ec5fe5SBram Moolenaar 669c8ec5fe5SBram Moolenaar " Wrong COMPOUNDMIN flag value in an affix file 670c8ec5fe5SBram Moolenaar call writefile(['COMPOUNDMIN 0'], 'Xtest.aff') 671c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 672c8ec5fe5SBram Moolenaar call assert_match('Wrong COMPOUNDMIN value in Xtest.aff line 1: 0', output) 673c8ec5fe5SBram Moolenaar 674c8ec5fe5SBram Moolenaar " Wrong COMPOUNDSYLMAX flag value in an affix file 675c8ec5fe5SBram Moolenaar call writefile(['COMPOUNDSYLMAX 0'], 'Xtest.aff') 676c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 677c8ec5fe5SBram Moolenaar call assert_match('Wrong COMPOUNDSYLMAX value in Xtest.aff line 1: 0', output) 678c8ec5fe5SBram Moolenaar 679c8ec5fe5SBram Moolenaar " Wrong CHECKCOMPOUNDPATTERN flag value in an affix file 680c8ec5fe5SBram Moolenaar call writefile(['CHECKCOMPOUNDPATTERN 0'], 'Xtest.aff') 681c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 682c8ec5fe5SBram Moolenaar call assert_match('Wrong CHECKCOMPOUNDPATTERN value in Xtest.aff line 1: 0', output) 683c8ec5fe5SBram Moolenaar 684bb162367SDominique Pelle " Both compounding and NOBREAK specified 685bb162367SDominique Pelle call writefile(['COMPOUNDFLAG c', 'NOBREAK'], 'Xtest.aff') 686bb162367SDominique Pelle let output = execute('mkspell! Xtest.spl Xtest') 687bb162367SDominique Pelle call assert_match('Warning: both compounding and NOBREAK specified', output) 688bb162367SDominique Pelle 689c8ec5fe5SBram Moolenaar " Duplicate affix entry in an affix file 690c8ec5fe5SBram Moolenaar call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L Y 1', 'PFX L 0 re x'], 691c8ec5fe5SBram Moolenaar \ 'Xtest.aff') 692c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 693c8ec5fe5SBram Moolenaar call assert_match('Duplicate affix in Xtest.aff line 3: L', output) 694c8ec5fe5SBram Moolenaar 695c8ec5fe5SBram Moolenaar " Duplicate affix entry in an affix file 696c8ec5fe5SBram Moolenaar call writefile(['PFX L Y 1', 'PFX L Y 1'], 'Xtest.aff') 697c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 698c8ec5fe5SBram Moolenaar call assert_match('Unrecognized or duplicate item in Xtest.aff line 2: PFX', output) 699c8ec5fe5SBram Moolenaar 700c8ec5fe5SBram Moolenaar " Different combining flags in an affix file 701c8ec5fe5SBram Moolenaar call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L N 1'], 'Xtest.aff') 702c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 703c8ec5fe5SBram Moolenaar call assert_match('Different combining flag in continued affix block in Xtest.aff line 3', output) 704c8ec5fe5SBram Moolenaar 705c8ec5fe5SBram Moolenaar " Try to reuse a affix used for BAD flag 706c8ec5fe5SBram Moolenaar call writefile(['BAD x', 'PFX x Y 1', 'PFX x 0 re x'], 'Xtest.aff') 707c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 708c8ec5fe5SBram Moolenaar call assert_match('Affix also used for BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST in Xtest.aff line 2: x', output) 709c8ec5fe5SBram Moolenaar 710c8ec5fe5SBram Moolenaar " Trailing characters in an affix entry 711c8ec5fe5SBram Moolenaar call writefile(['PFX L Y 1 Test', 'PFX L 0 re x'], 'Xtest.aff') 712c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 713c8ec5fe5SBram Moolenaar call assert_match('Trailing text in Xtest.aff line 1: Test', output) 714c8ec5fe5SBram Moolenaar 715c8ec5fe5SBram Moolenaar " Trailing characters in an affix entry 716c8ec5fe5SBram Moolenaar call writefile(['PFX L Y 1', 'PFX L 0 re x Test'], 'Xtest.aff') 717c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 718c8ec5fe5SBram Moolenaar call assert_match('Trailing text in Xtest.aff line 2: Test', output) 719c8ec5fe5SBram Moolenaar 720c8ec5fe5SBram Moolenaar " Incorrect combine flag in an affix entry 721c8ec5fe5SBram Moolenaar call writefile(['PFX L X 1', 'PFX L 0 re x'], 'Xtest.aff') 722c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 723c8ec5fe5SBram Moolenaar call assert_match('Expected Y or N in Xtest.aff line 1: X', output) 724c8ec5fe5SBram Moolenaar 725c8ec5fe5SBram Moolenaar " Invalid count for REP item 726c8ec5fe5SBram Moolenaar call writefile(['REP a'], 'Xtest.aff') 727c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 728c8ec5fe5SBram Moolenaar call assert_match('Expected REP(SAL) count in Xtest.aff line 1', output) 729c8ec5fe5SBram Moolenaar 730c8ec5fe5SBram Moolenaar " Trailing characters in REP item 731c8ec5fe5SBram Moolenaar call writefile(['REP 1', 'REP f ph test'], 'Xtest.aff') 732c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 733c8ec5fe5SBram Moolenaar call assert_match('Trailing text in Xtest.aff line 2: test', output) 734c8ec5fe5SBram Moolenaar 735c8ec5fe5SBram Moolenaar " Invalid count for MAP item 736c8ec5fe5SBram Moolenaar call writefile(['MAP a'], 'Xtest.aff') 737c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 738c8ec5fe5SBram Moolenaar call assert_match('Expected MAP count in Xtest.aff line 1', output) 739c8ec5fe5SBram Moolenaar 740c8ec5fe5SBram Moolenaar " Duplicate character in a MAP item 741c8ec5fe5SBram Moolenaar call writefile(['MAP 2', 'MAP xx', 'MAP yy'], 'Xtest.aff') 742c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 743c8ec5fe5SBram Moolenaar call assert_match('Duplicate character in MAP in Xtest.aff line 2', output) 744c8ec5fe5SBram Moolenaar 745c8ec5fe5SBram Moolenaar " Use COMPOUNDSYLMAX without SYLLABLE 746c8ec5fe5SBram Moolenaar call writefile(['COMPOUNDSYLMAX 2'], 'Xtest.aff') 747c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 748c8ec5fe5SBram Moolenaar call assert_match('COMPOUNDSYLMAX used without SYLLABLE', output) 749c8ec5fe5SBram Moolenaar 750c8ec5fe5SBram Moolenaar " Missing SOFOTO 751c8ec5fe5SBram Moolenaar call writefile(['SOFOFROM abcdef'], 'Xtest.aff') 752c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 753c8ec5fe5SBram Moolenaar call assert_match('Missing SOFOTO line in Xtest.aff', output) 754c8ec5fe5SBram Moolenaar 755b9fc192fSBram Moolenaar " Length of SOFOFROM and SOFOTO differ 756b9fc192fSBram Moolenaar call writefile(['SOFOFROM abcde', 'SOFOTO ABCD'], 'Xtest.aff') 757b9fc192fSBram Moolenaar call assert_fails('mkspell! Xtest.spl Xtest', 'E759:') 758b9fc192fSBram Moolenaar 759b9fc192fSBram Moolenaar " Both SAL and SOFOFROM/SOFOTO items 760b9fc192fSBram Moolenaar call writefile(['SOFOFROM abcd', 'SOFOTO ABCD', 'SAL CIA X'], 'Xtest.aff') 761b9fc192fSBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 762b9fc192fSBram Moolenaar call assert_match('Both SAL and SOFO lines in Xtest.aff', output) 763c8ec5fe5SBram Moolenaar 764c8ec5fe5SBram Moolenaar " use an alphabet flag when FLAG is num 765c8ec5fe5SBram Moolenaar call writefile(['FLAG num', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff') 766c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 767c8ec5fe5SBram Moolenaar call assert_match('Flag is not a number in Xtest.aff line 2: L', output) 768c8ec5fe5SBram Moolenaar 769c8ec5fe5SBram Moolenaar " use number and alphabet flag when FLAG is num 770c8ec5fe5SBram Moolenaar call writefile(['FLAG num', 'SFX 4f Y 1', 'SFX 4f 0 re [^x]'], 'Xtest.aff') 771c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 772c8ec5fe5SBram Moolenaar call assert_match('Affix name too long in Xtest.aff line 2: 4f', output) 773c8ec5fe5SBram Moolenaar 774c8ec5fe5SBram Moolenaar " use a single character flag when FLAG is long 775c8ec5fe5SBram Moolenaar call writefile(['FLAG long', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff') 776c8ec5fe5SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 777c8ec5fe5SBram Moolenaar call assert_match('Illegal flag in Xtest.aff line 2: L', output) 778c8ec5fe5SBram Moolenaar 77964e2db6dSBram Moolenaar " missing character in UPP entry. The character table is used only in a 78064e2db6dSBram Moolenaar " non-utf8 encoding 78164e2db6dSBram Moolenaar call writefile(['FOL abc', 'LOW abc', 'UPP A'], 'Xtest.aff') 78264e2db6dSBram Moolenaar let save_encoding = &encoding 78364e2db6dSBram Moolenaar set encoding=cp949 78464e2db6dSBram Moolenaar call assert_fails('mkspell! Xtest.spl Xtest', 'E761:') 78564e2db6dSBram Moolenaar let &encoding = save_encoding 78664e2db6dSBram Moolenaar 78764e2db6dSBram Moolenaar " character range doesn't match between FOL and LOW entries 78864e2db6dSBram Moolenaar call writefile(["FOL \u0102bc", 'LOW abc', 'UPP ABC'], 'Xtest.aff') 78964e2db6dSBram Moolenaar let save_encoding = &encoding 79064e2db6dSBram Moolenaar set encoding=cp949 79164e2db6dSBram Moolenaar call assert_fails('mkspell! Xtest.spl Xtest', 'E762:') 79264e2db6dSBram Moolenaar let &encoding = save_encoding 79364e2db6dSBram Moolenaar 79464e2db6dSBram Moolenaar " character range doesn't match between FOL and UPP entries 79564e2db6dSBram Moolenaar call writefile(["FOL \u0102bc", "LOW \u0102bc", 'UPP ABC'], 'Xtest.aff') 79664e2db6dSBram Moolenaar let save_encoding = &encoding 79764e2db6dSBram Moolenaar set encoding=cp949 79864e2db6dSBram Moolenaar call assert_fails('mkspell! Xtest.spl Xtest', 'E762:') 79964e2db6dSBram Moolenaar let &encoding = save_encoding 80064e2db6dSBram Moolenaar 80164e2db6dSBram Moolenaar " additional characters in LOW and UPP entries 80264e2db6dSBram Moolenaar call writefile(["FOL ab", "LOW abc", 'UPP ABC'], 'Xtest.aff') 80364e2db6dSBram Moolenaar let save_encoding = &encoding 80464e2db6dSBram Moolenaar set encoding=cp949 80564e2db6dSBram Moolenaar call assert_fails('mkspell! Xtest.spl Xtest', 'E761:') 80664e2db6dSBram Moolenaar let &encoding = save_encoding 80764e2db6dSBram Moolenaar 80896fdf434SBram Moolenaar " missing UPP entry 80996fdf434SBram Moolenaar call writefile(["FOL abc", "LOW abc"], 'Xtest.aff') 81096fdf434SBram Moolenaar let save_encoding = &encoding 81196fdf434SBram Moolenaar set encoding=cp949 81296fdf434SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 81396fdf434SBram Moolenaar call assert_match('Missing FOL/LOW/UPP line in Xtest.aff', output) 81496fdf434SBram Moolenaar let &encoding = save_encoding 81596fdf434SBram Moolenaar 816b9fc192fSBram Moolenaar " duplicate word in the .dic file 817b9fc192fSBram Moolenaar call writefile(['2', 'good', 'good', 'good'], 'Xtest.dic') 818b9fc192fSBram Moolenaar call writefile(['NAME vim'], 'Xtest.aff') 819b9fc192fSBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest') 820b9fc192fSBram Moolenaar call assert_match('First duplicate word in Xtest.dic line 3: good', output) 821b9fc192fSBram Moolenaar call assert_match('2 duplicate word(s) in Xtest.dic', output) 822b9fc192fSBram Moolenaar 82396fdf434SBram Moolenaar " use multiple .aff files with different values for COMPOUNDWORDMAX and 82496fdf434SBram Moolenaar " MIDWORD (number and string) 82596fdf434SBram Moolenaar call writefile(['1', 'world'], 'Xtest_US.dic') 82696fdf434SBram Moolenaar call writefile(['1', 'world'], 'Xtest_CA.dic') 82796fdf434SBram Moolenaar call writefile(["COMPOUNDWORDMAX 3", "MIDWORD '-"], 'Xtest_US.aff') 82896fdf434SBram Moolenaar call writefile(["COMPOUNDWORDMAX 4", "MIDWORD '="], 'Xtest_CA.aff') 82996fdf434SBram Moolenaar let output = execute('mkspell! Xtest.spl Xtest_US Xtest_CA') 83096fdf434SBram Moolenaar call assert_match('COMPOUNDWORDMAX value differs from what is used in another .aff file', output) 83196fdf434SBram Moolenaar call assert_match('MIDWORD value differs from what is used in another .aff file', output) 83296fdf434SBram Moolenaar call delete('Xtest_US.dic') 83396fdf434SBram Moolenaar call delete('Xtest_CA.dic') 83496fdf434SBram Moolenaar call delete('Xtest_US.aff') 83596fdf434SBram Moolenaar call delete('Xtest_CA.aff') 83696fdf434SBram Moolenaar 837c8ec5fe5SBram Moolenaar call delete('Xtest.dic') 838c8ec5fe5SBram Moolenaar call delete('Xtest.aff') 839c8ec5fe5SBram Moolenaar call delete('Xtest.spl') 840c8ec5fe5SBram Moolenaar call delete('Xtest.sug') 841c8ec5fe5SBram Moolenaarendfunc 842c8ec5fe5SBram Moolenaar 843fc2a47ffSBram Moolenaarfunc Test_spell_add_word() 844fc2a47ffSBram Moolenaar set spellfile= 845fc2a47ffSBram Moolenaar call assert_fails('spellgood abc', 'E764:') 846fc2a47ffSBram Moolenaar 847fc2a47ffSBram Moolenaar set spellfile=Xtest.utf-8.add 848fc2a47ffSBram Moolenaar call assert_fails('2spellgood abc', 'E765:') 849fc2a47ffSBram Moolenaar 850fc2a47ffSBram Moolenaar edit Xtest.utf-8.add 851fc2a47ffSBram Moolenaar call setline(1, 'sample') 852fc2a47ffSBram Moolenaar call assert_fails('spellgood abc', 'E139:') 853fc2a47ffSBram Moolenaar set spellfile& 854fc2a47ffSBram Moolenaar %bw! 855fc2a47ffSBram Moolenaarendfunc 856fc2a47ffSBram Moolenaar 8575a6cfb3fSDominique Pellefunc Test_spellfile_verbose() 8585a6cfb3fSDominique Pelle call writefile(['1', 'one'], 'XtestVerbose.dic') 8595a6cfb3fSDominique Pelle call writefile([], 'XtestVerbose.aff') 8605a6cfb3fSDominique Pelle mkspell! XtestVerbose-utf8.spl XtestVerbose 8615a6cfb3fSDominique Pelle set spell 8625a6cfb3fSDominique Pelle 8635a6cfb3fSDominique Pelle " First time: the spl file should be read. 8645a6cfb3fSDominique Pelle let a = execute('3verbose set spelllang=XtestVerbose-utf8.spl') 8655a6cfb3fSDominique Pelle call assert_match('Reading spell file "XtestVerbose-utf8.spl"', a) 8665a6cfb3fSDominique Pelle 8675a6cfb3fSDominique Pelle " Second time time: the spl file should not be read (already read). 8685a6cfb3fSDominique Pelle let a = execute('3verbose set spelllang=XtestVerbose-utf8.spl') 8695a6cfb3fSDominique Pelle call assert_notmatch('Reading spell file "XtestVerbose-utf8.spl"', a) 8705a6cfb3fSDominique Pelle 8715a6cfb3fSDominique Pelle set spell& spelllang& 8725a6cfb3fSDominique Pelle call delete('XtestVerbose.dic') 8735a6cfb3fSDominique Pelle call delete('XtestVerbose.aff') 8745a6cfb3fSDominique Pelle call delete('XtestVerbose-utf8.spl') 8755a6cfb3fSDominique Pelleendfunc 8765a6cfb3fSDominique Pelle 8775a6cfb3fSDominique Pelle" Test NOBREAK (see :help spell-NOBREAK) 8785a6cfb3fSDominique Pellefunc Test_NOBREAK() 8795a6cfb3fSDominique Pelle call writefile(['3', 'one', 'two', 'three' ], 'XtestNOBREAK.dic') 8805a6cfb3fSDominique Pelle call writefile(['NOBREAK' ], 'XtestNOBREAK.aff') 8815a6cfb3fSDominique Pelle 8825a6cfb3fSDominique Pelle mkspell! XtestNOBREAK-utf8.spl XtestNOBREAK 8835a6cfb3fSDominique Pelle set spell spelllang=XtestNOBREAK-utf8.spl 8845a6cfb3fSDominique Pelle 8855a6cfb3fSDominique Pelle call assert_equal(['', ''], spellbadword('One two three onetwo onetwothree threetwoone')) 8865a6cfb3fSDominique Pelle 8875a6cfb3fSDominique Pelle call assert_equal(['x', 'bad'], spellbadword('x')) 8885a6cfb3fSDominique Pelle call assert_equal(['y', 'bad'], spellbadword('yone')) 8895a6cfb3fSDominique Pelle call assert_equal(['z', 'bad'], spellbadword('onez')) 8905a6cfb3fSDominique Pelle call assert_equal(['zero', 'bad'], spellbadword('Onetwozerothree')) 8915a6cfb3fSDominique Pelle 892bb162367SDominique Pelle new 893bb162367SDominique Pelle call setline(1, 'Onetwwothree') 894bb162367SDominique Pelle norm! fw1z= 895bb162367SDominique Pelle call assert_equal('Onetwothree', getline(1)) 896bb162367SDominique Pelle call setline(1, 'Onetwothre') 897bb162367SDominique Pelle norm! fh1z= 898bb162367SDominique Pelle call assert_equal('Onetwothree', getline(1)) 899bb162367SDominique Pelle 900bb162367SDominique Pelle bw! 9015a6cfb3fSDominique Pelle set spell& spelllang& 9025a6cfb3fSDominique Pelle call delete('XtestNOBREAK.dic') 9035a6cfb3fSDominique Pelle call delete('XtestNOBREAK.aff') 9045a6cfb3fSDominique Pelle call delete('XtestNOBREAK-utf8.spl') 9055a6cfb3fSDominique Pelleendfunc 9065a6cfb3fSDominique Pelle 907dc3275a1SDominique Pelle" Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN) 908dc3275a1SDominique Pellefunc Test_spellfile_CHECKCOMPOUNDPATTERN() 909dc3275a1SDominique Pelle call writefile(['4', 910dc3275a1SDominique Pelle \ 'one/c', 911dc3275a1SDominique Pelle \ 'two/c', 912dc3275a1SDominique Pelle \ 'three/c', 913dc3275a1SDominique Pelle \ 'four'], 'XtestCHECKCOMPOUNDPATTERN.dic') 914dc3275a1SDominique Pelle " Forbid compound words where first word ends with 'wo' and second starts with 'on'. 915dc3275a1SDominique Pelle call writefile(['CHECKCOMPOUNDPATTERN 1', 916dc3275a1SDominique Pelle \ 'CHECKCOMPOUNDPATTERN wo on', 917dc3275a1SDominique Pelle \ 'COMPOUNDFLAG c'], 'XtestCHECKCOMPOUNDPATTERN.aff') 918dc3275a1SDominique Pelle 9195a6cfb3fSDominique Pelle mkspell! XtestCHECKCOMPOUNDPATTERN-utf8.spl XtestCHECKCOMPOUNDPATTERN 920dc3275a1SDominique Pelle set spell spelllang=XtestCHECKCOMPOUNDPATTERN-utf8.spl 921dc3275a1SDominique Pelle 922dc3275a1SDominique Pelle " Check valid words with and without valid compounds. 923dc3275a1SDominique Pelle for goodword in ['one', 'two', 'three', 'four', 924dc3275a1SDominique Pelle \ 'oneone', 'onetwo', 'onethree', 925dc3275a1SDominique Pelle \ 'twotwo', 'twothree', 926dc3275a1SDominique Pelle \ 'threeone', 'threetwo', 'threethree', 927dc3275a1SDominique Pelle \ 'onetwothree', 'onethreetwo', 'twothreeone', 'oneoneone'] 928dc3275a1SDominique Pelle call assert_equal(['', ''], spellbadword(goodword), goodword) 929dc3275a1SDominique Pelle endfor 930dc3275a1SDominique Pelle 931dc3275a1SDominique Pelle " Compounds 'twoone' or 'threetwoone' should be forbidden by CHECKCOMPOUNPATTERN. 932dc3275a1SDominique Pelle " 'four' does not have the 'c' flag in *.aff file so no compound. 933dc3275a1SDominique Pelle " 'five' is not in the *.dic file. 934dc3275a1SDominique Pelle for badword in ['five', 'onetwox', 935dc3275a1SDominique Pelle \ 'twoone', 'threetwoone', 936dc3275a1SDominique Pelle \ 'fourone', 'onefour'] 937dc3275a1SDominique Pelle call assert_equal([badword, 'bad'], spellbadword(badword)) 938dc3275a1SDominique Pelle endfor 939dc3275a1SDominique Pelle 940dc3275a1SDominique Pelle set spell& spelllang& 941dc3275a1SDominique Pelle call delete('XtestCHECKCOMPOUNDPATTERN.dic') 942dc3275a1SDominique Pelle call delete('XtestCHECKCOMPOUNDPATTERN.aff') 943dc3275a1SDominique Pelle call delete('XtestCHECKCOMPOUNDPATTERN-utf8.spl') 944dc3275a1SDominique Pelleendfunc 945dc3275a1SDominique Pelle 9469c9472ffSDominique Pelle" Test NOCOMPOUNDSUGS (see :help spell-NOCOMPOUNDSUGS) 9479c9472ffSDominique Pellefunc Test_spellfile_NOCOMPOUNDSUGS() 9489c9472ffSDominique Pelle call writefile(['3', 9499c9472ffSDominique Pelle \ 'one/c', 9509c9472ffSDominique Pelle \ 'two/c', 9519c9472ffSDominique Pelle \ 'three/c'], 'XtestNOCOMPOUNDSUGS.dic') 9529c9472ffSDominique Pelle 9539c9472ffSDominique Pelle " pass 0 tests without NOCOMPOUNDSUGS, pass 1 tests with NOCOMPOUNDSUGS 9549c9472ffSDominique Pelle for pass in [0, 1] 9559c9472ffSDominique Pelle if pass == 0 9569c9472ffSDominique Pelle call writefile(['COMPOUNDFLAG c'], 'XtestNOCOMPOUNDSUGS.aff') 9579c9472ffSDominique Pelle else 9589c9472ffSDominique Pelle call writefile(['NOCOMPOUNDSUGS', 9599c9472ffSDominique Pelle \ 'COMPOUNDFLAG c'], 'XtestNOCOMPOUNDSUGS.aff') 9609c9472ffSDominique Pelle endif 9619c9472ffSDominique Pelle 9629c9472ffSDominique Pelle mkspell! XtestNOCOMPOUNDSUGS-utf8.spl XtestNOCOMPOUNDSUGS 9639c9472ffSDominique Pelle set spell spelllang=XtestNOCOMPOUNDSUGS-utf8.spl 9649c9472ffSDominique Pelle 9659c9472ffSDominique Pelle for goodword in ['one', 'two', 'three', 9669c9472ffSDominique Pelle \ 'oneone', 'onetwo', 'onethree', 9679c9472ffSDominique Pelle \ 'twoone', 'twotwo', 'twothree', 9689c9472ffSDominique Pelle \ 'threeone', 'threetwo', 'threethree', 9699c9472ffSDominique Pelle \ 'onetwothree', 'onethreetwo', 'twothreeone', 'oneoneone'] 9709c9472ffSDominique Pelle call assert_equal(['', ''], spellbadword(goodword), goodword) 9719c9472ffSDominique Pelle endfor 9729c9472ffSDominique Pelle 9739c9472ffSDominique Pelle for badword in ['four', 'onetwox', 'onexone'] 9749c9472ffSDominique Pelle call assert_equal([badword, 'bad'], spellbadword(badword)) 9759c9472ffSDominique Pelle endfor 9769c9472ffSDominique Pelle 9779c9472ffSDominique Pelle if pass == 0 9789c9472ffSDominique Pelle call assert_equal(['one', 'oneone'], spellsuggest('onne', 2)) 9799c9472ffSDominique Pelle call assert_equal(['onethree', 'one three'], spellsuggest('onethre', 2)) 9809c9472ffSDominique Pelle else 9819c9472ffSDominique Pelle call assert_equal(['one', 'one one'], spellsuggest('onne', 2)) 9829c9472ffSDominique Pelle call assert_equal(['one three'], spellsuggest('onethre', 2)) 9839c9472ffSDominique Pelle endif 9849c9472ffSDominique Pelle endfor 9859c9472ffSDominique Pelle 9869c9472ffSDominique Pelle set spell& spelllang& 9879c9472ffSDominique Pelle call delete('XtestNOCOMPOUNDSUGS.dic') 9889c9472ffSDominique Pelle call delete('XtestNOCOMPOUNDSUGS.aff') 9899c9472ffSDominique Pelle call delete('XtestNOCOMPOUNDSUGS-utf8.spl') 9909c9472ffSDominique Pelleendfunc 9919c9472ffSDominique Pelle 992dc3275a1SDominique Pelle" Test COMMON (better suggestions with common words, see :help spell-COMMON) 993dc3275a1SDominique Pellefunc Test_spellfile_COMMON() 994dc3275a1SDominique Pelle call writefile(['7', 995dc3275a1SDominique Pelle \ 'and', 996dc3275a1SDominique Pelle \ 'ant', 997dc3275a1SDominique Pelle \ 'end', 998dc3275a1SDominique Pelle \ 'any', 999dc3275a1SDominique Pelle \ 'tee', 1000dc3275a1SDominique Pelle \ 'the', 1001dc3275a1SDominique Pelle \ 'ted'], 'XtestCOMMON.dic') 1002dc3275a1SDominique Pelle call writefile(['COMMON the and'], 'XtestCOMMON.aff') 1003dc3275a1SDominique Pelle 10045a6cfb3fSDominique Pelle mkspell! XtestCOMMON-utf8.spl XtestCOMMON 1005dc3275a1SDominique Pelle set spell spelllang=XtestCOMMON-utf8.spl 1006dc3275a1SDominique Pelle 1007dc3275a1SDominique Pelle " COMMON words 'and' and 'the' should be the top suggestions. 1008dc3275a1SDominique Pelle call assert_equal(['and', 'ant'], spellsuggest('anr', 2)) 1009dc3275a1SDominique Pelle call assert_equal(['and', 'end'], spellsuggest('ond', 2)) 1010dc3275a1SDominique Pelle call assert_equal(['the', 'ted'], spellsuggest('tha', 2)) 1011dc3275a1SDominique Pelle call assert_equal(['the', 'tee'], spellsuggest('dhe', 2)) 1012dc3275a1SDominique Pelle 1013dc3275a1SDominique Pelle set spell& spelllang& 1014dc3275a1SDominique Pelle call delete('XtestCOMMON.dic') 1015dc3275a1SDominique Pelle call delete('XtestCOMMON.aff') 1016dc3275a1SDominique Pelle call delete('XtestCOMMON-utf8.spl') 1017dc3275a1SDominique Pelleendfunc 1018dc3275a1SDominique Pelle 1019*bfb2bb16SDominique Pelle" Test NOSUGGEST (see :help spell-COMMON) 1020*bfb2bb16SDominique Pellefunc Test_spellfile_NOSUGGEST() 1021*bfb2bb16SDominique Pelle call writefile(['2', 'foo/X', 'fog'], 'XtestNOSUGGEST.dic') 1022*bfb2bb16SDominique Pelle call writefile(['NOSUGGEST X'], 'XtestNOSUGGEST.aff') 1023*bfb2bb16SDominique Pelle 1024*bfb2bb16SDominique Pelle mkspell! XtestNOSUGGEST-utf8.spl XtestNOSUGGEST 1025*bfb2bb16SDominique Pelle set spell spelllang=XtestNOSUGGEST-utf8.spl 1026*bfb2bb16SDominique Pelle 1027*bfb2bb16SDominique Pelle for goodword in ['foo', 'Foo', 'FOO', 'fog', 'Fog', 'FOG'] 1028*bfb2bb16SDominique Pelle call assert_equal(['', ''], spellbadword(goodword), goodword) 1029*bfb2bb16SDominique Pelle endfor 1030*bfb2bb16SDominique Pelle for badword in ['foO', 'fOO', 'fooo', 'foog', 'foofog', 'fogfoo'] 1031*bfb2bb16SDominique Pelle call assert_equal([badword, 'bad'], spellbadword(badword)) 1032*bfb2bb16SDominique Pelle endfor 1033*bfb2bb16SDominique Pelle 1034*bfb2bb16SDominique Pelle call assert_equal(['fog'], spellsuggest('fooo', 1)) 1035*bfb2bb16SDominique Pelle call assert_equal(['fog'], spellsuggest('fOo', 1)) 1036*bfb2bb16SDominique Pelle call assert_equal(['fog'], spellsuggest('foG', 1)) 1037*bfb2bb16SDominique Pelle call assert_equal(['fog'], spellsuggest('fogg', 1)) 1038*bfb2bb16SDominique Pelle 1039*bfb2bb16SDominique Pelle set spell& spelllang& 1040*bfb2bb16SDominique Pelle call delete('XtestNOSUGGEST.dic') 1041*bfb2bb16SDominique Pelle call delete('XtestNOSUGGEST.aff') 1042*bfb2bb16SDominique Pelle call delete('XtestNOSUGGEST-utf8.spl') 1043*bfb2bb16SDominique Pelleendfunc 1044*bfb2bb16SDominique Pelle 1045*bfb2bb16SDominique Pelle 10465a6cfb3fSDominique Pelle" Test CIRCUMFIX (see: :help spell-CIRCUMFIX) 10475a6cfb3fSDominique Pellefunc Test_spellfile_CIRCUMFIX() 10485a6cfb3fSDominique Pelle " Example taken verbatim from https://github.com/hunspell/hunspell/tree/master/tests 10495a6cfb3fSDominique Pelle call writefile(['1', 10505a6cfb3fSDominique Pelle \ 'nagy/C po:adj'], 'XtestCIRCUMFIX.dic') 10515a6cfb3fSDominique Pelle call writefile(['# circumfixes: ~ obligate prefix/suffix combinations', 10525a6cfb3fSDominique Pelle \ '# superlative in Hungarian: leg- (prefix) AND -bb (suffix)', 10535a6cfb3fSDominique Pelle \ '', 10545a6cfb3fSDominique Pelle \ 'CIRCUMFIX X', 10555a6cfb3fSDominique Pelle \ '', 10565a6cfb3fSDominique Pelle \ 'PFX A Y 1', 10575a6cfb3fSDominique Pelle \ 'PFX A 0 leg/X .', 10585a6cfb3fSDominique Pelle \ '', 10595a6cfb3fSDominique Pelle \ 'PFX B Y 1', 10605a6cfb3fSDominique Pelle \ 'PFX B 0 legesleg/X .', 10615a6cfb3fSDominique Pelle \ '', 10625a6cfb3fSDominique Pelle \ 'SFX C Y 3', 10635a6cfb3fSDominique Pelle \ 'SFX C 0 obb . is:COMPARATIVE', 10645a6cfb3fSDominique Pelle \ 'SFX C 0 obb/AX . is:SUPERLATIVE', 10655a6cfb3fSDominique Pelle \ 'SFX C 0 obb/BX . is:SUPERSUPERLATIVE'], 'XtestCIRCUMFIX.aff') 10665a6cfb3fSDominique Pelle 10675a6cfb3fSDominique Pelle mkspell! XtestCIRCUMFIX-utf8.spl XtestCIRCUMFIX 10685a6cfb3fSDominique Pelle set spell spelllang=XtestCIRCUMFIX-utf8.spl 10695a6cfb3fSDominique Pelle 10705a6cfb3fSDominique Pelle " From https://catalog.ldc.upenn.edu/docs/LDC2008T01/acta04.pdf: 10715a6cfb3fSDominique Pelle " Hungarian English 10725a6cfb3fSDominique Pelle " --------- ------- 10735a6cfb3fSDominique Pelle " nagy great 10745a6cfb3fSDominique Pelle " nagyobb greater 10755a6cfb3fSDominique Pelle " legnagyobb greatest 10765a6cfb3fSDominique Pelle " legeslegnagyob most greatest 10775a6cfb3fSDominique Pelle call assert_equal(['', ''], spellbadword('nagy nagyobb legnagyobb legeslegnagyobb')) 10785a6cfb3fSDominique Pelle 10795a6cfb3fSDominique Pelle for badword in ['legnagy', 'legeslegnagy', 'legobb', 'legeslegobb'] 10805a6cfb3fSDominique Pelle call assert_equal([badword, 'bad'], spellbadword(badword)) 10815a6cfb3fSDominique Pelle endfor 10825a6cfb3fSDominique Pelle 10835a6cfb3fSDominique Pelle set spell& spelllang& 10845a6cfb3fSDominique Pelle call delete('XtestCIRCUMFIX.dic') 10855a6cfb3fSDominique Pelle call delete('XtestCIRCUMFIX.aff') 10865a6cfb3fSDominique Pelle call delete('XtestCIRCUMFIX-utf8.spl') 10875a6cfb3fSDominique Pelleendfunc 10885a6cfb3fSDominique Pelle 1089bb162367SDominique Pelle" Test SFX that strips/chops characters 1090bb162367SDominique Pellefunc Test_spellfile_SFX_strip() 1091bb162367SDominique Pelle " Simplified conjugation of Italian verbs ending in -are (first conjugation). 1092bb162367SDominique Pelle call writefile(['SFX A Y 4', 1093bb162367SDominique Pelle \ 'SFX A are iamo [^icg]are', 1094bb162367SDominique Pelle \ 'SFX A are hiamo [cg]are', 1095bb162367SDominique Pelle \ 'SFX A re mo iare', 1096bb162367SDominique Pelle \ 'SFX A re vamo are'], 1097bb162367SDominique Pelle \ 'XtestSFX.aff') 1098bb162367SDominique Pelle " Examples of Italian verbs: 1099bb162367SDominique Pelle " - cantare = to sing 1100bb162367SDominique Pelle " - cercare = to search 1101bb162367SDominique Pelle " - odiare = to hate 1102bb162367SDominique Pelle call writefile(['3', 'cantare/A', 'cercare/A', 'odiare/A'], 'XtestSFX.dic') 1103bb162367SDominique Pelle 1104bb162367SDominique Pelle mkspell! XtestSFX-utf8.spl XtestSFX 1105bb162367SDominique Pelle set spell spelllang=XtestSFX-utf8.spl 1106bb162367SDominique Pelle 1107bb162367SDominique Pelle " To sing, we're singing, we were singing. 1108bb162367SDominique Pelle call assert_equal(['', ''], spellbadword('cantare cantiamo cantavamo')) 1109bb162367SDominique Pelle 1110bb162367SDominique Pelle " To search, we're searching, we were searching. 1111bb162367SDominique Pelle call assert_equal(['', ''], spellbadword('cercare cerchiamo cercavamo')) 1112bb162367SDominique Pelle 1113bb162367SDominique Pelle " To hate, we hate, we were hating. 1114bb162367SDominique Pelle call assert_equal(['', ''], spellbadword('odiare odiamo odiavamo')) 1115bb162367SDominique Pelle 1116bb162367SDominique Pelle for badword in ['canthiamo', 'cerciamo', 'cantarevamo', 'odiiamo'] 1117bb162367SDominique Pelle call assert_equal([badword, 'bad'], spellbadword(badword)) 1118bb162367SDominique Pelle endfor 1119bb162367SDominique Pelle 1120bb162367SDominique Pelle call assert_equal(['cantiamo'], spellsuggest('canthiamo', 1)) 1121bb162367SDominique Pelle call assert_equal(['cerchiamo'], spellsuggest('cerciamo', 1)) 1122bb162367SDominique Pelle call assert_equal(['cantavamo'], spellsuggest('cantarevamo', 1)) 1123bb162367SDominique Pelle call assert_equal(['odiamo'], spellsuggest('odiiamo', 1)) 1124bb162367SDominique Pelle 1125bb162367SDominique Pelle set spell& spelllang& 1126bb162367SDominique Pelle call delete('XtestSFX.dic') 1127bb162367SDominique Pelle call delete('XtestSFX.aff') 1128bb162367SDominique Pelle call delete('XtestSFX-utf8.spl') 1129bb162367SDominique Pelleendfunc 1130bb162367SDominique Pelle 1131c8ec5fe5SBram Moolenaar" When 'spellfile' is not set, adding a new good word will automatically set 1132c8ec5fe5SBram Moolenaar" the 'spellfile' 1133c8ec5fe5SBram Moolenaarfunc Test_init_spellfile() 1134c8ec5fe5SBram Moolenaar let save_rtp = &rtp 1135c8ec5fe5SBram Moolenaar let save_encoding = &encoding 1136c8ec5fe5SBram Moolenaar call mkdir('Xrtp/spell', 'p') 1137c8ec5fe5SBram Moolenaar call writefile(['vim'], 'Xrtp/spell/Xtest.dic') 1138c8ec5fe5SBram Moolenaar silent mkspell Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest.dic 1139c8ec5fe5SBram Moolenaar set runtimepath=./Xrtp 1140c8ec5fe5SBram Moolenaar set spelllang=Xtest 1141c8ec5fe5SBram Moolenaar set spell 1142c8ec5fe5SBram Moolenaar silent spellgood abc 1143c8ec5fe5SBram Moolenaar call assert_equal('./Xrtp/spell/Xtest.utf-8.add', &spellfile) 1144c8ec5fe5SBram Moolenaar call assert_equal(['abc'], readfile('Xrtp/spell/Xtest.utf-8.add')) 1145c8ec5fe5SBram Moolenaar call assert_true(filereadable('Xrtp/spell/Xtest.utf-8.spl')) 1146c8ec5fe5SBram Moolenaar set spell& spelllang& spellfile& 1147c8ec5fe5SBram Moolenaar call delete('Xrtp', 'rf') 1148c8ec5fe5SBram Moolenaar let &encoding = save_encoding 1149c8ec5fe5SBram Moolenaar let &rtp = save_rtp 1150c8ec5fe5SBram Moolenaar %bw! 1151c8ec5fe5SBram Moolenaarendfunc 1152c8ec5fe5SBram Moolenaar 1153b9fc192fSBram Moolenaar" Test for the 'mkspellmem' option 1154b9fc192fSBram Moolenaarfunc Test_mkspellmem_opt() 1155b9fc192fSBram Moolenaar call assert_fails('set mkspellmem=1000', 'E474:') 1156b9fc192fSBram Moolenaar call assert_fails('set mkspellmem=1000,', 'E474:') 1157b9fc192fSBram Moolenaar call assert_fails('set mkspellmem=1000,50', 'E474:') 1158b9fc192fSBram Moolenaar call assert_fails('set mkspellmem=1000,50,', 'E474:') 1159b9fc192fSBram Moolenaar call assert_fails('set mkspellmem=1000,50,10,', 'E474:') 1160b9fc192fSBram Moolenaar call assert_fails('set mkspellmem=1000,50,0', 'E474:') 1161b9fc192fSBram Moolenaarendfunc 1162b9fc192fSBram Moolenaar 11636d91bcb4SBram Moolenaar" vim: shiftwidth=2 sts=2 expandtab 1164