From acb6512f2eb7f692a6cc4451dd4e169d131a0686 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 4 Jul 2022 09:03:53 +0800 Subject: vim-patch:8.2.1470: errors in spell file not tested Problem: Errors in spell file not tested. Solution: Add test for spell file errors. (Yegappan Lakshmanan, closes vim/vim#6721) https://github.com/vim/vim/commit/c0f8823ee4ca629db5446ba0a935f68d4a4fb193 --- src/nvim/testdir/test_spellfile.vim | 167 +++++++++++++++++++++++++++++++++++- 1 file changed, 166 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/test_spellfile.vim b/src/nvim/testdir/test_spellfile.vim index 0f48ab8f6f..4b90ba0453 100644 --- a/src/nvim/testdir/test_spellfile.vim +++ b/src/nvim/testdir/test_spellfile.vim @@ -167,10 +167,175 @@ func Test_spell_normal() call assert_equal([], glob('Xspellfile.add',0,1)) call assert_equal([], glob('Xspellfile2.add',0,1)) - set spellfile= + set spellfile= spell& spelllang& bw! endfunc +" Test for spell file format errors +func Test_spellfile_format_error() + let save_rtp = &rtp + call mkdir('Xtest/spell', 'p') + + " empty spell file + call writefile([], './Xtest/spell/Xtest.utf-8.spl') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E757:') + set nospell spelllang& + + " invalid file ID + call writefile(['vim'], './Xtest/spell/Xtest.utf-8.spl') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E757:') + set nospell spelllang& + + " missing version number + call writefile(['VIMspell'], './Xtest/spell/Xtest.utf-8.spl') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E771:') + set nospell spelllang& + + " invalid version number + call writefile(['VIMspellz'], './Xtest/spell/Xtest.utf-8.spl') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E772:') + set nospell spelllang& + + " no sections + call writefile(0z56494D7370656C6C32, './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E758:') + set nospell spelllang& + + " missing section length + call writefile(['VIMspell200'], './Xtest/spell/Xtest.utf-8.spl') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E758:') + set nospell spelllang& + + " unsupported required section + call writefile(['VIMspell2z' .. nr2char(1) .. ' ' .. nr2char(4)], + \ './Xtest/spell/Xtest.utf-8.spl') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E770:') + set nospell spelllang& + + " unsupported not-required section + call writefile(['VIMspell2z' .. nr2char(0) .. ' ' .. nr2char(4)], + \ './Xtest/spell/Xtest.utf-8.spl') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E758:') + set nospell spelllang& + + " SN_REGION: invalid number of region names + call writefile(0z56494D7370656C6C320000000000FF, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E759:') + set nospell spelllang& + + " SN_CHARFLAGS: missing length + call writefile(0z56494D7370656C6C32010000000004, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E758:') + set nospell spelllang& + + " SN_CHARFLAGS: invalid length + call writefile(0z56494D7370656C6C320100000000010201, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + set spell + " FIXME: There are no error messages. How to check for the test result? + set nospell spelllang& + + " SN_CHARFLAGS: charflagslen == 0 and folcharslen != 0 + call writefile(0z56494D7370656C6C3201000000000400000101, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E759:') + set nospell spelllang& + + " SN_CHARFLAGS: missing length + call writefile(0z56494D7370656C6C3201000000000100, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E758:') + set nospell spelllang& + + " SN_PREFCOND: invalid prefcondcnt + call writefile(0z56494D7370656C6C3203000000000100, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E759:') + set nospell spelllang& + + " SN_PREFCOND: invalid condlen + call writefile(0z56494D7370656C6C320300000000020001, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E759:') + set nospell spelllang& + + " SN_REP: invalid repcount + call writefile(0z56494D7370656C6C3204000000000100, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E758:') + set nospell spelllang& + + " SN_REP: missing rep + call writefile(0z56494D7370656C6C320400000000020004, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E758:') + set nospell spelllang& + + " SN_REP: zero repfromlen + call writefile(0z56494D7370656C6C32040000000003000100, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E759:') + set nospell spelllang& + + " SN_REP: invalid reptolen + call writefile(0z56494D7370656C6C320400000000050001014101, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + " FIXME: There are no error messages. How to check for the test result? + set spell + set nospell spelllang& + + " SN_REP: zero reptolen + call writefile(0z56494D7370656C6C320400000000050001014100, + \ './Xtest/spell/Xtest.utf-8.spl', 'b') + set runtimepath=./Xtest + set spelllang=Xtest + call assert_fails('set spell', 'E759:') + set nospell spelllang& + + let &rtp = save_rtp + call delete('Xtest', 'rf') +endfunc + " Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN) func Test_spellfile_CHECKCOMPOUNDPATTERN() call writefile(['4', -- cgit From ed64c8f68327f6dd9d27720efb88b5bf530338ca Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 4 Jul 2022 09:07:01 +0800 Subject: vim-patch:8.2.1493: 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 vim/vim#6728) https://github.com/vim/vim/commit/fc2a47ffc425777704b329c9edbe21163bedf63c --- src/nvim/spellfile.c | 2 +- src/nvim/testdir/test_spellfile.vim | 362 +++++++++++++++++++++++++++--------- 2 files changed, 276 insertions(+), 88 deletions(-) (limited to 'src') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index a532c106ef..44885564d5 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -733,7 +733,7 @@ slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool sile if (lp->sl_syllable == NULL) { goto endFAIL; } - if (init_syl_tab(lp) == FAIL) { + if (init_syl_tab(lp) != OK) { goto endFAIL; } break; diff --git a/src/nvim/testdir/test_spellfile.vim b/src/nvim/testdir/test_spellfile.vim index 4b90ba0453..6cdf30d22e 100644 --- a/src/nvim/testdir/test_spellfile.vim +++ b/src/nvim/testdir/test_spellfile.vim @@ -171,171 +171,359 @@ func Test_spell_normal() bw! endfunc -" Test for spell file format errors +" Spell file content test. Write 'content' to the spell file prefixed by the +" spell file header and then enable spell checking. If 'emsg' is not empty, +" then check for error. +func Spellfile_Test(content, emsg) + let splfile = './Xtest/spell/Xtest.utf-8.spl' + " Add the spell file header and version (VIMspell2) + let v = 0z56494D7370656C6C32 + a:content + call writefile(v, splfile, 'b') + set runtimepath=./Xtest + set spelllang=Xtest + if a:emsg != '' + call assert_fails('set spell', a:emsg) + else + " FIXME: With some invalid spellfile contents, there are no error + " messages. So don't know how to check for the test result. + set spell + endif + set nospell spelllang& rtp& +endfunc + +" Test for spell file format errors. +" The spell file format is described in spellfile.c func Test_spellfile_format_error() let save_rtp = &rtp call mkdir('Xtest/spell', 'p') + let splfile = './Xtest/spell/Xtest.utf-8.spl' " empty spell file - call writefile([], './Xtest/spell/Xtest.utf-8.spl') + call writefile([], splfile) set runtimepath=./Xtest set spelllang=Xtest call assert_fails('set spell', 'E757:') set nospell spelllang& " invalid file ID - call writefile(['vim'], './Xtest/spell/Xtest.utf-8.spl') + call writefile(0z56494D, splfile, 'b') set runtimepath=./Xtest set spelllang=Xtest call assert_fails('set spell', 'E757:') set nospell spelllang& " missing version number - call writefile(['VIMspell'], './Xtest/spell/Xtest.utf-8.spl') + call writefile(0z56494D7370656C6C, splfile, 'b') set runtimepath=./Xtest set spelllang=Xtest call assert_fails('set spell', 'E771:') set nospell spelllang& " invalid version number - call writefile(['VIMspellz'], './Xtest/spell/Xtest.utf-8.spl') + call writefile(0z56494D7370656C6C7A, splfile, 'b') set runtimepath=./Xtest set spelllang=Xtest call assert_fails('set spell', 'E772:') set nospell spelllang& " no sections - call writefile(0z56494D7370656C6C32, './Xtest/spell/Xtest.utf-8.spl', 'b') - set runtimepath=./Xtest - set spelllang=Xtest - call assert_fails('set spell', 'E758:') - set nospell spelllang& + call Spellfile_Test(0z, 'E758:') " missing section length - call writefile(['VIMspell200'], './Xtest/spell/Xtest.utf-8.spl') - set runtimepath=./Xtest - set spelllang=Xtest - call assert_fails('set spell', 'E758:') - set nospell spelllang& + call Spellfile_Test(0z00, 'E758:') " unsupported required section - call writefile(['VIMspell2z' .. nr2char(1) .. ' ' .. nr2char(4)], - \ './Xtest/spell/Xtest.utf-8.spl') - set runtimepath=./Xtest - set spelllang=Xtest - call assert_fails('set spell', 'E770:') - set nospell spelllang& + call Spellfile_Test(0z7A0100000004, 'E770:') " unsupported not-required section - call writefile(['VIMspell2z' .. nr2char(0) .. ' ' .. nr2char(4)], - \ './Xtest/spell/Xtest.utf-8.spl') - set runtimepath=./Xtest - set spelllang=Xtest - call assert_fails('set spell', 'E758:') - set nospell spelllang& + call Spellfile_Test(0z7A0000000004, 'E758:') " SN_REGION: invalid number of region names - call writefile(0z56494D7370656C6C320000000000FF, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') - set runtimepath=./Xtest - set spelllang=Xtest - call assert_fails('set spell', 'E759:') - set nospell spelllang& + call Spellfile_Test(0z0000000000FF, 'E759:') " SN_CHARFLAGS: missing length - call writefile(0z56494D7370656C6C32010000000004, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') - set runtimepath=./Xtest - set spelllang=Xtest - call assert_fails('set spell', 'E758:') - set nospell spelllang& + call Spellfile_Test(0z010000000004, 'E758:') " SN_CHARFLAGS: invalid length - call writefile(0z56494D7370656C6C320100000000010201, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') - set runtimepath=./Xtest - set spelllang=Xtest - set spell - " FIXME: There are no error messages. How to check for the test result? - set nospell spelllang& + call Spellfile_Test(0z0100000000010201, '') " SN_CHARFLAGS: charflagslen == 0 and folcharslen != 0 - call writefile(0z56494D7370656C6C3201000000000400000101, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') - set runtimepath=./Xtest - set spelllang=Xtest - call assert_fails('set spell', 'E759:') - set nospell spelllang& + call Spellfile_Test(0z01000000000400000101, 'E759:') " SN_CHARFLAGS: missing length - call writefile(0z56494D7370656C6C3201000000000100, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') - set runtimepath=./Xtest - set spelllang=Xtest - call assert_fails('set spell', 'E758:') - set nospell spelllang& + call Spellfile_Test(0z01000000000100, 'E758:') " SN_PREFCOND: invalid prefcondcnt - call writefile(0z56494D7370656C6C3203000000000100, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') - set runtimepath=./Xtest - set spelllang=Xtest - call assert_fails('set spell', 'E759:') - set nospell spelllang& + call Spellfile_Test(0z03000000000100, 'E759:') " SN_PREFCOND: invalid condlen - call writefile(0z56494D7370656C6C320300000000020001, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') + call Spellfile_Test(0z0300000000020001, 'E759:') + + " SN_REP: invalid repcount + call Spellfile_Test(0z04000000000100, 'E758:') + + " SN_REP: missing rep + call Spellfile_Test(0z0400000000020004, 'E758:') + + " SN_REP: zero repfromlen + call Spellfile_Test(0z040000000003000100, 'E759:') + + " SN_REP: invalid reptolen + call Spellfile_Test(0z0400000000050001014101, '') + + " SN_REP: zero reptolen + call Spellfile_Test(0z0400000000050001014100, 'E759:') + + " SN_SAL: missing salcount + call Spellfile_Test(0z05000000000102, 'E758:') + + " SN_SAL: missing salfromlen + call Spellfile_Test(0z050000000003080001, 'E758:') + + " SN_SAL: missing saltolen + call Spellfile_Test(0z0500000000050400010161, 'E758:') + + " SN_WORDS: non-NUL terminated word + call Spellfile_Test(0z0D000000000376696D, 'E758:') + + " SN_WORDS: very long word + let v = eval('0z0D000000012C' .. repeat('41', 300)) + call Spellfile_Test(v, 'E759:') + + " SN_SOFO: missing sofofromlen + call Spellfile_Test(0z06000000000100, 'E758:') + + " SN_SOFO: missing sofotolen + call Spellfile_Test(0z06000000000400016100, 'E758:') + + " SN_SOFO: missing sofoto + call Spellfile_Test(0z0600000000050001610000, 'E759:') + + " SN_COMPOUND: compmax is less than 2 + call Spellfile_Test(0z08000000000101, 'E759:') + + " SN_COMPOUND: missing compsylmax and other options + call Spellfile_Test(0z0800000000020401, 'E759:') + + " SN_COMPOUND: missing compoptions + call Spellfile_Test(0z080000000005040101, 'E758:') + + " SN_INFO: missing info + call Spellfile_Test(0z0F0000000005040101, '') + + " SN_MIDWORD: missing midword + call Spellfile_Test(0z0200000000040102, '') + + " SN_MAP: missing midword + call Spellfile_Test(0z0700000000040102, '') + + " SN_SYLLABLE: missing SYLLABLE item + call Spellfile_Test(0z0900000000040102, '') + + " SN_SYLLABLE: More than SY_MAXLEN size + let v = eval('0z090000000022612F' .. repeat('62', 32)) + call Spellfile_Test(v, '') + + " LWORDTREE: missing + call Spellfile_Test(0zFF, 'E758:') + + " LWORDTREE: missing tree node + call Spellfile_Test(0zFF00000004, 'E758:') + + " LWORDTREE: missing tree node value + call Spellfile_Test(0zFF0000000402, 'E758:') + + " KWORDTREE: missing tree node + call Spellfile_Test(0zFF0000000000000004, 'E758:') + + " PREFIXTREE: missing tree node + call Spellfile_Test(0zFF000000000000000000000004, 'E758:') + + let &rtp = save_rtp + call delete('Xtest', 'rf') +endfunc + +" Test for format errors in suggest file +func Test_sugfile_format_error() + let save_rtp = &rtp + call mkdir('Xtest/spell', 'p') + let splfile = './Xtest/spell/Xtest.utf-8.spl' + let sugfile = './Xtest/spell/Xtest.utf-8.sug' + + " create an empty spell file with a suggest timestamp + call writefile(0z56494D7370656C6C320B00000000080000000000000044FF000000000000000000000000, splfile, 'b') + + " 'encoding' is set before each test to clear the previously loaded suggest + " file from memory. + + " empty suggest file + set encoding=utf-8 + call writefile([], sugfile) set runtimepath=./Xtest set spelllang=Xtest - call assert_fails('set spell', 'E759:') + set spell + call assert_fails("let s = spellsuggest('abc')", 'E778:') set nospell spelllang& - " SN_REP: invalid repcount - call writefile(0z56494D7370656C6C3204000000000100, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') + " zero suggest version + set encoding=utf-8 + call writefile(0z56494D73756700, sugfile) set runtimepath=./Xtest set spelllang=Xtest - call assert_fails('set spell', 'E758:') + set spell + call assert_fails("let s = spellsuggest('abc')", 'E779:') set nospell spelllang& - " SN_REP: missing rep - call writefile(0z56494D7370656C6C320400000000020004, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') + " unsupported suggest version + set encoding=utf-8 + call writefile(0z56494D7375671F, sugfile) set runtimepath=./Xtest set spelllang=Xtest - call assert_fails('set spell', 'E758:') + set spell + call assert_fails("let s = spellsuggest('abc')", 'E780:') set nospell spelllang& - " SN_REP: zero repfromlen - call writefile(0z56494D7370656C6C32040000000003000100, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') + " missing suggest timestamp + set encoding=utf-8 + call writefile(0z56494D73756701, sugfile) set runtimepath=./Xtest set spelllang=Xtest - call assert_fails('set spell', 'E759:') + set spell + call assert_fails("let s = spellsuggest('abc')", 'E781:') set nospell spelllang& - " SN_REP: invalid reptolen - call writefile(0z56494D7370656C6C320400000000050001014101, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') + " incorrect suggest timestamp + set encoding=utf-8 + call writefile(0z56494D7375670100000000000000FF, sugfile) set runtimepath=./Xtest set spelllang=Xtest - " FIXME: There are no error messages. How to check for the test result? set spell + call assert_fails("let s = spellsuggest('abc')", 'E781:') set nospell spelllang& - " SN_REP: zero reptolen - call writefile(0z56494D7370656C6C320400000000050001014100, - \ './Xtest/spell/Xtest.utf-8.spl', 'b') + " missing suggest wordtree + set encoding=utf-8 + call writefile(0z56494D737567010000000000000044, sugfile) set runtimepath=./Xtest set spelllang=Xtest - call assert_fails('set spell', 'E759:') + set spell + call assert_fails("let s = spellsuggest('abc')", 'E782:') set nospell spelllang& let &rtp = save_rtp call delete('Xtest', 'rf') endfunc +" Test for using :mkspell to create a spell file from a list of words +func Test_wordlist_dic() + " duplicate encoding + let lines =<< trim [END] + # This is an example word list + + /encoding=latin1 + /encoding=latin1 + example + [END] + call writefile(lines, 'Xwordlist.dic') + let output = execute('mkspell Xwordlist.spl Xwordlist.dic') + call assert_match('Duplicate /encoding= line ignored in Xwordlist.dic line 4: /encoding=latin1', output) + + " multiple encoding for a word + let lines =<< trim [END] + example + /encoding=latin1 + example + [END] + call writefile(lines, 'Xwordlist.dic') + let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') + call assert_match('/encoding= line after word ignored in Xwordlist.dic line 2: /encoding=latin1', output) + + " unsupported encoding for a word + let lines =<< trim [END] + /encoding=Xtest + example + [END] + call writefile(lines, 'Xwordlist.dic') + let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') + call assert_match('Conversion in Xwordlist.dic not supported: from Xtest to utf-8', output) + + " duplicate region + let lines =<< trim [END] + /regions=usca + /regions=usca + example + [END] + call writefile(lines, 'Xwordlist.dic') + let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') + call assert_match('Duplicate /regions= line ignored in Xwordlist.dic line 2: regions=usca', output) + + " maximum regions + let lines =<< trim [END] + /regions=uscauscauscauscausca + example + [END] + call writefile(lines, 'Xwordlist.dic') + let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') + call assert_match('Too many regions in Xwordlist.dic line 1: uscauscauscauscausca', output) + + " unsupported '/' value + let lines =<< trim [END] + /test=abc + example + [END] + call writefile(lines, 'Xwordlist.dic') + let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') + call assert_match('/ line ignored in Xwordlist.dic line 1: /test=abc', output) + + " unsupported flag + let lines =<< trim [END] + example/+ + [END] + call writefile(lines, 'Xwordlist.dic') + let output = execute('mkspell! Xwordlist.spl Xwordlist.dic') + call assert_match('Unrecognized flags in Xwordlist.dic line 1: +', output) + + " non-ascii word + call writefile(["ʀʀ"], 'Xwordlist.dic') + let output = execute('mkspell! -ascii Xwordlist.spl Xwordlist.dic') + call assert_match('Ignored 1 words with non-ASCII characters', output) + + call delete('Xwordlist.spl') + call delete('Xwordlist.dic') +endfunc + +" Test for the :mkspell command +func Test_mkspell() + call assert_fails('mkspell Xtest_us.spl', 'E751:') + call assert_fails('mkspell a b c d e f g h i j k', 'E754:') + + call writefile([], 'Xtest.spl') + call writefile([], 'Xtest.dic') + call assert_fails('mkspell Xtest.spl Xtest.dic', 'E13:') + call delete('Xtest.spl') + call delete('Xtest.dic') + + call mkdir('Xtest.spl') + call assert_fails('mkspell! Xtest.spl Xtest.dic', 'E17:') + call delete('Xtest.spl', 'rf') + + call assert_fails('mkspell en en_US abc_xyz', 'E755:') +endfunc + +func Test_spell_add_word() + set spellfile= + call assert_fails('spellgood abc', 'E764:') + + set spellfile=Xtest.utf-8.add + call assert_fails('2spellgood abc', 'E765:') + + edit Xtest.utf-8.add + call setline(1, 'sample') + call assert_fails('spellgood abc', 'E139:') + set spellfile& + %bw! +endfunc + " Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN) func Test_spellfile_CHECKCOMPOUNDPATTERN() call writefile(['4', -- cgit From a2d8d5e1f547432668fd29ad48529d5122516b47 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 4 Jul 2022 09:10:05 +0800 Subject: vim-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 vim/vim#6763) https://github.com/vim/vim/commit/c8ec5fe56fc30201c889ca577bf1e69823fadb2a Add missing whitespace in message. --- src/nvim/spellfile.c | 2 +- src/nvim/testdir/test_spellfile.vim | 223 ++++++++++++++++++++++++++++++++++++ 2 files changed, 224 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 44885564d5..04eb9dd2bc 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -2379,7 +2379,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) || cur_aff->ah_flag == aff->af_needcomp || cur_aff->ah_flag == aff->af_comproot) { smsg(_("Affix also used for " - "BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST" + "BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST " "in %s line %d: %s"), fname, lnum, items[1]); } diff --git a/src/nvim/testdir/test_spellfile.vim b/src/nvim/testdir/test_spellfile.vim index 6cdf30d22e..1991373e9e 100644 --- a/src/nvim/testdir/test_spellfile.vim +++ b/src/nvim/testdir/test_spellfile.vim @@ -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,6 +725,28 @@ 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 + " Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN) func Test_spellfile_CHECKCOMPOUNDPATTERN() call writefile(['4', -- cgit From 7648a8524c3f20d79db50df069a87cfa0cd23f96 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 4 Jul 2022 09:17:35 +0800 Subject: vim-patch:8.2.1523: still not enough test coverage for the spell file handling Problem: Still not enough test coverage for the spell file handling. Solution: Add spell file tests. (Yegappan Lakshmanan, closes vim/vim#6790) https://github.com/vim/vim/commit/b9fc192f928b484c8809fb985ef334d7a2bb5a09 --- src/nvim/testdir/test_spellfile.vim | 82 ++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_spellfile.vim b/src/nvim/testdir/test_spellfile.vim index 1991373e9e..f1331a9f2a 100644 --- a/src/nvim/testdir/test_spellfile.vim +++ b/src/nvim/testdir/test_spellfile.vim @@ -410,6 +410,24 @@ func Test_sugfile_format_error() call assert_fails("let s = spellsuggest('abc')", 'E782:') set nospell spelllang& + " invalid suggest word count in SUGTABLE + set encoding=utf-8 + call writefile(0z56494D7375670100000000000000440000000022, sugfile) + set runtimepath=./Xtest + set spelllang=Xtest + set spell + call assert_fails("let s = spellsuggest('abc')", 'E782:') + set nospell spelllang& + + " missing sugline in SUGTABLE + set encoding=utf-8 + call writefile(0z56494D7375670100000000000000440000000000000005, sugfile) + set runtimepath=./Xtest + set spelllang=Xtest + set spell + call assert_fails("let s = spellsuggest('abc')", 'E782:') + set nospell spelllang& + let &rtp = save_rtp call delete('Xtest', 'rf') endfunc @@ -512,25 +530,29 @@ endfunc " Tests for :mkspell with a .dic and .aff file func Test_aff_file_format_error() + " FIXME: For some reason, the :mkspell command below doesn't fail on the + " MS-Windows CI build. Disable this test on MS-Windows for now. + CheckNotMSWindows + " 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 + " create a .dic file for the tests below call writefile(['1', 'work'], 'Xtest.dic') + + " Invalid encoding in .aff file 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) @@ -558,153 +580,139 @@ func Test_aff_file_format_error() 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) + " Length of SOFOFROM and SOFOTO differ + call writefile(['SOFOFROM abcde', 'SOFOTO ABCD'], 'Xtest.aff') + call assert_fails('mkspell! Xtest.spl Xtest', 'E759:') + + " Both SAL and SOFOFROM/SOFOTO items + 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) + " duplicate word in the .dic file + call writefile(['2', 'good', 'good', 'good'], 'Xtest.dic') + call writefile(['NAME vim'], 'Xtest.aff') + let output = execute('mkspell! Xtest.spl Xtest') + call assert_match('First duplicate word in Xtest.dic line 3: good', output) + call assert_match('2 duplicate word(s) in Xtest.dic', output) + call delete('Xtest.dic') call delete('Xtest.aff') call delete('Xtest.spl') @@ -747,6 +755,16 @@ func Test_init_spellfile() %bw! endfunc +" Test for the 'mkspellmem' option +func Test_mkspellmem_opt() + call assert_fails('set mkspellmem=1000', 'E474:') + call assert_fails('set mkspellmem=1000,', 'E474:') + call assert_fails('set mkspellmem=1000,50', 'E474:') + call assert_fails('set mkspellmem=1000,50,', 'E474:') + call assert_fails('set mkspellmem=1000,50,10,', 'E474:') + call assert_fails('set mkspellmem=1000,50,0', 'E474:') +endfunc + " Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN) func Test_spellfile_CHECKCOMPOUNDPATTERN() call writefile(['4', -- cgit From 1ff86aa634cc5b12e3f804f6594c36799acbf296 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 4 Jul 2022 09:21:19 +0800 Subject: vim-patch:8.2.1770: invalid memory use when using SpellFileMissing autocmd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Invalid memory use when using SpellFileMissing autocmd. Solution: Add test case. (Dominique Pellé, closes vim/vim#7036) Fix using a window that was closed. https://github.com/vim/vim/commit/d569a9e74684cd17f9cea63e804281388728e513 Skip an assert because of #3027. --- src/nvim/spell.c | 2 +- src/nvim/testdir/test_spell.vim | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 304fd30b36..1cefc532aa 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2327,11 +2327,11 @@ char *did_set_spelllang(win_T *wp) } } } + redraw_later(wp, NOT_VALID); theend: xfree(spl_copy); recursive = false; - redraw_later(wp, NOT_VALID); return ret_msg; } diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index d0895a48b4..b768dc1814 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -131,6 +131,30 @@ foobar/? set spell& endfunc +func Test_spell_file_missing() + let s:spell_file_missing = 0 + augroup TestSpellFileMissing + autocmd! SpellFileMissing * let s:spell_file_missing += 1 + augroup END + + set spell spelllang=ab_cd + let messages = GetMessages() + " This message is not shown in Nvim because of #3027 + " call assert_equal('Warning: Cannot find word list "ab.utf-8.spl" or "ab.ascii.spl"', messages[-1]) + call assert_equal(1, s:spell_file_missing) + + new XTestSpellFileMissing + augroup TestSpellFileMissing + autocmd! SpellFileMissing * bwipe + augroup END + call assert_fails('set spell spelllang=ab_cd', 'E797:') + + augroup! TestSpellFileMissing + unlet s:spell_file_missing + set spell& spelllang& + %bwipe! +endfunc + func Test_spelllang_inv_region() set spell spelllang=en_xx let messages = GetMessages() -- cgit From a4215a0a21d1812e1d198c0546942302f7ad4126 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 4 Jul 2022 09:48:20 +0800 Subject: vim-patch:8.2.5072: using uninitialized value and freed memory in spell command Problem: Using uninitialized value and freed memory in spell command. Solution: Initialize "attr". Check for empty line early. https://github.com/vim/vim/commit/2813f38e021c6e6581c0c88fcf107e41788bc835 --- src/nvim/spell.c | 6 ++++-- src/nvim/testdir/test_spell_utf8.vim | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 1cefc532aa..0fedd27037 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1469,7 +1469,9 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att } // Copy the line into "buf" and append the start of the next line if - // possible. + // possible. Note: this ml_get_buf() may make "line" invalid, check + // for empty line first. + bool empty_line = *skipwhite((const char *)line) == NUL; STRCPY(buf, line); if (lnum < wp->w_buffer->b_ml.ml_line_count) { spell_cat_line(buf + STRLEN(buf), @@ -1613,7 +1615,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att --capcol; // But after empty line check first word in next line - if (*skipwhite((char *)line) == NUL) { + if (empty_line) { capcol = 0; } } diff --git a/src/nvim/testdir/test_spell_utf8.vim b/src/nvim/testdir/test_spell_utf8.vim index 3d240a8f2c..7ee001c090 100644 --- a/src/nvim/testdir/test_spell_utf8.vim +++ b/src/nvim/testdir/test_spell_utf8.vim @@ -808,5 +808,20 @@ func Test_word_index() call delete('Xtmpfile') endfunc +func Test_check_empty_line() + " This was using freed memory + enew + spellgood! fl + norm z= + norm yy + sil! norm P]svc + norm P]s + + " set 'encoding' to clear the wordt list + set enc=latin1 + set enc=utf-8 + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 6b474d0237a1ec9b5b027e5d1fb738be38a57347 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 4 Jul 2022 09:53:58 +0800 Subject: vim-patch:8.2.5074: spell test fails on MS-Windows Problem: Spell test fails on MS-Windows. Solution: Do not change 'encoding' https://github.com/vim/vim/commit/ad73cc2ff2a8b5397ed20598757b702a4e686256 --- src/nvim/testdir/test_spell_utf8.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_spell_utf8.vim b/src/nvim/testdir/test_spell_utf8.vim index 7ee001c090..2fd176557d 100644 --- a/src/nvim/testdir/test_spell_utf8.vim +++ b/src/nvim/testdir/test_spell_utf8.vim @@ -817,9 +817,7 @@ func Test_check_empty_line() sil! norm P]svc norm P]s - " set 'encoding' to clear the wordt list - set enc=latin1 - set enc=utf-8 + " TODO: should we clear the word list? bwipe! endfunc -- cgit