neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_spellfile.vim (40402B)


      1 " Test for commands that operate on the spellfile.
      2 
      3 source shared.vim
      4 source check.vim
      5 
      6 CheckFeature spell
      7 CheckFeature syntax
      8 
      9 func Test_spell_normal()
     10  new
     11  call append(0, ['1 good', '2 goood', '3 goood'])
     12  set spell spellfile=./Xspellfile.add spelllang=en
     13  let oldlang=v:lang
     14  lang C
     15 
     16  " Test for zg
     17  1
     18  norm! ]s
     19  call assert_equal('2 goood', getline('.'))
     20  norm! zg
     21  1
     22  let a=execute('unsilent :norm! ]s')
     23  call assert_equal('1 good', getline('.'))
     24  call assert_equal('search hit BOTTOM, continuing at TOP', a[1:])
     25  let cnt=readfile('./Xspellfile.add')
     26  call assert_equal('goood', cnt[0])
     27 
     28  " zg should fail in operator-pending mode
     29  call assert_beeps('norm! czg')
     30 
     31  " zg fails in visual mode when not able to get the visual text
     32  call assert_beeps('norm! ggVjzg')
     33  norm! V
     34 
     35  " zg fails for a non-identifier word
     36  call append(line('$'), '###')
     37  call assert_fails('norm! Gzg', 'E349:')
     38  $d
     39 
     40  " Test for zw
     41  2
     42  norm! $zw
     43  1
     44  norm! ]s
     45  call assert_equal('2 goood', getline('.'))
     46  let cnt=readfile('./Xspellfile.add')
     47  call assert_equal('#oood', cnt[0])
     48  call assert_equal('goood/!', cnt[1])
     49 
     50  " Test for :spellrare
     51  spellrare rare
     52  let cnt=readfile('./Xspellfile.add')
     53  call assert_equal(['#oood', 'goood/!', 'rare/?'], cnt)
     54 
     55  " Make sure :spellundo works for rare words.
     56  spellundo rare
     57  let cnt=readfile('./Xspellfile.add')
     58  call assert_equal(['#oood', 'goood/!', '#are/?'], cnt)
     59 
     60  " Test for zg in visual mode
     61  let a=execute('unsilent :norm! V$zg')
     62  call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
     63  1
     64  norm! ]s
     65  call assert_equal('3 goood', getline('.'))
     66  let cnt=readfile('./Xspellfile.add')
     67  call assert_equal('2 goood', cnt[3])
     68  " Remove "2 good" from spellfile
     69  2
     70  let a=execute('unsilent norm! V$zw')
     71  call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
     72  let cnt=readfile('./Xspellfile.add')
     73  call assert_equal('2 goood/!', cnt[4])
     74 
     75  " Test for zG
     76  let a=execute('unsilent norm! V$zG')
     77  call assert_match("Word '2 goood' added to .*", a)
     78  let fname=matchstr(a, 'to\s\+\zs\f\+$')
     79  let cnt=readfile(fname)
     80  call assert_equal('2 goood', cnt[0])
     81 
     82  " Test for zW
     83  let a=execute('unsilent norm! V$zW')
     84  call assert_match("Word '2 goood' added to .*", a)
     85  let cnt=readfile(fname)
     86  call assert_equal('# goood', cnt[0])
     87  call assert_equal('2 goood/!', cnt[1])
     88 
     89  " Test for zuW
     90  let a=execute('unsilent norm! V$zuW')
     91  call assert_match("Word '2 goood' removed from .*", a)
     92  let cnt=readfile(fname)
     93  call assert_equal('# goood', cnt[0])
     94  call assert_equal('# goood/!', cnt[1])
     95 
     96  " Test for zuG
     97  let a=execute('unsilent norm! $zG')
     98  call assert_match("Word 'goood' added to .*", a)
     99  let cnt=readfile(fname)
    100  call assert_equal('# goood', cnt[0])
    101  call assert_equal('# goood/!', cnt[1])
    102  call assert_equal('goood', cnt[2])
    103  let a=execute('unsilent norm! $zuG')
    104  let cnt=readfile(fname)
    105  call assert_match("Word 'goood' removed from .*", a)
    106  call assert_equal('# goood', cnt[0])
    107  call assert_equal('# goood/!', cnt[1])
    108  call assert_equal('#oood', cnt[2])
    109  " word not found in wordlist
    110  let a=execute('unsilent norm! V$zuG')
    111  let cnt=readfile(fname)
    112  call assert_match("", a)
    113  call assert_equal('# goood', cnt[0])
    114  call assert_equal('# goood/!', cnt[1])
    115  call assert_equal('#oood', cnt[2])
    116 
    117  " Test for zug
    118  call delete('./Xspellfile.add')
    119  2
    120  let a=execute('unsilent norm! $zg')
    121  let cnt=readfile('./Xspellfile.add')
    122  call assert_equal('goood', cnt[0])
    123  let a=execute('unsilent norm! $zug')
    124  call assert_match("Word 'goood' removed from \./Xspellfile.add", a)
    125  let cnt=readfile('./Xspellfile.add')
    126  call assert_equal('#oood', cnt[0])
    127  " word not in wordlist
    128  let a=execute('unsilent norm! V$zug')
    129  call assert_match('', a)
    130  let cnt=readfile('./Xspellfile.add')
    131  call assert_equal('#oood', cnt[0])
    132 
    133  " Test for zuw
    134  call delete('./Xspellfile.add')
    135  2
    136  let a=execute('unsilent norm! Vzw')
    137  let cnt=readfile('./Xspellfile.add')
    138  call assert_equal('2 goood/!', cnt[0])
    139  let a=execute('unsilent norm! Vzuw')
    140  call assert_match("Word '2 goood' removed from \./Xspellfile.add", a)
    141  let cnt=readfile('./Xspellfile.add')
    142  call assert_equal('# goood/!', cnt[0])
    143  " word not in wordlist
    144  let a=execute('unsilent norm! $zug')
    145  call assert_match('', a)
    146  let cnt=readfile('./Xspellfile.add')
    147  call assert_equal('# goood/!', cnt[0])
    148 
    149  " add second entry to spellfile setting
    150  set spellfile=./Xspellfile.add,./Xspellfile2.add
    151  call delete('./Xspellfile.add')
    152  2
    153  let a=execute('unsilent norm! $2zg')
    154  let cnt=readfile('./Xspellfile2.add')
    155  call assert_match("Word 'goood' added to ./Xspellfile2.add", a)
    156  call assert_equal('goood', cnt[0])
    157 
    158  " Test for :spellgood!
    159  let temp = execute(':spe!0/0')
    160  call assert_match('Invalid region', temp)
    161  let spellfile = matchstr(temp, 'Invalid region nr in \zs.*\ze line \d: 0')
    162  call assert_equal(['# goood', '# goood/!', '#oood', '0/0'], readfile(spellfile))
    163 
    164  " Test for :spellrare!
    165  :spellrare! raare
    166  call assert_equal(['# goood', '# goood/!', '#oood', '0/0', 'raare/?'], readfile(spellfile))
    167  call delete(spellfile)
    168 
    169  " clean up
    170  exe "lang" oldlang
    171  call delete("./Xspellfile.add")
    172  call delete("./Xspellfile2.add")
    173  call delete("./Xspellfile.add.spl")
    174  call delete("./Xspellfile2.add.spl")
    175 
    176  " zux -> no-op
    177  2
    178  norm! $zux
    179  call assert_equal([], glob('Xspellfile.add',0,1))
    180  call assert_equal([], glob('Xspellfile2.add',0,1))
    181 
    182  set spellfile= spell& spelllang&
    183  bw!
    184 endfunc
    185 
    186 " Spell file content test. Write 'content' to the spell file prefixed by the
    187 " spell file header and then enable spell checking. If 'emsg' is not empty,
    188 " then check for error.
    189 func Spellfile_Test(content, emsg)
    190  let splfile = './Xtest/spell/Xtest.utf-8.spl'
    191  " Add the spell file header and version (VIMspell2)
    192  let v = 0z56494D7370656C6C32 + a:content
    193  call writefile(v, splfile, 'b')
    194 
    195  " 'encoding' is set before each test to clear the previously loaded suggest
    196  " file from memory.
    197  set encoding=utf-8
    198 
    199  set runtimepath=./Xtest
    200  set spelllang=Xtest
    201  if a:emsg != ''
    202    call assert_fails('set spell', a:emsg)
    203  else
    204    " FIXME: With some invalid spellfile contents, there are no error
    205    " messages. So don't know how to check for the test result.
    206    set spell
    207  endif
    208  set nospell spelllang& rtp&
    209 endfunc
    210 
    211 " Test for spell file format errors.
    212 " The spell file format is described in spellfile.c
    213 func Test_spellfile_format_error()
    214  let save_rtp = &rtp
    215  call mkdir('Xtest/spell', 'pR')
    216  let splfile = './Xtest/spell/Xtest.utf-8.spl'
    217 
    218  " empty spell file
    219  call writefile([], splfile)
    220  set runtimepath=./Xtest
    221  set spelllang=Xtest
    222  call assert_fails('set spell', 'E757:')
    223  set nospell spelllang&
    224 
    225  " invalid file ID
    226  call writefile(0z56494D, splfile, 'b')
    227  set runtimepath=./Xtest
    228  set spelllang=Xtest
    229  call assert_fails('set spell', 'E757:')
    230  set nospell spelllang&
    231 
    232  " missing version number
    233  call writefile(0z56494D7370656C6C, splfile, 'b')
    234  set runtimepath=./Xtest
    235  set spelllang=Xtest
    236  call assert_fails('set spell', 'E771:')
    237  set nospell spelllang&
    238 
    239  " invalid version number
    240  call writefile(0z56494D7370656C6C7A, splfile, 'b')
    241  set runtimepath=./Xtest
    242  set spelllang=Xtest
    243  call assert_fails('set spell', 'E772:')
    244  set nospell spelllang&
    245 
    246  " no sections
    247  call Spellfile_Test(0z, 'E758:')
    248 
    249  " missing section length
    250  call Spellfile_Test(0z00, 'E758:')
    251 
    252  " unsupported required section
    253  call Spellfile_Test(0z7A0100000004, 'E770:')
    254 
    255  " unsupported not-required section
    256  call Spellfile_Test(0z7A0000000004, 'E758:')
    257 
    258  " SN_REGION: invalid number of region names
    259  call Spellfile_Test(0z0000000000FF, 'E759:')
    260 
    261  " SN_CHARFLAGS: missing <charflagslen> length
    262  call Spellfile_Test(0z010000000004, 'E758:')
    263 
    264  " SN_CHARFLAGS: invalid <charflagslen> length
    265  call Spellfile_Test(0z0100000000010201, '')
    266 
    267  " SN_CHARFLAGS: charflagslen == 0 and folcharslen != 0
    268  call Spellfile_Test(0z01000000000400000101, 'E759:')
    269 
    270  " SN_CHARFLAGS: missing <folcharslen> length
    271  call Spellfile_Test(0z01000000000100, 'E758:')
    272 
    273  " SN_PREFCOND: invalid prefcondcnt
    274  call Spellfile_Test(0z03000000000100, 'E759:')
    275 
    276  " SN_PREFCOND: invalid condlen
    277  call Spellfile_Test(0z0300000000020001, 'E759:')
    278 
    279  " SN_REP: invalid repcount
    280  call Spellfile_Test(0z04000000000100, 'E758:')
    281 
    282  " SN_REP: missing rep
    283  call Spellfile_Test(0z0400000000020004, 'E758:')
    284 
    285  " SN_REP: zero repfromlen
    286  call Spellfile_Test(0z040000000003000100, 'E759:')
    287 
    288  " SN_REP: invalid reptolen
    289  call Spellfile_Test(0z0400000000050001014101, '')
    290 
    291  " SN_REP: zero reptolen
    292  call Spellfile_Test(0z0400000000050001014100, 'E759:')
    293 
    294  " SN_SAL: missing salcount
    295  call Spellfile_Test(0z05000000000102, 'E758:')
    296 
    297  " SN_SAL: missing salfromlen
    298  call Spellfile_Test(0z050000000003080001, 'E758:')
    299 
    300  " SN_SAL: missing saltolen
    301  call Spellfile_Test(0z0500000000050400010161, 'E758:')
    302 
    303  " SN_WORDS: non-NUL terminated word
    304  call Spellfile_Test(0z0D000000000376696D, 'E758:')
    305 
    306  " SN_WORDS: very long word
    307  let v = eval('0z0D000000012C' .. repeat('41', 300))
    308  call Spellfile_Test(v, 'E759:')
    309 
    310  " SN_SOFO: missing sofofromlen
    311  call Spellfile_Test(0z06000000000100, 'E758:')
    312 
    313  " SN_SOFO: missing sofotolen
    314  call Spellfile_Test(0z06000000000400016100, 'E758:')
    315 
    316  " SN_SOFO: missing sofoto
    317  call Spellfile_Test(0z0600000000050001610000, 'E759:')
    318 
    319  " SN_SOFO: empty sofofrom and sofoto
    320  call Spellfile_Test(0z06000000000400000000FF000000000000000000000000, '')
    321 
    322  " SN_SOFO: multi-byte characters in sofofrom and sofoto
    323  call Spellfile_Test(0z0600000000080002CF810002CF82FF000000000000000000000000, '')
    324 
    325  " SN_COMPOUND: compmax is less than 2
    326  call Spellfile_Test(0z08000000000101, 'E759:')
    327 
    328  " SN_COMPOUND: missing compsylmax and other options
    329  call Spellfile_Test(0z0800000000020401, 'E759:')
    330 
    331  " SN_COMPOUND: missing compoptions
    332  call Spellfile_Test(0z080000000005040101, 'E758:')
    333 
    334  " SN_COMPOUND: missing comppattern
    335  call Spellfile_Test(0z08000000000704010100000001, 'E758:')
    336 
    337  " SN_COMPOUND: incorrect comppatlen
    338  call Spellfile_Test(0z080000000007040101000000020165, 'E758:')
    339 
    340  " SN_INFO: missing info
    341  call Spellfile_Test(0z0F0000000005040101, '')
    342 
    343  " SN_MIDWORD: missing midword
    344  call Spellfile_Test(0z0200000000040102, '')
    345 
    346  " SN_MAP: missing midword
    347  call Spellfile_Test(0z0700000000040102, '')
    348 
    349  " SN_MAP: empty map string
    350  call Spellfile_Test(0z070000000000FF000000000000000000000000, '')
    351 
    352  " SN_MAP: duplicate multibyte character
    353  call Spellfile_Test(0z070000000004DC81DC81, 'E783:')
    354 
    355  " SN_SYLLABLE: missing SYLLABLE item
    356  call Spellfile_Test(0z0900000000040102, '')
    357 
    358  " SN_SYLLABLE: More than SY_MAXLEN size
    359  let v = eval('0z090000000022612F' .. repeat('62', 32))
    360  call Spellfile_Test(v, '')
    361 
    362  " LWORDTREE: missing
    363  call Spellfile_Test(0zFF, 'E758:')
    364 
    365  " LWORDTREE: missing tree node
    366  call Spellfile_Test(0zFF00000004, 'E758:')
    367 
    368  " LWORDTREE: missing tree node value
    369  call Spellfile_Test(0zFF0000000402, 'E758:')
    370 
    371  " LWORDTREE: incorrect sibling node count
    372  call Spellfile_Test(0zFF00000001040000000000000000, 'E759:')
    373 
    374  " KWORDTREE: missing tree node
    375  call Spellfile_Test(0zFF0000000000000004, 'E758:')
    376 
    377  " PREFIXTREE: missing tree node
    378  call Spellfile_Test(0zFF000000000000000000000004, 'E758:')
    379 
    380  " PREFIXTREE: incorrect prefcondnr
    381  call Spellfile_Test(0zFF000000000000000000000002010200000020, 'E759:')
    382 
    383  " PREFIXTREE: invalid nodeidx
    384  call Spellfile_Test(0zFF00000000000000000000000201010000, 'E759:')
    385 
    386  let &rtp = save_rtp
    387 endfunc
    388 
    389 " Test for format errors in suggest file
    390 func Test_sugfile_format_error()
    391  let save_rtp = &rtp
    392  call mkdir('Xtest/spell', 'pR')
    393  let splfile = './Xtest/spell/Xtest.utf-8.spl'
    394  let sugfile = './Xtest/spell/Xtest.utf-8.sug'
    395 
    396  " create an empty spell file with a suggest timestamp
    397  call writefile(0z56494D7370656C6C320B00000000080000000000000044FF000000000000000000000000, splfile, 'b')
    398 
    399  " 'encoding' is set before each test to clear the previously loaded suggest
    400  " file from memory.
    401 
    402  " empty suggest file
    403  set encoding=utf-8
    404  call writefile([], sugfile)
    405  set runtimepath=./Xtest
    406  set spelllang=Xtest
    407  set spell
    408  call assert_fails("let s = spellsuggest('abc')", 'E778:')
    409  set nospell spelllang&
    410 
    411  " zero suggest version
    412  set encoding=utf-8
    413  call writefile(0z56494D73756700, sugfile)
    414  set runtimepath=./Xtest
    415  set spelllang=Xtest
    416  set spell
    417  call assert_fails("let s = spellsuggest('abc')", 'E779:')
    418  set nospell spelllang&
    419 
    420  " unsupported suggest version
    421  set encoding=utf-8
    422  call writefile(0z56494D7375671F, sugfile)
    423  set runtimepath=./Xtest
    424  set spelllang=Xtest
    425  set spell
    426  call assert_fails("let s = spellsuggest('abc')", 'E780:')
    427  set nospell spelllang&
    428 
    429  " missing suggest timestamp
    430  set encoding=utf-8
    431  call writefile(0z56494D73756701, sugfile)
    432  set runtimepath=./Xtest
    433  set spelllang=Xtest
    434  set spell
    435  call assert_fails("let s = spellsuggest('abc')", 'E781:')
    436  set nospell spelllang&
    437 
    438  " incorrect suggest timestamp
    439  set encoding=utf-8
    440  call writefile(0z56494D7375670100000000000000FF, sugfile)
    441  set runtimepath=./Xtest
    442  set spelllang=Xtest
    443  set spell
    444  call assert_fails("let s = spellsuggest('abc')", 'E781:')
    445  set nospell spelllang&
    446 
    447  " missing suggest wordtree
    448  set encoding=utf-8
    449  call writefile(0z56494D737567010000000000000044, sugfile)
    450  set runtimepath=./Xtest
    451  set spelllang=Xtest
    452  set spell
    453  call assert_fails("let s = spellsuggest('abc')", 'E782:')
    454  set nospell spelllang&
    455 
    456  " invalid suggest word count in SUGTABLE
    457  set encoding=utf-8
    458  call writefile(0z56494D7375670100000000000000440000000022, sugfile)
    459  set runtimepath=./Xtest
    460  set spelllang=Xtest
    461  set spell
    462  call assert_fails("let s = spellsuggest('abc')", 'E782:')
    463  set nospell spelllang&
    464 
    465  " missing sugline in SUGTABLE
    466  set encoding=utf-8
    467  call writefile(0z56494D7375670100000000000000440000000000000005, sugfile)
    468  set runtimepath=./Xtest
    469  set spelllang=Xtest
    470  set spell
    471  call assert_fails("let s = spellsuggest('abc')", 'E782:')
    472  set nospell spelllang&
    473 
    474  let &rtp = save_rtp
    475 endfunc
    476 
    477 " Test for using :mkspell to create a spell file from a list of words
    478 func Test_wordlist_dic()
    479  " duplicate encoding
    480  let lines =<< trim [END]
    481    # This is an example word list
    482 
    483    /encoding=latin1
    484    /encoding=latin1
    485    example
    486  [END]
    487  call writefile(lines, 'Xwordlist.dic', 'D')
    488  let output = execute('mkspell Xwordlist.spl Xwordlist.dic')
    489  call assert_match('Duplicate /encoding= line ignored in Xwordlist.dic line 4: /encoding=latin1', output)
    490 
    491  " multiple encoding for a word
    492  let lines =<< trim [END]
    493    example
    494    /encoding=latin1
    495    example
    496  [END]
    497  call writefile(lines, 'Xwordlist.dic')
    498  let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
    499  call assert_match('/encoding= line after word ignored in Xwordlist.dic line 2: /encoding=latin1', output)
    500 
    501  " unsupported encoding for a word
    502  let lines =<< trim [END]
    503    /encoding=Xtest
    504    example
    505  [END]
    506  call writefile(lines, 'Xwordlist.dic')
    507  let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
    508  call assert_match('Conversion in Xwordlist.dic not supported: from Xtest to utf-8', output)
    509 
    510  " duplicate region
    511  let lines =<< trim [END]
    512    /regions=usca
    513    /regions=usca
    514    example
    515  [END]
    516  call writefile(lines, 'Xwordlist.dic')
    517  let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
    518  call assert_match('Duplicate /regions= line ignored in Xwordlist.dic line 2: regions=usca', output)
    519 
    520  " maximum regions
    521  let lines =<< trim [END]
    522    /regions=uscauscauscauscausca
    523    example
    524  [END]
    525  call writefile(lines, 'Xwordlist.dic')
    526  let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
    527  call assert_match('Too many regions in Xwordlist.dic line 1: uscauscauscauscausca', output)
    528 
    529  " unsupported '/' value
    530  let lines =<< trim [END]
    531    /test=abc
    532    example
    533  [END]
    534  call writefile(lines, 'Xwordlist.dic')
    535  let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
    536  call assert_match('/ line ignored in Xwordlist.dic line 1: /test=abc', output)
    537 
    538  " unsupported flag
    539  let lines =<< trim [END]
    540    example/+
    541  [END]
    542  call writefile(lines, 'Xwordlist.dic')
    543  let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
    544  call assert_match('Unrecognized flags in Xwordlist.dic line 1: +', output)
    545 
    546  " non-ascii word
    547  call writefile(["ʀʀ"], 'Xwordlist.dic')
    548  let output = execute('mkspell! -ascii Xwordlist.spl Xwordlist.dic')
    549  call assert_match('Ignored 1 words with non-ASCII characters', output)
    550 
    551  " keep case of a word
    552  let lines =<< trim [END]
    553    example/=
    554  [END]
    555  call writefile(lines, 'Xwordlist.dic')
    556  let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
    557  call assert_match('Compressed keep-case:', output)
    558 
    559  call delete('Xwordlist.spl')
    560 endfunc
    561 
    562 " Test for the :mkspell command
    563 func Test_mkspell()
    564  call assert_fails('mkspell Xtest_us.spl', 'E751:')
    565  call assert_fails('mkspell Xtest.spl abc', 'E484:')
    566  call assert_fails('mkspell a b c d e f g h i j k', 'E754:')
    567 
    568  " create a .aff file but not the .dic file
    569  call writefile([], 'Xtest.aff')
    570  call assert_fails('mkspell Xtest.spl Xtest', 'E484:')
    571  call delete('Xtest.aff')
    572 
    573  call writefile([], 'Xtest.spl')
    574  call writefile([], 'Xtest.dic')
    575  call assert_fails('mkspell Xtest.spl Xtest.dic', 'E13:')
    576  call delete('Xtest.spl')
    577  call delete('Xtest.dic')
    578 
    579  call mkdir('Xtest.spl')
    580  call assert_fails('mkspell! Xtest.spl Xtest.dic', 'E17:')
    581  call delete('Xtest.spl', 'rf')
    582 
    583  " can't write the .spl file as its directory does not exist
    584  call writefile([], 'Xtest.aff')
    585  call writefile([], 'Xtest.dic')
    586  call assert_fails('mkspell DOES_NOT_EXIT/Xtest.spl Xtest.dic', 'E484:')
    587  call delete('Xtest.aff')
    588  call delete('Xtest.dic')
    589 
    590  call assert_fails('mkspell en en_US abc_xyz', 'E755:')
    591 endfunc
    592 
    593 " Tests for :mkspell with a .dic and .aff file
    594 func Test_aff_file_format_error()
    595  " FIXME: For some reason, the :mkspell command below doesn't fail on the
    596  " MS-Windows CI build. Disable this test on MS-Windows for now.
    597  CheckNotMSWindows
    598 
    599  " No word count in .dic file
    600  call writefile([], 'Xtest.dic', 'D')
    601  call writefile([], 'Xtest.aff', 'D')
    602  call assert_fails('mkspell! Xtest.spl Xtest', 'E760:')
    603 
    604  " create a .dic file for the tests below
    605  call writefile(['1', 'work'], 'Xtest.dic')
    606 
    607  " Invalid encoding in .aff file
    608  call writefile(['# comment', 'SET Xinvalidencoding'], 'Xtest.aff')
    609  let output = execute('mkspell! Xtest.spl Xtest')
    610  call assert_match('Conversion in Xtest.aff not supported: from xinvalidencoding', output)
    611 
    612  " Invalid flag in .aff file
    613  call writefile(['FLAG xxx'], 'Xtest.aff')
    614  let output = execute('mkspell! Xtest.spl Xtest')
    615  call assert_match('Invalid value for FLAG in Xtest.aff line 1: xxx', output)
    616 
    617  " set FLAGS after using flag for an affix
    618  call writefile(['SFX L Y 1', 'SFX L 0 re [^x]', 'FLAG long'], 'Xtest.aff')
    619  let output = execute('mkspell! Xtest.spl Xtest')
    620  call assert_match('FLAG after using flags in Xtest.aff line 3: long', output)
    621 
    622  " INFO in affix file
    623  let save_encoding = &encoding
    624  call mkdir('Xrtp/spell', 'p')
    625  call writefile(['1', 'work'], 'Xrtp/spell/Xtest.dic')
    626  call writefile(['NAME klingon', 'VERSION 1.4', 'AUTHOR Spock'],
    627        \ 'Xrtp/spell/Xtest.aff')
    628  silent mkspell! Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest
    629  let save_rtp = &rtp
    630  set runtimepath=./Xrtp
    631  set spelllang=Xtest
    632  set spell
    633  let output = split(execute('spellinfo'), "\n")
    634  call assert_equal("NAME klingon", output[1])
    635  call assert_equal("VERSION 1.4", output[2])
    636  call assert_equal("AUTHOR Spock", output[3])
    637  let &rtp = save_rtp
    638  call delete('Xrtp', 'rf')
    639  set spell& spelllang& spellfile&
    640  %bw!
    641  " 'encoding' must be set again to clear the spell file in memory
    642  let &encoding = save_encoding
    643 
    644  " COMPOUNDFORBIDFLAG flag after PFX in an affix file
    645  call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDFLAG c', 'COMPOUNDFORBIDFLAG x'],
    646        \ 'Xtest.aff')
    647  let output = execute('mkspell! Xtest.spl Xtest')
    648  call assert_match('Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in Xtest.aff line 4', output)
    649 
    650  " COMPOUNDPERMITFLAG flag after PFX in an affix file
    651  call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDPERMITFLAG c'],
    652        \ 'Xtest.aff')
    653  let output = execute('mkspell! Xtest.spl Xtest')
    654  call assert_match('Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in Xtest.aff line 3', output)
    655 
    656  " Wrong COMPOUNDRULES flag value in an affix file
    657  call writefile(['COMPOUNDRULES a'], 'Xtest.aff')
    658  let output = execute('mkspell! Xtest.spl Xtest')
    659  call assert_match('Wrong COMPOUNDRULES value in Xtest.aff line 1: a', output)
    660 
    661  " Wrong COMPOUNDWORDMAX flag value in an affix file
    662  call writefile(['COMPOUNDWORDMAX 0'], 'Xtest.aff')
    663  let output = execute('mkspell! Xtest.spl Xtest')
    664  call assert_match('Wrong COMPOUNDWORDMAX value in Xtest.aff line 1: 0', output)
    665 
    666  " Wrong COMPOUNDMIN flag value in an affix file
    667  call writefile(['COMPOUNDMIN 0'], 'Xtest.aff')
    668  let output = execute('mkspell! Xtest.spl Xtest')
    669  call assert_match('Wrong COMPOUNDMIN value in Xtest.aff line 1: 0', output)
    670 
    671  " Wrong COMPOUNDSYLMAX flag value in an affix file
    672  call writefile(['COMPOUNDSYLMAX 0'], 'Xtest.aff')
    673  let output = execute('mkspell! Xtest.spl Xtest')
    674  call assert_match('Wrong COMPOUNDSYLMAX value in Xtest.aff line 1: 0', output)
    675 
    676  " Wrong CHECKCOMPOUNDPATTERN flag value in an affix file
    677  call writefile(['CHECKCOMPOUNDPATTERN 0'], 'Xtest.aff')
    678  let output = execute('mkspell! Xtest.spl Xtest')
    679  call assert_match('Wrong CHECKCOMPOUNDPATTERN value in Xtest.aff line 1: 0', output)
    680 
    681  " Both compounding and NOBREAK specified
    682  call writefile(['COMPOUNDFLAG c', 'NOBREAK'], 'Xtest.aff')
    683  let output = execute('mkspell! Xtest.spl Xtest')
    684  call assert_match('Warning: both compounding and NOBREAK specified', output)
    685 
    686  " Duplicate affix entry in an affix file
    687  call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L Y 1', 'PFX L 0 re x'],
    688        \ 'Xtest.aff')
    689  let output = execute('mkspell! Xtest.spl Xtest')
    690  call assert_match('Duplicate affix in Xtest.aff line 3: L', output)
    691 
    692  " Duplicate affix entry in an affix file
    693  call writefile(['PFX L Y 1', 'PFX L Y 1'], 'Xtest.aff')
    694  let output = execute('mkspell! Xtest.spl Xtest')
    695  call assert_match('Unrecognized or duplicate item in Xtest.aff line 2: PFX', output)
    696 
    697  " Different combining flags in an affix file
    698  call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L N 1'], 'Xtest.aff')
    699  let output = execute('mkspell! Xtest.spl Xtest')
    700  call assert_match('Different combining flag in continued affix block in Xtest.aff line 3', output)
    701 
    702  " Try to reuse an affix used for BAD flag
    703  call writefile(['BAD x', 'PFX x Y 1', 'PFX x 0 re x'], 'Xtest.aff')
    704  let output = execute('mkspell! Xtest.spl Xtest')
    705  call assert_match('Affix also used for BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST in Xtest.aff line 2: x', output)
    706 
    707  " Trailing characters in an affix entry
    708  call writefile(['PFX L Y 1 Test', 'PFX L 0 re x'], 'Xtest.aff')
    709  let output = execute('mkspell! Xtest.spl Xtest')
    710  call assert_match('Trailing text in Xtest.aff line 1: Test', output)
    711 
    712  " Trailing characters in an affix entry
    713  call writefile(['PFX L Y 1', 'PFX L 0 re x Test'], 'Xtest.aff')
    714  let output = execute('mkspell! Xtest.spl Xtest')
    715  call assert_match('Trailing text in Xtest.aff line 2: Test', output)
    716 
    717  " Incorrect combine flag in an affix entry
    718  call writefile(['PFX L X 1', 'PFX L 0 re x'], 'Xtest.aff')
    719  let output = execute('mkspell! Xtest.spl Xtest')
    720  call assert_match('Expected Y or N in Xtest.aff line 1: X', output)
    721 
    722  " Invalid count for REP item
    723  call writefile(['REP a'], 'Xtest.aff')
    724  let output = execute('mkspell! Xtest.spl Xtest')
    725  call assert_match('Expected REP(SAL) count in Xtest.aff line 1', output)
    726 
    727  " Trailing characters in REP item
    728  call writefile(['REP 1', 'REP f ph test'], 'Xtest.aff')
    729  let output = execute('mkspell! Xtest.spl Xtest')
    730  call assert_match('Trailing text in Xtest.aff line 2: test', output)
    731 
    732  " Invalid count for MAP item
    733  call writefile(['MAP a'], 'Xtest.aff')
    734  let output = execute('mkspell! Xtest.spl Xtest')
    735  call assert_match('Expected MAP count in Xtest.aff line 1', output)
    736 
    737  " Duplicate character in a MAP item
    738  call writefile(['MAP 2', 'MAP xx', 'MAP yy'], 'Xtest.aff')
    739  let output = execute('mkspell! Xtest.spl Xtest')
    740  call assert_match('Duplicate character in MAP in Xtest.aff line 2', output)
    741 
    742  " Use COMPOUNDSYLMAX without SYLLABLE
    743  call writefile(['COMPOUNDSYLMAX 2'], 'Xtest.aff')
    744  let output = execute('mkspell! Xtest.spl Xtest')
    745  call assert_match('COMPOUNDSYLMAX used without SYLLABLE', output)
    746 
    747  " Missing SOFOTO
    748  call writefile(['SOFOFROM abcdef'], 'Xtest.aff')
    749  let output = execute('mkspell! Xtest.spl Xtest')
    750  call assert_match('Missing SOFOTO line in Xtest.aff', output)
    751 
    752  " Length of SOFOFROM and SOFOTO differ
    753  call writefile(['SOFOFROM abcde', 'SOFOTO ABCD'], 'Xtest.aff')
    754  call assert_fails('mkspell! Xtest.spl Xtest', 'E759:')
    755 
    756  " Both SAL and SOFOFROM/SOFOTO items
    757  call writefile(['SOFOFROM abcd', 'SOFOTO ABCD', 'SAL CIA X'], 'Xtest.aff')
    758  let output = execute('mkspell! Xtest.spl Xtest')
    759  call assert_match('Both SAL and SOFO lines in Xtest.aff', output)
    760 
    761  " use an alphabet flag when FLAG is num
    762  call writefile(['FLAG num', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff')
    763  let output = execute('mkspell! Xtest.spl Xtest')
    764  call assert_match('Flag is not a number in Xtest.aff line 2: L', output)
    765 
    766  " use number and alphabet flag when FLAG is num
    767  call writefile(['FLAG num', 'SFX 4f Y 1', 'SFX 4f 0 re [^x]'], 'Xtest.aff')
    768  let output = execute('mkspell! Xtest.spl Xtest')
    769  call assert_match('Affix name too long in Xtest.aff line 2: 4f', output)
    770 
    771  " use a single character flag when FLAG is long
    772  call writefile(['FLAG long', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff')
    773  let output = execute('mkspell! Xtest.spl Xtest')
    774  call assert_match('Illegal flag in Xtest.aff line 2: L', output)
    775 
    776  " Nvim: non-utf8 encoding not supported
    777  " " missing character in UPP entry. The character table is used only in a
    778  " " non-utf8 encoding
    779  " call writefile(['FOL abc', 'LOW abc', 'UPP A'], 'Xtest.aff')
    780  " let save_encoding = &encoding
    781  " set encoding=cp949
    782  " call assert_fails('mkspell! Xtest.spl Xtest', 'E761:')
    783  " let &encoding = save_encoding
    784  "
    785  " " character range doesn't match between FOL and LOW entries
    786  " call writefile(["FOL \u0102bc", 'LOW abc', 'UPP ABC'], 'Xtest.aff')
    787  " let save_encoding = &encoding
    788  " set encoding=cp949
    789  " call assert_fails('mkspell! Xtest.spl Xtest', 'E762:')
    790  " let &encoding = save_encoding
    791  "
    792  " " character range doesn't match between FOL and UPP entries
    793  " call writefile(["FOL \u0102bc", "LOW \u0102bc", 'UPP ABC'], 'Xtest.aff')
    794  " let save_encoding = &encoding
    795  " set encoding=cp949
    796  " call assert_fails('mkspell! Xtest.spl Xtest', 'E762:')
    797  " let &encoding = save_encoding
    798  "
    799  " " additional characters in LOW and UPP entries
    800  " call writefile(["FOL ab", "LOW abc", 'UPP ABC'], 'Xtest.aff')
    801  " let save_encoding = &encoding
    802  " set encoding=cp949
    803  " call assert_fails('mkspell! Xtest.spl Xtest', 'E761:')
    804  " let &encoding = save_encoding
    805  "
    806  " " missing UPP entry
    807  " call writefile(["FOL abc", "LOW abc"], 'Xtest.aff')
    808  " let save_encoding = &encoding
    809  " set encoding=cp949
    810  " let output = execute('mkspell! Xtest.spl Xtest')
    811  " call assert_match('Missing FOL/LOW/UPP line in Xtest.aff', output)
    812  " let &encoding = save_encoding
    813 
    814  " duplicate word in the .dic file
    815  call writefile(['2', 'good', 'good', 'good'], 'Xtest.dic')
    816  call writefile(['NAME vim'], 'Xtest.aff')
    817  let output = execute('mkspell! Xtest.spl Xtest')
    818  call assert_match('First duplicate word in Xtest.dic line 3: good', output)
    819  call assert_match('2 duplicate word(s) in Xtest.dic', output)
    820 
    821  " use multiple .aff files with different values for COMPOUNDWORDMAX and
    822  " MIDWORD (number and string)
    823  call writefile(['1', 'world'], 'Xtest_US.dic', 'D')
    824  call writefile(['1', 'world'], 'Xtest_CA.dic', 'D')
    825  call writefile(["COMPOUNDWORDMAX 3", "MIDWORD '-"], 'Xtest_US.aff', 'D')
    826  call writefile(["COMPOUNDWORDMAX 4", "MIDWORD '="], 'Xtest_CA.aff', 'D')
    827  let output = execute('mkspell! Xtest.spl Xtest_US Xtest_CA')
    828  call assert_match('COMPOUNDWORDMAX value differs from what is used in another .aff file', output)
    829  call assert_match('MIDWORD value differs from what is used in another .aff file', output)
    830 
    831  call delete('Xtest.spl')
    832  call delete('Xtest.sug')
    833 endfunc
    834 
    835 func Test_spell_add_word()
    836  set spellfile=
    837  call assert_fails('spellgood abc', 'E764:')
    838 
    839  set spellfile=Xtest.utf-8.add
    840  call assert_fails('2spellgood abc', 'E765:')
    841 
    842  edit Xtest.utf-8.add
    843  call setline(1, 'sample')
    844  call assert_fails('spellgood abc', 'E139:')
    845  set spellfile&
    846  %bw!
    847 endfunc
    848 
    849 func Test_spell_add_long_word()
    850  set spell spellfile=./Xspellfile.add spelllang=en
    851 
    852  let word = repeat('a', 9000)
    853  let v:errmsg = ''
    854  " Spell checking doesn't really work for such a long word,
    855  " but this should not cause an E1510 error.
    856  exe 'spellgood ' .. word
    857  call assert_equal('', v:errmsg)
    858  call assert_equal([word], readfile('./Xspellfile.add'))
    859 
    860  set spell& spellfile= spelllang& encoding=utf-8
    861  call delete('./Xspellfile.add')
    862  call delete('./Xspellfile.add.spl')
    863 endfunc
    864 
    865 func Test_spellfile_verbose()
    866  call writefile(['1', 'one'], 'XtestVerbose.dic', 'D')
    867  call writefile([], 'XtestVerbose.aff', 'D')
    868  mkspell! XtestVerbose-utf8.spl XtestVerbose
    869  set spell
    870 
    871  " First time: the spl file should be read.
    872  let a = execute('3verbose set spelllang=XtestVerbose-utf8.spl')
    873  call assert_match('Reading spell file "XtestVerbose-utf8.spl"', a)
    874 
    875  " Second time time: the spl file should not be read (already read).
    876  let a = execute('3verbose set spelllang=XtestVerbose-utf8.spl')
    877  call assert_notmatch('Reading spell file "XtestVerbose-utf8.spl"', a)
    878 
    879  set spell& spelllang&
    880  call delete('XtestVerbose-utf8.spl')
    881 endfunc
    882 
    883 " Test NOBREAK (see :help spell-NOBREAK)
    884 func Test_NOBREAK()
    885  call writefile(['3', 'one', 'two', 'three' ], 'XtestNOBREAK.dic', 'D')
    886  call writefile(['NOBREAK' ], 'XtestNOBREAK.aff', 'D')
    887 
    888  mkspell! XtestNOBREAK-utf8.spl XtestNOBREAK
    889  set spell spelllang=XtestNOBREAK-utf8.spl
    890 
    891  call assert_equal(['', ''], spellbadword('One two three onetwo onetwothree threetwoone'))
    892 
    893  call assert_equal(['x', 'bad'], spellbadword('x'))
    894  call assert_equal(['y', 'bad'], spellbadword('yone'))
    895  call assert_equal(['z', 'bad'], spellbadword('onez'))
    896  call assert_equal(['zero', 'bad'], spellbadword('Onetwozerothree'))
    897 
    898  new
    899  call setline(1, 'Onetwwothree')
    900  norm! fw1z=
    901  call assert_equal('Onetwothree', getline(1))
    902  call setline(1, 'Onetwothre')
    903  norm! fh1z=
    904  call assert_equal('Onetwothree', getline(1))
    905 
    906  bw!
    907  set spell& spelllang&
    908  call delete('XtestNOBREAK-utf8.spl')
    909 endfunc
    910 
    911 " Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN)
    912 func Test_spellfile_CHECKCOMPOUNDPATTERN()
    913  call writefile(['4',
    914        \         'one/c',
    915        \         'two/c',
    916        \         'three/c',
    917        \         'four'], 'XtestCHECKCOMPOUNDPATTERN.dic', 'D')
    918  " Forbid compound words where first word ends with 'wo' and second starts with 'on'.
    919  call writefile(['CHECKCOMPOUNDPATTERN 1',
    920        \         'CHECKCOMPOUNDPATTERN wo on',
    921        \         'COMPOUNDFLAG c'], 'XtestCHECKCOMPOUNDPATTERN.aff', 'D')
    922 
    923  mkspell! XtestCHECKCOMPOUNDPATTERN-utf8.spl XtestCHECKCOMPOUNDPATTERN
    924  set spell spelllang=XtestCHECKCOMPOUNDPATTERN-utf8.spl
    925 
    926  " Check valid words with and without valid compounds.
    927  for goodword in ['one', 'two', 'three', 'four',
    928        \          'oneone', 'onetwo',  'onethree',
    929        \          'twotwo', 'twothree',
    930        \          'threeone', 'threetwo', 'threethree',
    931        \          'onetwothree', 'onethreetwo', 'twothreeone', 'oneoneone']
    932    call assert_equal(['', ''], spellbadword(goodword), goodword)
    933  endfor
    934 
    935  " Compounds 'twoone' or 'threetwoone' should be forbidden by CHECKCOMPOUNPATTERN.
    936  " 'four' does not have the 'c' flag in *.aff file so no compound.
    937  " 'five' is not in the *.dic file.
    938  for badword in ['five', 'onetwox',
    939        \         'twoone', 'threetwoone',
    940        \         'fourone', 'onefour']
    941    call assert_equal([badword, 'bad'], spellbadword(badword))
    942  endfor
    943 
    944  set spell& spelllang&
    945  call delete('XtestCHECKCOMPOUNDPATTERN-utf8.spl')
    946 endfunc
    947 
    948 " Test NOCOMPOUNDSUGS (see :help spell-NOCOMPOUNDSUGS)
    949 func Test_spellfile_NOCOMPOUNDSUGS()
    950  call writefile(['3',
    951        \         'one/c',
    952        \         'two/c',
    953        \         'three/c'], 'XtestNOCOMPOUNDSUGS.dic', 'D')
    954 
    955  " pass 0 tests without NOCOMPOUNDSUGS, pass 1 tests with NOCOMPOUNDSUGS
    956  for pass in [0, 1]
    957    if pass == 0
    958      call writefile(['COMPOUNDFLAG c'], 'XtestNOCOMPOUNDSUGS.aff', 'D')
    959    else
    960      call writefile(['NOCOMPOUNDSUGS',
    961          \           'COMPOUNDFLAG c'], 'XtestNOCOMPOUNDSUGS.aff', 'D')
    962    endif
    963 
    964    mkspell! XtestNOCOMPOUNDSUGS-utf8.spl XtestNOCOMPOUNDSUGS
    965    set spell spelllang=XtestNOCOMPOUNDSUGS-utf8.spl
    966 
    967    for goodword in ['one', 'two', 'three',
    968          \          'oneone', 'onetwo',  'onethree',
    969          \          'twoone', 'twotwo', 'twothree',
    970          \          'threeone', 'threetwo', 'threethree',
    971          \          'onetwothree', 'onethreetwo', 'twothreeone', 'oneoneone']
    972      call assert_equal(['', ''], spellbadword(goodword), goodword)
    973    endfor
    974 
    975    for badword in ['four', 'onetwox', 'onexone']
    976      call assert_equal([badword, 'bad'], spellbadword(badword))
    977    endfor
    978 
    979    if pass == 0
    980      call assert_equal(['one', 'oneone'], spellsuggest('onne', 2))
    981      call assert_equal(['onethree', 'one three'], spellsuggest('onethre', 2))
    982    else
    983      call assert_equal(['one', 'one one'], spellsuggest('onne', 2))
    984      call assert_equal(['one three'], spellsuggest('onethre', 2))
    985    endif
    986  endfor
    987 
    988  set spell& spelllang&
    989  call delete('XtestNOCOMPOUNDSUGS-utf8.spl')
    990 endfunc
    991 
    992 " Test COMMON (better suggestions with common words, see :help spell-COMMON)
    993 func Test_spellfile_COMMON()
    994  call writefile(['7',
    995        \         'and',
    996        \         'ant',
    997        \         'end',
    998        \         'any',
    999        \         'tee',
   1000        \         'the',
   1001        \         'ted'], 'XtestCOMMON.dic', 'D')
   1002  call writefile(['COMMON the and'], 'XtestCOMMON.aff', 'D')
   1003 
   1004  mkspell! XtestCOMMON-utf8.spl XtestCOMMON
   1005  set spell spelllang=XtestCOMMON-utf8.spl
   1006 
   1007  " COMMON words 'and' and 'the' should be the top suggestions.
   1008  call assert_equal(['and', 'ant'], spellsuggest('anr', 2))
   1009  call assert_equal(['and', 'end'], spellsuggest('ond', 2))
   1010  call assert_equal(['the', 'ted'], spellsuggest('tha', 2))
   1011  call assert_equal(['the', 'tee'], spellsuggest('dhe', 2))
   1012 
   1013  set spell& spelllang&
   1014  call delete('XtestCOMMON-utf8.spl')
   1015 endfunc
   1016 
   1017 " Test NOSUGGEST (see :help spell-COMMON)
   1018 func Test_spellfile_NOSUGGEST()
   1019  call writefile(['2', 'foo/X', 'fog'], 'XtestNOSUGGEST.dic', 'D')
   1020  call writefile(['NOSUGGEST X'], 'XtestNOSUGGEST.aff', 'D')
   1021 
   1022  mkspell! XtestNOSUGGEST-utf8.spl XtestNOSUGGEST
   1023  set spell spelllang=XtestNOSUGGEST-utf8.spl
   1024 
   1025  for goodword in ['foo', 'Foo', 'FOO', 'fog', 'Fog', 'FOG']
   1026    call assert_equal(['', ''], spellbadword(goodword), goodword)
   1027  endfor
   1028  for badword in ['foO', 'fOO', 'fooo', 'foog', 'foofog', 'fogfoo']
   1029    call assert_equal([badword, 'bad'], spellbadword(badword))
   1030  endfor
   1031 
   1032  call assert_equal(['fog'], spellsuggest('fooo', 1))
   1033  call assert_equal(['fog'], spellsuggest('fOo', 1))
   1034  call assert_equal(['fog'], spellsuggest('foG', 1))
   1035  call assert_equal(['fog'], spellsuggest('fogg', 1))
   1036 
   1037  set spell& spelllang&
   1038  call delete('XtestNOSUGGEST-utf8.spl')
   1039 endfunc
   1040 
   1041 
   1042 " Test CIRCUMFIX (see: :help spell-CIRCUMFIX)
   1043 func Test_spellfile_CIRCUMFIX()
   1044  " Example taken verbatim from https://github.com/hunspell/hunspell/tree/master/tests
   1045  call writefile(['1',
   1046        \         'nagy/C	po:adj'], 'XtestCIRCUMFIX.dic', 'D')
   1047  call writefile(['# circumfixes: ~ obligate prefix/suffix combinations',
   1048        \         '# superlative in Hungarian: leg- (prefix) AND -bb (suffix)',
   1049        \         '',
   1050        \         'CIRCUMFIX X',
   1051        \         '',
   1052        \         'PFX A Y 1',
   1053        \         'PFX A 0 leg/X .',
   1054        \         '',
   1055        \         'PFX B Y 1',
   1056        \         'PFX B 0 legesleg/X .',
   1057        \         '',
   1058        \         'SFX C Y 3',
   1059        \         'SFX C 0 obb . is:COMPARATIVE',
   1060        \         'SFX C 0 obb/AX . is:SUPERLATIVE',
   1061        \         'SFX C 0 obb/BX . is:SUPERSUPERLATIVE'], 'XtestCIRCUMFIX.aff', 'D')
   1062 
   1063  mkspell! XtestCIRCUMFIX-utf8.spl XtestCIRCUMFIX
   1064  set spell spelllang=XtestCIRCUMFIX-utf8.spl
   1065 
   1066  " From https://catalog.ldc.upenn.edu/docs/LDC2008T01/acta04.pdf:
   1067  " Hungarian       English
   1068  " ---------       -------
   1069  " nagy            great
   1070  " nagyobb         greater
   1071  " legnagyobb      greatest
   1072  " legeslegnagyob  most greatest
   1073  call assert_equal(['', ''], spellbadword('nagy nagyobb legnagyobb legeslegnagyobb'))
   1074 
   1075  for badword in ['legnagy', 'legeslegnagy', 'legobb', 'legeslegobb']
   1076    call assert_equal([badword, 'bad'], spellbadword(badword))
   1077  endfor
   1078 
   1079  set spell& spelllang&
   1080  call delete('XtestCIRCUMFIX-utf8.spl')
   1081 endfunc
   1082 
   1083 " Test SFX that strips/chops characters
   1084 func Test_spellfile_SFX_strip()
   1085  " Simplified conjugation of Italian verbs ending in -are (first conjugation).
   1086  call writefile(['SFX A Y 4',
   1087        \         'SFX A are iamo [^icg]are',
   1088        \         'SFX A are hiamo [cg]are',
   1089        \         'SFX A re mo iare',
   1090        \         'SFX A re vamo are'],
   1091        \         'XtestSFX.aff', 'D')
   1092  " Examples of Italian verbs:
   1093  " - cantare = to sing
   1094  " - cercare = to search
   1095  " - odiare = to hate
   1096  call writefile(['3', 'cantare/A', 'cercare/A', 'odiare/A'], 'XtestSFX.dic', 'D')
   1097 
   1098  mkspell! XtestSFX-utf8.spl XtestSFX
   1099  set spell spelllang=XtestSFX-utf8.spl
   1100 
   1101  " To sing, we're singing, we were singing.
   1102  call assert_equal(['', ''], spellbadword('cantare cantiamo cantavamo'))
   1103 
   1104  " To search, we're searching, we were searching.
   1105  call assert_equal(['', ''], spellbadword('cercare cerchiamo cercavamo'))
   1106 
   1107  " To hate, we hate, we were hating.
   1108  call assert_equal(['', ''], spellbadword('odiare odiamo odiavamo'))
   1109 
   1110  for badword in ['canthiamo', 'cerciamo', 'cantarevamo', 'odiiamo']
   1111    call assert_equal([badword, 'bad'], spellbadword(badword))
   1112  endfor
   1113 
   1114  call assert_equal(['cantiamo'],  spellsuggest('canthiamo', 1))
   1115  call assert_equal(['cerchiamo'], spellsuggest('cerciamo', 1))
   1116  call assert_equal(['cantavamo'], spellsuggest('cantarevamo', 1))
   1117  call assert_equal(['odiamo'],    spellsuggest('odiiamo', 1))
   1118 
   1119  set spell& spelllang&
   1120  call delete('XtestSFX-utf8.spl')
   1121 endfunc
   1122 
   1123 " When 'spellfile' is not set, adding a new good word will automatically set
   1124 " the 'spellfile'
   1125 func Test_init_spellfile()
   1126  throw 'Skipped: Nvim defaults spellfile to stdpath("data")/spell/'
   1127  let save_rtp = &rtp
   1128  let save_encoding = &encoding
   1129  call mkdir('Xrtp/spell', 'pR')
   1130  call writefile(['vim'], 'Xrtp/spell/Xtest.dic')
   1131  silent mkspell Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest.dic
   1132  set runtimepath=./Xrtp
   1133  set spelllang=Xtest
   1134  set spell
   1135  silent spellgood abc
   1136  call assert_equal('./Xrtp/spell/Xtest.utf-8.add', &spellfile)
   1137  call assert_equal(['abc'], readfile('Xrtp/spell/Xtest.utf-8.add'))
   1138  call assert_true(filereadable('Xrtp/spell/Xtest.utf-8.spl'))
   1139 
   1140  set spell& spelllang& spellfile&
   1141  let &encoding = save_encoding
   1142  let &rtp = save_rtp
   1143  %bw!
   1144 endfunc
   1145 
   1146 " Test for the 'mkspellmem' option
   1147 func Test_mkspellmem_opt()
   1148  call assert_fails('set mkspellmem=1000', 'E474:')
   1149  call assert_fails('set mkspellmem=1000,', 'E474:')
   1150  call assert_fails('set mkspellmem=1000,50', 'E474:')
   1151  call assert_fails('set mkspellmem=1000,50,', 'E474:')
   1152  call assert_fails('set mkspellmem=1000,50,10,', 'E474:')
   1153  call assert_fails('set mkspellmem=1000,50,0', 'E474:')
   1154 endfunc
   1155 
   1156 " 'spellfile' accepts '@' on top of 'isfname'.
   1157 func Test_spellfile_allow_at_character()
   1158  call mkdir('Xtest/the foo@bar,dir', 'p')
   1159  let &spellfile = './Xtest/the foo@bar\,dir/Xspellfile.add'
   1160  let &spellfile = ''
   1161  call delete('Xtest', 'rf')
   1162 endfunc
   1163 
   1164 " this was using a NULL pointer
   1165 func Test_mkspell_empty_dic()
   1166  call writefile(['1'], 'XtestEmpty.dic', 'D')
   1167  call writefile(['SOFOFROM abcd', 'SOFOTO ABCD', 'SAL CIA X'], 'XtestEmpty.aff', 'D')
   1168  mkspell! XtestEmpty.spl XtestEmpty
   1169 
   1170  call delete('XtestEmpty.spl')
   1171 endfunc
   1172 
   1173 
   1174 " vim: shiftwidth=2 sts=2 expandtab