Mercurial > vim
diff src/testdir/test_edit.vim @ 25974:416237f1de22 v8.2.3520
patch 8.2.3520: cannot define a function for thesaurus completion
Commit: https://github.com/vim/vim/commit/160e994d768d03a3c826b58115cde94df8fce607
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sat Oct 16 15:41:29 2021 +0100
patch 8.2.3520: cannot define a function for thesaurus completion
Problem: Cannot define a function for thesaurus completion.
Solution: Add 'thesaurusfunc'. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/8987,
closes 8950)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 16 Oct 2021 16:45:04 +0200 |
parents | fc39d7352cb6 |
children | ac330e2fecc4 |
line wrap: on
line diff
--- a/src/testdir/test_edit.vim +++ b/src/testdir/test_edit.vim @@ -890,6 +890,48 @@ func Test_edit_CTRL_T() bw! endfunc +" Test 'thesaurusfunc' +func MyThesaurus(findstart, base) + let mythesaurus = [ + \ #{word: "happy", + \ synonyms: "cheerful,blissful,flying high,looking good,peppy"}, + \ #{word: "kind", + \ synonyms: "amiable,bleeding-heart,heart in right place"}] + if a:findstart + " locate the start of the word + let line = getline('.') + let start = col('.') - 1 + while start > 0 && line[start - 1] =~ '\a' + let start -= 1 + endwhile + return start + else + " find strings matching with "a:base" + let res = [] + for w in mythesaurus + if w.word =~ '^' . a:base + call add(res, w.word) + call extend(res, split(w.synonyms, ",")) + endif + endfor + return res + endif +endfunc + +func Test_thesaurus_func() + new + set thesaurus= + set thesaurusfunc=MyThesaurus + call setline(1, "an ki") + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['an amiable', ''], getline(1, '$')) + set thesaurusfunc=NonExistingFunc + call assert_fails("normal $a\<C-X>\<C-T>", 'E117:') + set thesaurusfunc& + %bw! +endfunc + func Test_edit_CTRL_U() " Test 'completefunc' new