0
0
mirror of https://github.com/vim/vim.git synced 2025-07-24 10:45:12 -04:00

patch 8.2.1522: not enough test coverage for the spell file handling

Problem:    Not enough test coverage for the spell file handling.
Solution:   Add spell file tests. (Yegappan Lakshmanan, closes #6763)
This commit is contained in:
Bram Moolenaar 2020-08-24 20:28:56 +02:00
parent 07399e7f07
commit c8ec5fe56f
2 changed files with 225 additions and 0 deletions

View File

@ -510,6 +510,207 @@ func Test_mkspell()
call assert_fails('mkspell en en_US abc_xyz', 'E755:')
endfunc
" Tests for :mkspell with a .dic and .aff file
func Test_aff_file_format_error()
" No word count in .dic file
call writefile([], 'Xtest.dic')
call writefile([], 'Xtest.aff')
call assert_fails('mkspell! Xtest.spl Xtest', 'E760:')
" Invalid encoding in .aff file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['# comment', 'SET Xinvalidencoding'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Conversion in Xtest.aff not supported: from xinvalidencoding', output)
" Invalid flag in .aff file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['FLAG xxx'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Invalid value for FLAG in Xtest.aff line 1: xxx', output)
" set FLAGS after using flag for an affix
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['SFX L Y 1', 'SFX L 0 re [^x]', 'FLAG long'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('FLAG after using flags in Xtest.aff line 3: long', output)
" INFO in affix file
let save_encoding = &encoding
call mkdir('Xrtp/spell', 'p')
call writefile(['1', 'work'], 'Xrtp/spell/Xtest.dic')
call writefile(['NAME klingon', 'VERSION 1.4', 'AUTHOR Spock'],
\ 'Xrtp/spell/Xtest.aff')
silent mkspell! Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest
let save_rtp = &rtp
set runtimepath=./Xrtp
set spelllang=Xtest
set spell
let output = split(execute('spellinfo'), "\n")
call assert_equal("NAME klingon", output[1])
call assert_equal("VERSION 1.4", output[2])
call assert_equal("AUTHOR Spock", output[3])
let &rtp = save_rtp
call delete('Xrtp', 'rf')
set spell& spelllang& spellfile&
%bw!
" 'encoding' must be set again to clear the spell file in memory
let &encoding = save_encoding
" COMPOUNDFORBIDFLAG flag after PFX in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDFLAG c', 'COMPOUNDFORBIDFLAG x'],
\ 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in Xtest.aff line 4', output)
" COMPOUNDPERMITFLAG flag after PFX in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDPERMITFLAG c'],
\ 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in Xtest.aff line 3', output)
" Wrong COMPOUNDRULES flag value in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['COMPOUNDRULES a'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Wrong COMPOUNDRULES value in Xtest.aff line 1: a', output)
" Wrong COMPOUNDWORDMAX flag value in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['COMPOUNDWORDMAX 0'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Wrong COMPOUNDWORDMAX value in Xtest.aff line 1: 0', output)
" Wrong COMPOUNDMIN flag value in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['COMPOUNDMIN 0'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Wrong COMPOUNDMIN value in Xtest.aff line 1: 0', output)
" Wrong COMPOUNDSYLMAX flag value in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['COMPOUNDSYLMAX 0'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Wrong COMPOUNDSYLMAX value in Xtest.aff line 1: 0', output)
" Wrong CHECKCOMPOUNDPATTERN flag value in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['CHECKCOMPOUNDPATTERN 0'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Wrong CHECKCOMPOUNDPATTERN value in Xtest.aff line 1: 0', output)
" Duplicate affix entry in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L Y 1', 'PFX L 0 re x'],
\ 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Duplicate affix in Xtest.aff line 3: L', output)
" Duplicate affix entry in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['PFX L Y 1', 'PFX L Y 1'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Unrecognized or duplicate item in Xtest.aff line 2: PFX', output)
" Different combining flags in an affix file
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L N 1'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Different combining flag in continued affix block in Xtest.aff line 3', output)
" Try to reuse a affix used for BAD flag
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['BAD x', 'PFX x Y 1', 'PFX x 0 re x'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Affix also used for BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST in Xtest.aff line 2: x', output)
" Trailing characters in an affix entry
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['PFX L Y 1 Test', 'PFX L 0 re x'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Trailing text in Xtest.aff line 1: Test', output)
" Trailing characters in an affix entry
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['PFX L Y 1', 'PFX L 0 re x Test'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Trailing text in Xtest.aff line 2: Test', output)
" Incorrect combine flag in an affix entry
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['PFX L X 1', 'PFX L 0 re x'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Expected Y or N in Xtest.aff line 1: X', output)
" Invalid count for REP item
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['REP a'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Expected REP(SAL) count in Xtest.aff line 1', output)
" Trailing characters in REP item
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['REP 1', 'REP f ph test'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Trailing text in Xtest.aff line 2: test', output)
" Invalid count for MAP item
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['MAP a'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Expected MAP count in Xtest.aff line 1', output)
" Duplicate character in a MAP item
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['MAP 2', 'MAP xx', 'MAP yy'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Duplicate character in MAP in Xtest.aff line 2', output)
" Use COMPOUNDSYLMAX without SYLLABLE
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['COMPOUNDSYLMAX 2'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('COMPOUNDSYLMAX used without SYLLABLE', output)
" Missing SOFOTO
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['SOFOFROM abcdef'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Missing SOFOTO line in Xtest.aff', output)
" FIXME: The following test causes a heap overflow with the ASAN build
" " Both SAL and SOFOFROM/SOFOTO items
" call writefile(['1', 'work'], 'Xtest.dic')
" call writefile(['SOFOFROM abcd', 'SOFOTO ABCD', 'SAL CIA X'], 'Xtest.aff')
" let output = execute('mkspell! Xtest.spl Xtest')
" call assert_match('Both SAL and SOFO lines in Xtest.aff', output)
" use an alphabet flag when FLAG is num
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['FLAG num', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Flag is not a number in Xtest.aff line 2: L', output)
" use number and alphabet flag when FLAG is num
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['FLAG num', 'SFX 4f Y 1', 'SFX 4f 0 re [^x]'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Affix name too long in Xtest.aff line 2: 4f', output)
" use a single character flag when FLAG is long
call writefile(['1', 'work'], 'Xtest.dic')
call writefile(['FLAG long', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff')
let output = execute('mkspell! Xtest.spl Xtest')
call assert_match('Illegal flag in Xtest.aff line 2: L', output)
call delete('Xtest.dic')
call delete('Xtest.aff')
call delete('Xtest.spl')
call delete('Xtest.sug')
endfunc
func Test_spell_add_word()
set spellfile=
call assert_fails('spellgood abc', 'E764:')
@ -524,4 +725,26 @@ func Test_spell_add_word()
%bw!
endfunc
" When 'spellfile' is not set, adding a new good word will automatically set
" the 'spellfile'
func Test_init_spellfile()
let save_rtp = &rtp
let save_encoding = &encoding
call mkdir('Xrtp/spell', 'p')
call writefile(['vim'], 'Xrtp/spell/Xtest.dic')
silent mkspell Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest.dic
set runtimepath=./Xrtp
set spelllang=Xtest
set spell
silent spellgood abc
call assert_equal('./Xrtp/spell/Xtest.utf-8.add', &spellfile)
call assert_equal(['abc'], readfile('Xrtp/spell/Xtest.utf-8.add'))
call assert_true(filereadable('Xrtp/spell/Xtest.utf-8.spl'))
set spell& spelllang& spellfile&
call delete('Xrtp', 'rf')
let &encoding = save_encoding
let &rtp = save_rtp
%bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1522,
/**/
1521,
/**/