From f376e67a536010d8e0250fb96b28f66ddcf7168a Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 11 Jun 2021 22:20:28 -0400 Subject: vim-patch:8.2.0038: spell suggestions insufficiently tested Problem: Spell suggestions insufficiently tested. Solution: Add spell suggestion tests. (Dominique Pelle, closes vim/vim#5398) https://github.com/vim/vim/commit/e9a8d1f9adaf4599b5a7923f8db8e207ed6e7eca Requires latest en.utf-8.spl from https://ftp.nluug.nl/pub/vim/runtime/spell/. Include the following patch because patch v8.2.0946 was merged: vim-patch:8.2.0948: spell test fails Problem: Spell test fails. Solution: Adjust expected text of the prompt. https://github.com/vim/vim/commit/d281b7c227bc4c78813fdc297ccee4b2cad7e605 --- src/nvim/testdir/test_spell.vim | 173 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 171 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir/test_spell.vim') diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index ab8a998bb8..587d9fc42c 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -172,6 +172,175 @@ func Test_spellreall() bwipe! endfunc +" Test spellsuggest({word} [, {max} [, {capital}]]) +func Test_spellsuggest() + " No suggestions when spell checking is not enabled. + set nospell + call assert_equal([], spellsuggest('mercurry')) + + set spell + + " With 1 argument. + call assert_equal(['mercury', 'Mercury'], spellsuggest('mercurry')[0:1]) + + " With 2 arguments. + call assert_equal(['mercury', 'Mercury'], spellsuggest('mercurry', 2)) + + " With 3 arguments. + call assert_equal(['mercury'], spellsuggest('mercurry', 1, 0)) + call assert_equal(['Mercury'], spellsuggest('mercurry', 1, 1)) + + " Test with digits and hyphen. + call assert_equal('Carbon-14', spellsuggest('Carbon-15')[0]) + + " Comment taken from spellsuggest.c explains the following test cases: + " + " If there are more UPPER than lower case letters suggest an + " ALLCAP word. Otherwise, if the first letter is UPPER then + " suggest ONECAP. Exception: "ALl" most likely should be "All", + " require three upper case letters. + call assert_equal(['MACARONI', 'macaroni'], spellsuggest('maCARONI', 2)) + call assert_equal(['macaroni', 'MACARONI'], spellsuggest('maCAroni', 2)) + call assert_equal(['Macaroni'], spellsuggest('MACAroni', 1)) + call assert_equal(['All'], spellsuggest('ALl', 1)) + + set spell& +endfunc + +" Test 'spellsuggest' option with methods fast, best and double. +func Test_spellsuggest_option_methods() + set spell + + set spellsuggest=fast + call assert_equal(['Keyword', 'Keyboard'], spellsuggest('Keybord', 2)) + + " With best or double option, "Keyboard" should become the top suggestion + " because of better phonetic matching. + set spellsuggest=best + call assert_equal(['Keyboard', 'Keyword'], spellsuggest('Keybord', 2)) + + set spellsuggest=double + call assert_equal(['Keyboard', 'Keyword'], spellsuggest('Keybord', 2)) + + set spell& spellsuggest& +endfunc + +" Test 'spellsuggest' option with value file:{filename} +func Test_spellsuggest_option_file() + set spell spellsuggest=file:Xspellsuggest + call writefile(['emacs/vim', + \ 'theribal/terrible', + \ 'teribal/terrrible', + \ 'terribal'], + \ 'Xspellsuggest') + + call assert_equal(['vim'], spellsuggest('emacs', 2)) + call assert_equal(['terrible'], spellsuggest('theribal',2)) + + " If the suggestion is misspelled (*terrrible* with 3 r), + " it should not be proposed. + " The entry for "terribal" should be ignored because of missing slash. + call assert_equal([], spellsuggest('teribal', 2)) + call assert_equal([], spellsuggest('terribal', 2)) + + set spell spellsuggest=best,file:Xspellsuggest + call assert_equal(['vim', 'Emacs'], spellsuggest('emacs', 2)) + call assert_equal(['terrible', 'tribal'], spellsuggest('theribal', 2)) + call assert_equal(['tribal'], spellsuggest('teribal', 1)) + call assert_equal(['tribal'], spellsuggest('terribal', 1)) + + call delete('Xspellsuggest') + call assert_fails("call spellsuggest('vim')", "E484: Can't open file Xspellsuggest") + + set spellsuggest& spell& +endfunc + +" Test 'spellsuggest' option with value {number} +" to limit the number of suggestions +func Test_spellsuggest_option_number() + set spell spellsuggest=2,best + new + + " We limited the number of suggestions to 2, so selecting + " the 1st and 2nd suggestion should correct the word, but + " selecting a 3rd suggestion should do nothing. + call setline(1, 'Keybord') + norm 1z= + call assert_equal('Keyboard', getline(1)) + + call setline(1, 'Keybord') + norm 2z= + call assert_equal('Keyword', getline(1)) + + call setline(1, 'Keybord') + norm 3z= + call assert_equal('Keybord', getline(1)) + + let a = execute('norm z=') + call assert_equal( + \ "\n" + \ .. "Change \"Keybord\" to:\n" + \ .. " 1 \"Keyboard\"\n" + \ .. " 2 \"Keyword\"\n" + \ .. "Type number and or click with the mouse (q or empty cancels): ", a) + + set spell spellsuggest=0 + " FIXME: the following line is currently commented out as it triggers a + " memory error detected in cleanup_suggestions() by asan or valgrind. + "call assert_equal("\nSorry, no suggestions", execute('norm z=')) + + " Unlike z=, function spellsuggest(...) should not be affected by the + " max number of suggestions (2) set by the 'spellsuggest' option. + call assert_equal(['Keyboard', 'Keyword', 'Keyboards'], spellsuggest('Keybord', 3)) + + set spellsuggest& spell& + bwipe! +endfunc + +" Test 'spellsuggest' option with value expr:{expr} +func Test_spellsuggest_option_expr() + " A silly 'spellsuggest' function which makes suggestions all uppercase + " and makes the score of each suggestion the length of the suggested word. + " So shorter suggestions are preferred. + func MySuggest() + let spellsuggest_save = &spellsuggest + set spellsuggest=best + let result = map(spellsuggest(v:val, 3), "[toupper(v:val), len(v:val)]") + let &spellsuggest = spellsuggest_save + return result + endfunc + + set spell spellsuggest=3,expr:MySuggest() + call assert_equal(['KEYWORD', 'KEYBOARD', 'KEYBOARDS'], spellsuggest('Keybord', 3)) + call assert_equal(['KEYWORD', 'KEYBOARD', 'KEYBOARDS'], spellsuggest('Keybord', 3)) + + new + call setline(1, 'Keybord') + let a = execute('norm z=') + call assert_equal( + \ "\n" + \ .. "Change \"Keybord\" to:\n" + \ .. " 1 \"KEYWORD\"\n" + \ .. " 2 \"KEYBOARD\"\n" + \ .. " 3 \"KEYBOARDS\"\n" + \ .. "Type number and or click with the mouse (q or empty cancels): ", a) + + " With verbose, z= should show the score i.e. word length with + " our SpellSuggest() function. + set verbose=1 + let a = execute('norm z=') + call assert_equal( + \ "\n" + \ .. "Change \"Keybord\" to:\n" + \ .. " 1 \"KEYWORD\" (7 - 0)\n" + \ .. " 2 \"KEYBOARD\" (8 - 0)\n" + \ .. " 3 \"KEYBOARDS\" (9 - 0)\n" + \ .. "Type number and or click with the mouse (q or empty cancels): ", a) + + set spell& spellsuggest& verbose& + bwipe! +endfunc + func Test_spellinfo() throw 'skipped: Nvim does not support enc=latin1' new @@ -227,7 +396,7 @@ func Test_zz_basic() \ ) call assert_equal("gebletegek", soundfold('goobledygoook')) - call assert_equal("kepereneven", soundfold('kóopërÿnôven')) + call assert_equal("kepereneven", soundfold('kóopërÿnôven')) call assert_equal("everles gesvets etele", soundfold('oeverloos gezwets edale')) endfunc @@ -408,7 +577,7 @@ func Test_zz_sal_and_addition() mkspell! Xtest Xtest set spl=Xtest.latin1.spl spell call assert_equal('kbltykk', soundfold('goobledygoook')) - call assert_equal('kprnfn', soundfold('kóopërÿnôven')) + call assert_equal('kprnfn', soundfold('kóopërÿnôven')) call assert_equal('*fls kswts tl', soundfold('oeverloos gezwets edale')) "also use an addition file -- cgit From e78656875dc82206928812a26df49eca99d0b098 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 11 Jun 2021 22:32:39 -0400 Subject: vim-patch:8.2.0039: memory access error when "z=" has no suggestions Problem: Memory access error when "z=" has no suggestions. Solution: Check for negative index. https://github.com/vim/vim/commit/569fea2c312126dd5a542c4b1aa51095136a2c0d --- src/nvim/testdir/test_spell.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/testdir/test_spell.vim') diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index 587d9fc42c..2ec77ca57a 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -285,9 +285,7 @@ func Test_spellsuggest_option_number() \ .. "Type number and or click with the mouse (q or empty cancels): ", a) set spell spellsuggest=0 - " FIXME: the following line is currently commented out as it triggers a - " memory error detected in cleanup_suggestions() by asan or valgrind. - "call assert_equal("\nSorry, no suggestions", execute('norm z=')) + call assert_equal("\nSorry, no suggestions", execute('norm z=')) " Unlike z=, function spellsuggest(...) should not be affected by the " max number of suggestions (2) set by the 'spellsuggest' option. -- cgit From 82d1c29bfd652c74fad8b9a4d403ffdf45c05321 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 11 Jun 2021 22:35:03 -0400 Subject: vim-patch:8.2.0046: tests for spell suggestions are slow Problem: Tests for spell suggestions are slow. Solution: Use shorter words. Test with latin1 and utf-8 to cover more code. (Dominique Pelle, closes vim/vim#5399) https://github.com/vim/vim/commit/767340574b5a0c697e650b3bbc3a4af10e51cb89 --- src/nvim/testdir/test_spell.vim | 93 +++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 45 deletions(-) (limited to 'src/nvim/testdir/test_spell.vim') diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index 2ec77ca57a..78b37df098 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -176,19 +176,19 @@ endfunc func Test_spellsuggest() " No suggestions when spell checking is not enabled. set nospell - call assert_equal([], spellsuggest('mercurry')) + call assert_equal([], spellsuggest('marrch')) set spell " With 1 argument. - call assert_equal(['mercury', 'Mercury'], spellsuggest('mercurry')[0:1]) + call assert_equal(['march', 'March'], spellsuggest('marrch')[0:1]) " With 2 arguments. - call assert_equal(['mercury', 'Mercury'], spellsuggest('mercurry', 2)) + call assert_equal(['march', 'March'], spellsuggest('marrch', 2)) " With 3 arguments. - call assert_equal(['mercury'], spellsuggest('mercurry', 1, 0)) - call assert_equal(['Mercury'], spellsuggest('mercurry', 1, 1)) + call assert_equal(['march'], spellsuggest('marrch', 1, 0)) + call assert_equal(['March'], spellsuggest('marrch', 1, 1)) " Test with digits and hyphen. call assert_equal('Carbon-14', spellsuggest('Carbon-15')[0]) @@ -199,9 +199,9 @@ func Test_spellsuggest() " ALLCAP word. Otherwise, if the first letter is UPPER then " suggest ONECAP. Exception: "ALl" most likely should be "All", " require three upper case letters. - call assert_equal(['MACARONI', 'macaroni'], spellsuggest('maCARONI', 2)) - call assert_equal(['macaroni', 'MACARONI'], spellsuggest('maCAroni', 2)) - call assert_equal(['Macaroni'], spellsuggest('MACAroni', 1)) + call assert_equal(['THIRD', 'third'], spellsuggest('thIRD', 2)) + call assert_equal(['third', 'THIRD'], spellsuggest('tHIrd', 2)) + call assert_equal(['Third'], spellsuggest('THird', 1)) call assert_equal(['All'], spellsuggest('ALl', 1)) set spell& @@ -211,18 +211,22 @@ endfunc func Test_spellsuggest_option_methods() set spell - set spellsuggest=fast - call assert_equal(['Keyword', 'Keyboard'], spellsuggest('Keybord', 2)) + for e in ['utf-8'] + exe 'set encoding=' .. e - " With best or double option, "Keyboard" should become the top suggestion - " because of better phonetic matching. - set spellsuggest=best - call assert_equal(['Keyboard', 'Keyword'], spellsuggest('Keybord', 2)) + set spellsuggest=fast + call assert_equal(['Stick', 'Stitch'], spellsuggest('Stich', 2), e) - set spellsuggest=double - call assert_equal(['Keyboard', 'Keyword'], spellsuggest('Keybord', 2)) + " With best or double option, "Stitch" should become the top suggestion + " because of better phonetic matching. + set spellsuggest=best + call assert_equal(['Stitch', 'Stick'], spellsuggest('Stich', 2), e) + + set spellsuggest=double + call assert_equal(['Stitch', 'Stick'], spellsuggest('Stich', 2), e) + endfor - set spell& spellsuggest& + set spell& spellsuggest& encoding& endfunc " Test 'spellsuggest' option with value file:{filename} @@ -264,32 +268,32 @@ func Test_spellsuggest_option_number() " We limited the number of suggestions to 2, so selecting " the 1st and 2nd suggestion should correct the word, but " selecting a 3rd suggestion should do nothing. - call setline(1, 'Keybord') - norm 1z= - call assert_equal('Keyboard', getline(1)) + call setline(1, 'A baord') + norm $1z= + call assert_equal('A board', getline(1)) - call setline(1, 'Keybord') - norm 2z= - call assert_equal('Keyword', getline(1)) + call setline(1, 'A baord') + norm $2z= + call assert_equal('A bard', getline(1)) - call setline(1, 'Keybord') - norm 3z= - call assert_equal('Keybord', getline(1)) + call setline(1, 'A baord') + norm $3z= + call assert_equal('A baord', getline(1)) - let a = execute('norm z=') + let a = execute('norm $z=') call assert_equal( \ "\n" - \ .. "Change \"Keybord\" to:\n" - \ .. " 1 \"Keyboard\"\n" - \ .. " 2 \"Keyword\"\n" + \ .. "Change \"baord\" to:\n" + \ .. " 1 \"board\"\n" + \ .. " 2 \"bard\"\n" \ .. "Type number and or click with the mouse (q or empty cancels): ", a) set spell spellsuggest=0 - call assert_equal("\nSorry, no suggestions", execute('norm z=')) + call assert_equal("\nSorry, no suggestions", execute('norm $z=')) " Unlike z=, function spellsuggest(...) should not be affected by the " max number of suggestions (2) set by the 'spellsuggest' option. - call assert_equal(['Keyboard', 'Keyword', 'Keyboards'], spellsuggest('Keybord', 3)) + call assert_equal(['board', 'bard', 'broad'], spellsuggest('baord', 3)) set spellsuggest& spell& bwipe! @@ -302,25 +306,24 @@ func Test_spellsuggest_option_expr() " So shorter suggestions are preferred. func MySuggest() let spellsuggest_save = &spellsuggest - set spellsuggest=best + set spellsuggest=3,best let result = map(spellsuggest(v:val, 3), "[toupper(v:val), len(v:val)]") let &spellsuggest = spellsuggest_save return result endfunc - set spell spellsuggest=3,expr:MySuggest() - call assert_equal(['KEYWORD', 'KEYBOARD', 'KEYBOARDS'], spellsuggest('Keybord', 3)) - call assert_equal(['KEYWORD', 'KEYBOARD', 'KEYBOARDS'], spellsuggest('Keybord', 3)) + set spell spellsuggest=expr:MySuggest() + call assert_equal(['BARD', 'BOARD', 'BROAD'], spellsuggest('baord', 3)) new - call setline(1, 'Keybord') + call setline(1, 'baord') let a = execute('norm z=') call assert_equal( \ "\n" - \ .. "Change \"Keybord\" to:\n" - \ .. " 1 \"KEYWORD\"\n" - \ .. " 2 \"KEYBOARD\"\n" - \ .. " 3 \"KEYBOARDS\"\n" + \ .. "Change \"baord\" to:\n" + \ .. " 1 \"BARD\"\n" + \ .. " 2 \"BOARD\"\n" + \ .. " 3 \"BROAD\"\n" \ .. "Type number and or click with the mouse (q or empty cancels): ", a) " With verbose, z= should show the score i.e. word length with @@ -329,10 +332,10 @@ func Test_spellsuggest_option_expr() let a = execute('norm z=') call assert_equal( \ "\n" - \ .. "Change \"Keybord\" to:\n" - \ .. " 1 \"KEYWORD\" (7 - 0)\n" - \ .. " 2 \"KEYBOARD\" (8 - 0)\n" - \ .. " 3 \"KEYBOARDS\" (9 - 0)\n" + \ .. "Change \"baord\" to:\n" + \ .. " 1 \"BARD\" (4 - 0)\n" + \ .. " 2 \"BOARD\" (5 - 0)\n" + \ .. " 3 \"BROAD\" (5 - 0)\n" \ .. "Type number and or click with the mouse (q or empty cancels): ", a) set spell& spellsuggest& verbose& -- cgit From 72b512bd530afe7937d5ed8a9b68da889669bf80 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 11 Jun 2021 22:43:22 -0400 Subject: vim-patch:8.2.0945: cannot use "z=" when 'spell' is off Problem: Cannot use "z=" when 'spell' is off. Solution: Make "z=" work even when 'spell' is off. (Christian Brabandt, Gary Johnson, closes vim/vim#6227) https://github.com/vim/vim/commit/152e79e94bb935e75b866bd55479648cde11066a --- src/nvim/testdir/test_spell.vim | 48 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'src/nvim/testdir/test_spell.vim') diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index 78b37df098..e525d06ea2 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -106,11 +106,14 @@ foobar/? set spelllang=Xwords.spl call assert_equal(['foobar', 'rare'], spellbadword('foo foobar')) - " Typo should not be detected without the 'spell' option. + " Typo should be detected even without the 'spell' option. set spelllang=en_gb nospell call assert_equal(['', ''], spellbadword('centre')) - call assert_equal(['', ''], spellbadword('My bycycle.')) - call assert_equal(['', ''], spellbadword('A sentence. another sentence')) + call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.')) + call assert_equal(['another', 'caps'], spellbadword('A sentence. another sentence')) + + set spelllang= + call assert_fails("call spellbadword('maxch')", 'E756:') call delete('Xwords.spl') call delete('Xwords') @@ -174,9 +177,9 @@ endfunc " Test spellsuggest({word} [, {max} [, {capital}]]) func Test_spellsuggest() - " No suggestions when spell checking is not enabled. + " Verify suggestions are given even when spell checking is not enabled. set nospell - call assert_equal([], spellsuggest('marrch')) + call assert_equal(['march', 'March'], spellsuggest('marrch', 2)) set spell @@ -204,6 +207,13 @@ func Test_spellsuggest() call assert_equal(['Third'], spellsuggest('THird', 1)) call assert_equal(['All'], spellsuggest('ALl', 1)) + call assert_fails("call spellsuggest('maxch', [])", 'E745:') + call assert_fails("call spellsuggest('maxch', 2, [])", 'E745:') + + set spelllang= + call assert_fails("call spellsuggest('maxch')", 'E756:') + set spelllang& + set spell& endfunc @@ -631,6 +641,34 @@ func Test_zeq_crash() bwipe! endfunc +" Check that z= works even when 'nospell' is set. This test uses one of the +" tests in Test_spellsuggest_option_number() just to verify that z= basically +" works and that "E756: Spell checking is not enabled" is not generated. +func Test_zeq_nospell() + new + set nospell spellsuggest=1,best + call setline(1, 'A baord') + try + norm $1z= + call assert_equal('A board', getline(1)) + catch + call assert_report("Caught exception: " . v:exception) + endtry + set spell& spellsuggest& + bwipe! +endfunc + +" Check that "E756: Spell checking is not possible" is reported when z= is +" executed and 'spelllang' is empty. +func Test_zeq_no_spelllang() + new + set spelllang= spellsuggest=1,best + call setline(1, 'A baord') + call assert_fails('normal $1z=', 'E756:') + set spelllang& spellsuggest& + bwipe! +endfunc + " Check handling a word longer than MAXWLEN. func Test_spell_long_word() set enc=utf-8 -- cgit