2022-11-06 22:37:22 -07:00
|
|
|
|
" Test for insert completion
|
|
|
|
|
|
2020-10-08 15:52:18 -07:00
|
|
|
|
source screendump.vim
|
|
|
|
|
source check.vim
|
2022-11-06 22:37:22 -07:00
|
|
|
|
source vim9.vim
|
2018-02-02 15:14:30 -07:00
|
|
|
|
|
|
|
|
|
" Test for insert expansion
|
|
|
|
|
func Test_ins_complete()
|
2018-02-03 04:11:07 -07:00
|
|
|
|
edit test_ins_complete.vim
|
2018-02-11 16:05:54 -07:00
|
|
|
|
" The files in the current directory interferes with the files
|
|
|
|
|
" used by this test. So use a separate directory for the test.
|
|
|
|
|
call mkdir('Xdir')
|
|
|
|
|
cd Xdir
|
|
|
|
|
|
2018-02-02 15:14:30 -07:00
|
|
|
|
set ff=unix
|
|
|
|
|
call writefile(["test11\t36Gepeto\t/Tag/",
|
|
|
|
|
\ "asd\ttest11file\t36G",
|
|
|
|
|
\ "Makefile\tto\trun"], 'Xtestfile')
|
|
|
|
|
call writefile(['', 'start of testfile',
|
|
|
|
|
\ 'ru',
|
|
|
|
|
\ 'run1',
|
|
|
|
|
\ 'run2',
|
|
|
|
|
\ 'STARTTEST',
|
|
|
|
|
\ 'ENDTEST',
|
|
|
|
|
\ 'end of testfile'], 'Xtestdata')
|
|
|
|
|
set ff&
|
|
|
|
|
|
|
|
|
|
enew!
|
|
|
|
|
edit Xtestdata
|
|
|
|
|
new
|
|
|
|
|
call append(0, ['#include "Xtestfile"', ''])
|
|
|
|
|
call cursor(2, 1)
|
|
|
|
|
|
|
|
|
|
set cot=
|
|
|
|
|
set cpt=.,w
|
|
|
|
|
" add-expands (word from next line) from other window
|
|
|
|
|
exe "normal iru\<C-N>\<C-N>\<C-X>\<C-N>\<Esc>\<C-A>"
|
|
|
|
|
call assert_equal('run1 run3', getline('.'))
|
|
|
|
|
" add-expands (current buffer first)
|
|
|
|
|
exe "normal o\<C-P>\<C-X>\<C-N>"
|
|
|
|
|
call assert_equal('run3 run3', getline('.'))
|
|
|
|
|
" Local expansion, ends in an empty line (unless it becomes a global
|
|
|
|
|
" expansion)
|
|
|
|
|
exe "normal o\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>"
|
|
|
|
|
call assert_equal('', getline('.'))
|
|
|
|
|
" starts Local and switches to global add-expansion
|
|
|
|
|
exe "normal o\<C-X>\<C-P>\<C-P>\<C-X>\<C-X>\<C-N>\<C-X>\<C-N>\<C-N>"
|
|
|
|
|
call assert_equal('run1 run2', getline('.'))
|
|
|
|
|
|
2022-08-23 22:33:15 -07:00
|
|
|
|
set cpt=.,\ ,w,i
|
2018-02-02 15:14:30 -07:00
|
|
|
|
" i-add-expands and switches to local
|
|
|
|
|
exe "normal OM\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-X>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal("Makefile\tto\trun3", getline('.'))
|
2022-08-23 22:33:15 -07:00
|
|
|
|
" add-expands lines (it would end in an empty line if it didn't ignore
|
2018-02-02 15:14:30 -07:00
|
|
|
|
" itself)
|
|
|
|
|
exe "normal o\<C-X>\<C-L>\<C-X>\<C-L>\<C-P>\<C-P>"
|
|
|
|
|
call assert_equal("Makefile\tto\trun3", getline('.'))
|
|
|
|
|
call assert_equal("Makefile\tto\trun3", getline(line('.') - 1))
|
|
|
|
|
|
|
|
|
|
set cpt=kXtestfile
|
|
|
|
|
" checks k-expansion, and file expansion (use Xtest11 instead of test11,
|
|
|
|
|
" because TEST11.OUT may match first on DOS)
|
|
|
|
|
write Xtest11.one
|
|
|
|
|
write Xtest11.two
|
|
|
|
|
exe "normal o\<C-N>\<Esc>IX\<Esc>A\<C-X>\<C-F>\<C-N>"
|
|
|
|
|
call assert_equal('Xtest11.two', getline('.'))
|
|
|
|
|
|
|
|
|
|
" use CTRL-X CTRL-F to complete Xtest11.one, remove it and then use CTRL-X
|
|
|
|
|
" CTRL-F again to verify this doesn't cause trouble.
|
|
|
|
|
exe "normal oXt\<C-X>\<C-F>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<C-X>\<C-F>"
|
|
|
|
|
call assert_equal('Xtest11.one', getline('.'))
|
|
|
|
|
normal ddk
|
|
|
|
|
|
2022-08-24 17:04:25 -07:00
|
|
|
|
" Test for expanding a non-existing filename
|
|
|
|
|
exe "normal oa1b2X3Y4\<C-X>\<C-F>"
|
|
|
|
|
call assert_equal('a1b2X3Y4', getline('.'))
|
|
|
|
|
normal ddk
|
|
|
|
|
|
2018-02-02 15:14:30 -07:00
|
|
|
|
set cpt=w
|
|
|
|
|
" checks make_cyclic in other window
|
|
|
|
|
exe "normal oST\<C-N>\<C-P>\<C-P>\<C-P>\<C-P>"
|
|
|
|
|
call assert_equal('STARTTEST', getline('.'))
|
|
|
|
|
|
|
|
|
|
set cpt=u nohid
|
|
|
|
|
" checks unloaded buffer expansion
|
|
|
|
|
only
|
|
|
|
|
exe "normal oEN\<C-N>"
|
|
|
|
|
call assert_equal('ENDTEST', getline('.'))
|
|
|
|
|
" checks adding mode abortion
|
|
|
|
|
exe "normal ounl\<C-N>\<C-X>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal('unless', getline('.'))
|
|
|
|
|
|
|
|
|
|
set cpt=t,d def=^\\k* tags=Xtestfile notagbsearch
|
|
|
|
|
" tag expansion, define add-expansion interrupted
|
|
|
|
|
exe "normal o\<C-X>\<C-]>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-D>"
|
|
|
|
|
call assert_equal('test11file 36Gepeto /Tag/ asd', getline('.'))
|
|
|
|
|
" t-expansion
|
|
|
|
|
exe "normal oa\<C-N>\<Esc>"
|
|
|
|
|
call assert_equal('asd', getline('.'))
|
|
|
|
|
|
|
|
|
|
%bw!
|
|
|
|
|
call delete('Xtestfile')
|
|
|
|
|
call delete('Xtest11.one')
|
|
|
|
|
call delete('Xtest11.two')
|
|
|
|
|
call delete('Xtestdata')
|
2022-07-09 15:59:58 -07:00
|
|
|
|
set cpt& cot& def& tags& tagbsearch& hidden&
|
2018-02-11 16:05:54 -07:00
|
|
|
|
cd ..
|
|
|
|
|
call delete('Xdir', 'rf')
|
2018-02-02 15:14:30 -07:00
|
|
|
|
endfunc
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
2024-03-09 04:21:31 -07:00
|
|
|
|
func Test_ins_complete_invalid_byte()
|
|
|
|
|
if has('unix') && executable('base64')
|
|
|
|
|
" this weird command was causing an illegal memory access
|
|
|
|
|
call writefile(['bm9ybTlvMDCAMM4Dbw4OGA4ODg=='], 'Xinvalid64')
|
|
|
|
|
call system('base64 -d Xinvalid64 > Xinvalid')
|
|
|
|
|
call writefile(['qa!'], 'Xexit')
|
|
|
|
|
call RunVim([], [], " -i NONE -n -X -Z -e -m -s -S Xinvalid -S Xexit")
|
|
|
|
|
call delete('Xinvalid64')
|
|
|
|
|
call delete('Xinvalid')
|
|
|
|
|
call delete('Xexit')
|
|
|
|
|
endif
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-20 15:00:16 -07:00
|
|
|
|
func Test_omni_dash()
|
|
|
|
|
func Omni(findstart, base)
|
|
|
|
|
if a:findstart
|
|
|
|
|
return 5
|
|
|
|
|
else
|
|
|
|
|
echom a:base
|
|
|
|
|
return ['-help', '-v']
|
|
|
|
|
endif
|
|
|
|
|
endfunc
|
|
|
|
|
set omnifunc=Omni
|
|
|
|
|
new
|
|
|
|
|
exe "normal Gofind -\<C-x>\<C-o>"
|
|
|
|
|
call assert_equal("find -help", getline('$'))
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
delfunc Omni
|
|
|
|
|
set omnifunc=
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_omni_throw()
|
|
|
|
|
let g:CallCount = 0
|
|
|
|
|
func Omni(findstart, base)
|
|
|
|
|
let g:CallCount += 1
|
|
|
|
|
if a:findstart
|
|
|
|
|
throw "he he he"
|
|
|
|
|
endif
|
|
|
|
|
endfunc
|
|
|
|
|
set omnifunc=Omni
|
|
|
|
|
new
|
|
|
|
|
try
|
|
|
|
|
exe "normal ifoo\<C-x>\<C-o>"
|
|
|
|
|
call assert_false(v:true, 'command should have failed')
|
|
|
|
|
catch
|
|
|
|
|
call assert_exception('he he he')
|
|
|
|
|
call assert_equal(1, g:CallCount)
|
|
|
|
|
endtry
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
delfunc Omni
|
|
|
|
|
unlet g:CallCount
|
|
|
|
|
set omnifunc=
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_completefunc_args()
|
|
|
|
|
let s:args = []
|
|
|
|
|
func! CompleteFunc(findstart, base)
|
|
|
|
|
let s:args += [[a:findstart, empty(a:base)]]
|
|
|
|
|
endfunc
|
|
|
|
|
new
|
|
|
|
|
|
|
|
|
|
set completefunc=CompleteFunc
|
|
|
|
|
call feedkeys("i\<C-X>\<C-U>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([1, 1], s:args[0])
|
|
|
|
|
call assert_equal(0, s:args[1][0])
|
|
|
|
|
set completefunc=
|
|
|
|
|
|
|
|
|
|
let s:args = []
|
|
|
|
|
set omnifunc=CompleteFunc
|
|
|
|
|
call feedkeys("i\<C-X>\<C-O>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([1, 1], s:args[0])
|
|
|
|
|
call assert_equal(0, s:args[1][0])
|
|
|
|
|
set omnifunc=
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
unlet s:args
|
|
|
|
|
delfunc CompleteFunc
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func s:CompleteDone_CompleteFuncNone( findstart, base )
|
|
|
|
|
throw 'skipped: Nvim does not support v:none'
|
|
|
|
|
if a:findstart
|
|
|
|
|
return 0
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
return v:none
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-02-06 14:34:20 -07:00
|
|
|
|
func s:CompleteDone_CompleteFuncDict( findstart, base )
|
2018-02-18 15:56:59 -07:00
|
|
|
|
if a:findstart
|
|
|
|
|
return 0
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
return {
|
2022-12-15 15:08:59 -07:00
|
|
|
|
\ 'words': [
|
|
|
|
|
\ {
|
|
|
|
|
\ 'word': 'aword',
|
|
|
|
|
\ 'abbr': 'wrd',
|
|
|
|
|
\ 'menu': 'extra text',
|
|
|
|
|
\ 'info': 'words are cool',
|
|
|
|
|
\ 'kind': 'W',
|
|
|
|
|
\ 'user_data': ['one', 'two']
|
|
|
|
|
\ }
|
|
|
|
|
\ ]
|
|
|
|
|
\ }
|
2022-02-06 14:34:20 -07:00
|
|
|
|
endfunc
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func s:CompleteDone_CheckCompletedItemNone()
|
|
|
|
|
let s:called_completedone = 1
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-01-26 19:34:32 -07:00
|
|
|
|
func s:CompleteDone_CheckCompletedItemDict(pre)
|
2018-02-18 15:56:59 -07:00
|
|
|
|
call assert_equal( 'aword', v:completed_item[ 'word' ] )
|
|
|
|
|
call assert_equal( 'wrd', v:completed_item[ 'abbr' ] )
|
|
|
|
|
call assert_equal( 'extra text', v:completed_item[ 'menu' ] )
|
|
|
|
|
call assert_equal( 'words are cool', v:completed_item[ 'info' ] )
|
|
|
|
|
call assert_equal( 'W', v:completed_item[ 'kind' ] )
|
2020-04-28 08:27:14 -07:00
|
|
|
|
call assert_equal( ['one', 'two'], v:completed_item[ 'user_data' ] )
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
2020-01-26 19:34:32 -07:00
|
|
|
|
if a:pre
|
|
|
|
|
call assert_equal('function', complete_info().mode)
|
|
|
|
|
endif
|
2020-01-17 21:31:18 -07:00
|
|
|
|
|
2018-02-18 15:56:59 -07:00
|
|
|
|
let s:called_completedone = 1
|
2020-01-26 19:34:32 -07:00
|
|
|
|
endfunc
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func Test_CompleteDoneNone()
|
|
|
|
|
throw 'skipped: Nvim does not support v:none'
|
|
|
|
|
au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone()
|
2020-01-17 21:14:47 -07:00
|
|
|
|
let oldline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
|
2020-01-17 20:06:44 -07:00
|
|
|
|
|
|
|
|
|
set completefunc=<SID>CompleteDone_CompleteFuncNone
|
|
|
|
|
execute "normal a\<C-X>\<C-U>\<C-Y>"
|
|
|
|
|
set completefunc&
|
2020-01-17 21:14:47 -07:00
|
|
|
|
let newline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
|
2020-01-17 20:06:44 -07:00
|
|
|
|
|
|
|
|
|
call assert_true(s:called_completedone)
|
2020-01-17 21:14:47 -07:00
|
|
|
|
call assert_equal(oldline, newline)
|
2020-01-17 20:06:44 -07:00
|
|
|
|
|
|
|
|
|
let s:called_completedone = 0
|
|
|
|
|
au! CompleteDone
|
|
|
|
|
endfunc
|
|
|
|
|
|
2024-12-05 02:49:39 -07:00
|
|
|
|
func Test_CompleteDone_vevent_keys()
|
|
|
|
|
func OnDone()
|
|
|
|
|
let g:complete_word = get(v:event, 'complete_word', v:null)
|
|
|
|
|
let g:complete_type = get(v:event, 'complete_type', v:null)
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
autocmd CompleteDone * :call OnDone()
|
|
|
|
|
|
|
|
|
|
func CompleteFunc(findstart, base)
|
|
|
|
|
if a:findstart
|
|
|
|
|
return col(".")
|
|
|
|
|
endif
|
|
|
|
|
return [#{word: "foo"}, #{word: "bar"}]
|
|
|
|
|
endfunc
|
|
|
|
|
set omnifunc=CompleteFunc
|
|
|
|
|
set completefunc=CompleteFunc
|
|
|
|
|
set completeopt+=menuone
|
|
|
|
|
|
|
|
|
|
new
|
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'tx')
|
|
|
|
|
call assert_equal('', g:complete_word)
|
|
|
|
|
call assert_equal('omni', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call feedkeys("S\<C-X>\<C-O>\<C-Y>\<Esc>", 'tx')
|
|
|
|
|
call assert_equal('foo', g:complete_word)
|
|
|
|
|
call assert_equal('omni', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call feedkeys("S\<C-X>\<C-O>\<C-N>\<C-Y>\<Esc>0", 'tx')
|
|
|
|
|
call assert_equal('bar', g:complete_word)
|
|
|
|
|
call assert_equal('omni', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call feedkeys("Shello vim visual v\<C-X>\<C-N>\<ESC>", 'tx')
|
|
|
|
|
call assert_equal('', g:complete_word)
|
|
|
|
|
call assert_equal('keyword', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call feedkeys("Shello vim visual v\<C-X>\<C-N>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('vim', g:complete_word)
|
|
|
|
|
call assert_equal('keyword', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call feedkeys("Shello vim visual v\<C-X>\<C-N>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('vim', g:complete_word)
|
|
|
|
|
call assert_equal('keyword', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call feedkeys("Shello vim\<CR>completion test\<CR>\<C-X>\<C-l>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('completion test', g:complete_word)
|
|
|
|
|
call assert_equal('whole_line', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call feedkeys("S\<C-X>\<C-U>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('foo', g:complete_word)
|
|
|
|
|
call assert_equal('function', g:complete_type)
|
|
|
|
|
|
|
|
|
|
inoremap <buffer> <f3> <cmd>call complete(1, ["red", "blue"])<cr>
|
|
|
|
|
call feedkeys("S\<f3>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('red', g:complete_word)
|
|
|
|
|
call assert_equal('eval', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call feedkeys("S\<C-X>\<C-V>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('!', g:complete_word)
|
|
|
|
|
call assert_equal('cmdline', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call writefile([''], 'foo_test', 'D')
|
|
|
|
|
call feedkeys("Sfoo\<C-X>\<C-F>\<C-Y>\<Esc>", 'tx')
|
|
|
|
|
call assert_equal('foo_test', g:complete_word)
|
|
|
|
|
call assert_equal('files', g:complete_type)
|
|
|
|
|
|
|
|
|
|
call writefile(['hello help'], 'test_case.txt', 'D')
|
|
|
|
|
set dictionary=test_case.txt
|
|
|
|
|
call feedkeys("ggdGSh\<C-X>\<C-K>\<C-Y>\<Esc>", 'tx')
|
|
|
|
|
call assert_equal('hello', g:complete_word)
|
|
|
|
|
call assert_equal('dictionary', g:complete_type)
|
|
|
|
|
|
|
|
|
|
set spell spelllang=en_us
|
|
|
|
|
call feedkeys("STheatre\<C-X>s\<C-Y>\<Esc>", 'tx')
|
|
|
|
|
call assert_equal('Theater', g:complete_word)
|
|
|
|
|
call assert_equal('spell', g:complete_type)
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
set completeopt& omnifunc& completefunc& spell& spelllang& dictionary&
|
|
|
|
|
autocmd! CompleteDone
|
|
|
|
|
delfunc OnDone
|
|
|
|
|
delfunc CompleteFunc
|
|
|
|
|
unlet g:complete_word
|
|
|
|
|
unlet g:complete_type
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func Test_CompleteDoneDict()
|
2020-01-26 19:34:32 -07:00
|
|
|
|
au CompleteDonePre * :call <SID>CompleteDone_CheckCompletedItemDict(1)
|
|
|
|
|
au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict(0)
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
|
|
|
|
set completefunc=<SID>CompleteDone_CompleteFuncDict
|
|
|
|
|
execute "normal a\<C-X>\<C-U>\<C-Y>"
|
|
|
|
|
set completefunc&
|
|
|
|
|
|
2020-04-28 08:27:14 -07:00
|
|
|
|
call assert_equal(['one', 'two'], v:completed_item[ 'user_data' ])
|
2020-01-17 20:06:44 -07:00
|
|
|
|
call assert_true(s:called_completedone)
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
|
|
|
|
let s:called_completedone = 0
|
|
|
|
|
au! CompleteDone
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base)
|
2018-02-18 15:56:59 -07:00
|
|
|
|
if a:findstart
|
|
|
|
|
return 0
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
return {
|
2022-12-15 15:08:59 -07:00
|
|
|
|
\ 'words': [
|
|
|
|
|
\ {
|
|
|
|
|
\ 'word': 'aword',
|
|
|
|
|
\ 'abbr': 'wrd',
|
|
|
|
|
\ 'menu': 'extra text',
|
|
|
|
|
\ 'info': 'words are cool',
|
|
|
|
|
\ 'kind': 'W',
|
|
|
|
|
\ }
|
|
|
|
|
\ ]
|
|
|
|
|
\ }
|
2020-01-17 20:06:44 -07:00
|
|
|
|
endfunc
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func s:CompleteDone_CheckCompletedItemDictNoUserData()
|
2018-02-18 15:56:59 -07:00
|
|
|
|
call assert_equal( 'aword', v:completed_item[ 'word' ] )
|
|
|
|
|
call assert_equal( 'wrd', v:completed_item[ 'abbr' ] )
|
|
|
|
|
call assert_equal( 'extra text', v:completed_item[ 'menu' ] )
|
|
|
|
|
call assert_equal( 'words are cool', v:completed_item[ 'info' ] )
|
|
|
|
|
call assert_equal( 'W', v:completed_item[ 'kind' ] )
|
|
|
|
|
call assert_equal( '', v:completed_item[ 'user_data' ] )
|
|
|
|
|
|
|
|
|
|
let s:called_completedone = 1
|
2020-01-17 20:06:44 -07:00
|
|
|
|
endfunc
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func Test_CompleteDoneDictNoUserData()
|
2018-02-18 15:56:59 -07:00
|
|
|
|
au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData()
|
|
|
|
|
|
|
|
|
|
set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData
|
|
|
|
|
execute "normal a\<C-X>\<C-U>\<C-Y>"
|
|
|
|
|
set completefunc&
|
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
call assert_equal('', v:completed_item[ 'user_data' ])
|
|
|
|
|
call assert_true(s:called_completedone)
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
|
|
|
|
let s:called_completedone = 0
|
|
|
|
|
au! CompleteDone
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func s:CompleteDone_CompleteFuncList(findstart, base)
|
2018-02-18 15:56:59 -07:00
|
|
|
|
if a:findstart
|
|
|
|
|
return 0
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
return [ 'aword' ]
|
2020-01-17 20:06:44 -07:00
|
|
|
|
endfunc
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func s:CompleteDone_CheckCompletedItemList()
|
2018-02-18 15:56:59 -07:00
|
|
|
|
call assert_equal( 'aword', v:completed_item[ 'word' ] )
|
|
|
|
|
call assert_equal( '', v:completed_item[ 'abbr' ] )
|
|
|
|
|
call assert_equal( '', v:completed_item[ 'menu' ] )
|
|
|
|
|
call assert_equal( '', v:completed_item[ 'info' ] )
|
|
|
|
|
call assert_equal( '', v:completed_item[ 'kind' ] )
|
|
|
|
|
call assert_equal( '', v:completed_item[ 'user_data' ] )
|
|
|
|
|
|
|
|
|
|
let s:called_completedone = 1
|
2020-01-17 20:06:44 -07:00
|
|
|
|
endfunc
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
func Test_CompleteDoneList()
|
2018-02-18 15:56:59 -07:00
|
|
|
|
au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList()
|
|
|
|
|
|
|
|
|
|
set completefunc=<SID>CompleteDone_CompleteFuncList
|
|
|
|
|
execute "normal a\<C-X>\<C-U>\<C-Y>"
|
|
|
|
|
set completefunc&
|
|
|
|
|
|
2020-01-17 20:06:44 -07:00
|
|
|
|
call assert_equal('', v:completed_item[ 'user_data' ])
|
|
|
|
|
call assert_true(s:called_completedone)
|
2018-02-18 15:56:59 -07:00
|
|
|
|
|
|
|
|
|
let s:called_completedone = 0
|
|
|
|
|
au! CompleteDone
|
|
|
|
|
endfunc
|
2018-08-22 10:00:42 -07:00
|
|
|
|
|
2022-07-20 15:00:16 -07:00
|
|
|
|
func Test_CompleteDone_undo()
|
|
|
|
|
au CompleteDone * call append(0, "prepend1")
|
2019-07-27 15:19:41 -07:00
|
|
|
|
new
|
2022-07-20 15:00:16 -07:00
|
|
|
|
call setline(1, ["line1", "line2"])
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx")
|
|
|
|
|
call assert_equal(["prepend1", "line1", "line2", "line1", ""],
|
|
|
|
|
\ getline(1, '$'))
|
|
|
|
|
undo
|
|
|
|
|
call assert_equal(["line1", "line2"], getline(1, '$'))
|
2019-07-27 15:19:41 -07:00
|
|
|
|
bwipe!
|
2022-07-20 15:00:16 -07:00
|
|
|
|
au! CompleteDone
|
2019-07-27 15:19:41 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-27 14:19:38 -07:00
|
|
|
|
func Test_CompleteDone_modify()
|
|
|
|
|
let value = {
|
|
|
|
|
\ 'word': '',
|
|
|
|
|
\ 'abbr': '',
|
|
|
|
|
\ 'menu': '',
|
|
|
|
|
\ 'info': '',
|
|
|
|
|
\ 'kind': '',
|
|
|
|
|
\ 'user_data': '',
|
|
|
|
|
\ }
|
|
|
|
|
let v:completed_item = value
|
2022-07-31 03:49:57 -07:00
|
|
|
|
call assert_equal(value, v:completed_item)
|
2022-07-27 14:19:38 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2020-12-02 21:29:04 -07:00
|
|
|
|
func CompleteTest(findstart, query)
|
|
|
|
|
if a:findstart
|
|
|
|
|
return col('.')
|
|
|
|
|
endif
|
|
|
|
|
return ['matched']
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_completefunc_info()
|
|
|
|
|
new
|
|
|
|
|
set completeopt=menuone
|
|
|
|
|
set completefunc=CompleteTest
|
|
|
|
|
call feedkeys("i\<C-X>\<C-U>\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
|
2020-12-02 21:43:43 -07:00
|
|
|
|
call assert_equal("matched{'pum_visible': 1, 'mode': 'function', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1))
|
2020-12-02 21:29:04 -07:00
|
|
|
|
bwipe!
|
|
|
|
|
set completeopt&
|
|
|
|
|
set completefunc&
|
|
|
|
|
endfunc
|
|
|
|
|
|
2024-03-20 16:50:12 -07:00
|
|
|
|
func CompleteInfoUserDefinedFn(findstart, query)
|
|
|
|
|
" User defined function (i_CTRL-X_CTRL-U)
|
|
|
|
|
if a:findstart
|
|
|
|
|
return col('.')
|
|
|
|
|
endif
|
|
|
|
|
return [{'word': 'foo'}, {'word': 'bar'}, {'word': 'baz'}, {'word': 'qux'}]
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func CompleteInfoTestUserDefinedFn(mvmt, idx, noselect)
|
|
|
|
|
new
|
|
|
|
|
if a:noselect
|
|
|
|
|
set completeopt=menuone,popup,noinsert,noselect
|
|
|
|
|
else
|
|
|
|
|
set completeopt=menu,preview
|
|
|
|
|
endif
|
|
|
|
|
set completefunc=CompleteInfoUserDefinedFn
|
|
|
|
|
call feedkeys("i\<C-X>\<C-U>" . a:mvmt . "\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
|
|
|
|
|
let completed = a:idx != -1 ? ['foo', 'bar', 'baz', 'qux']->get(a:idx) : ''
|
|
|
|
|
call assert_equal(completed. "{'pum_visible': 1, 'mode': 'function', 'selected': " . a:idx . ", 'items': [" .
|
|
|
|
|
\ "{'word': 'foo', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, " .
|
|
|
|
|
\ "{'word': 'bar', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, " .
|
|
|
|
|
\ "{'word': 'baz', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, " .
|
|
|
|
|
\ "{'word': 'qux', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}" .
|
|
|
|
|
\ "]}", getline(1))
|
|
|
|
|
bwipe!
|
|
|
|
|
set completeopt&
|
|
|
|
|
set completefunc&
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_complete_info_user_defined_fn()
|
|
|
|
|
" forward
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>", 1, v:true)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>", 2, v:true)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>", 2, v:false)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>", 3, v:false)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>\<C-N>", -1, v:false)
|
|
|
|
|
" backward
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>", 2, v:true)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>", 1, v:true)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>", -1, v:true)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>", 3, v:false)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>", 2, v:false)
|
|
|
|
|
" forward backward
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>\<C-P>", 1, v:true)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-P>", 0, v:true)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>\<C-P>", 2, v:false)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>\<C-N>\<C-P>", 3, v:false)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-P>", 1, v:false)
|
|
|
|
|
" backward forward
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-N>", 0, v:true)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-N>", 2, v:true)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-N>", 1, v:false)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-N>", 3, v:false)
|
|
|
|
|
call CompleteInfoTestUserDefinedFn("\<C-P>\<C-N>\<C-N>", 1, v:false)
|
|
|
|
|
endfunc
|
|
|
|
|
|
2023-03-02 16:44:16 -07:00
|
|
|
|
" Test that mouse scrolling/movement should not interrupt completion.
|
|
|
|
|
func Test_mouse_scroll_move_during_completion()
|
|
|
|
|
new
|
|
|
|
|
com! -buffer TestCommand1 echo 'TestCommand1'
|
|
|
|
|
com! -buffer TestCommand2 echo 'TestCommand2'
|
|
|
|
|
call setline(1, ['', '', '', '', ''])
|
|
|
|
|
call cursor(5, 1)
|
|
|
|
|
|
|
|
|
|
" Without completion menu scrolling can move text.
|
|
|
|
|
set completeopt-=menu wrap
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelDown>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
call assert_notequal(1, winsaveview().topline)
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelUp>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
call assert_equal(1, winsaveview().topline)
|
|
|
|
|
set nowrap
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelRight>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
call assert_notequal(0, winsaveview().leftcol)
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelLeft>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
call assert_equal(0, winsaveview().leftcol)
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<MouseMove>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
|
|
|
|
|
" With completion menu scrolling cannot move text.
|
|
|
|
|
set completeopt+=menu wrap
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelDown>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
call assert_equal(1, winsaveview().topline)
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelUp>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
call assert_equal(1, winsaveview().topline)
|
|
|
|
|
set nowrap
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelRight>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
call assert_equal(0, winsaveview().leftcol)
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelLeft>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
call assert_equal(0, winsaveview().leftcol)
|
|
|
|
|
call feedkeys("ccT\<C-X>\<C-V>\<MouseMove>\<C-V>", 'tx')
|
|
|
|
|
call assert_equal('TestCommand2', getline('.'))
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
set completeopt& wrap&
|
|
|
|
|
endfunc
|
|
|
|
|
|
2019-06-23 19:04:46 -07:00
|
|
|
|
" Check that when using feedkeys() typeahead does not interrupt searching for
|
|
|
|
|
" completions.
|
|
|
|
|
func Test_compl_feedkeys()
|
|
|
|
|
new
|
|
|
|
|
set completeopt=menuone,noselect
|
|
|
|
|
call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx")
|
|
|
|
|
call assert_equal("jump jump", getline(1))
|
|
|
|
|
bwipe!
|
|
|
|
|
set completeopt&
|
|
|
|
|
endfunc
|
2019-11-24 19:50:24 -07:00
|
|
|
|
|
2022-01-29 09:34:00 -07:00
|
|
|
|
func s:ComplInCmdwin_GlobalCompletion(a, l, p)
|
|
|
|
|
return 'global'
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func s:ComplInCmdwin_LocalCompletion(a, l, p)
|
|
|
|
|
return 'local'
|
|
|
|
|
endfunc
|
|
|
|
|
|
2019-11-24 19:50:24 -07:00
|
|
|
|
func Test_compl_in_cmdwin()
|
|
|
|
|
set wildmenu wildchar=<Tab>
|
|
|
|
|
com! -nargs=1 -complete=command GetInput let input = <q-args>
|
|
|
|
|
com! -buffer TestCommand echo 'TestCommand'
|
2020-10-25 09:38:52 -07:00
|
|
|
|
let w:test_winvar = 'winvar'
|
|
|
|
|
let b:test_bufvar = 'bufvar'
|
2019-11-24 19:50:24 -07:00
|
|
|
|
|
2020-10-25 09:38:52 -07:00
|
|
|
|
" User-defined commands
|
2019-11-24 19:50:24 -07:00
|
|
|
|
let input = ''
|
|
|
|
|
call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!')
|
|
|
|
|
call assert_equal('TestCommand', input)
|
|
|
|
|
|
|
|
|
|
let input = ''
|
|
|
|
|
call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!')
|
|
|
|
|
call assert_equal('T', input)
|
|
|
|
|
|
2020-10-25 09:38:52 -07:00
|
|
|
|
com! -nargs=1 -complete=var GetInput let input = <q-args>
|
|
|
|
|
" Window-local variables
|
|
|
|
|
let input = ''
|
|
|
|
|
call feedkeys("q:iGetInput w:test_\<C-x>\<C-v>\<CR>", 'tx!')
|
|
|
|
|
call assert_equal('w:test_winvar', input)
|
|
|
|
|
|
|
|
|
|
let input = ''
|
|
|
|
|
call feedkeys("q::GetInput w:test_\<Tab>\<CR>:q\<CR>", 'tx!')
|
|
|
|
|
call assert_equal('w:test_', input)
|
|
|
|
|
|
|
|
|
|
" Buffer-local variables
|
|
|
|
|
let input = ''
|
|
|
|
|
call feedkeys("q:iGetInput b:test_\<C-x>\<C-v>\<CR>", 'tx!')
|
|
|
|
|
call assert_equal('b:test_bufvar', input)
|
|
|
|
|
|
|
|
|
|
let input = ''
|
|
|
|
|
call feedkeys("q::GetInput b:test_\<Tab>\<CR>:q\<CR>", 'tx!')
|
|
|
|
|
call assert_equal('b:test_', input)
|
|
|
|
|
|
2022-01-29 09:34:00 -07:00
|
|
|
|
|
|
|
|
|
" Argument completion of buffer-local command
|
|
|
|
|
func s:ComplInCmdwin_GlobalCompletionList(a, l, p)
|
|
|
|
|
return ['global']
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func s:ComplInCmdwin_LocalCompletionList(a, l, p)
|
|
|
|
|
return ['local']
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func s:ComplInCmdwin_CheckCompletion(arg)
|
|
|
|
|
call assert_equal('local', a:arg)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
com! -nargs=1 -complete=custom,<SID>ComplInCmdwin_GlobalCompletion
|
|
|
|
|
\ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
|
|
|
|
|
com! -buffer -nargs=1 -complete=custom,<SID>ComplInCmdwin_LocalCompletion
|
|
|
|
|
\ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
|
|
|
|
|
call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
|
|
|
|
|
|
|
|
|
|
com! -nargs=1 -complete=customlist,<SID>ComplInCmdwin_GlobalCompletionList
|
|
|
|
|
\ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
|
|
|
|
|
com! -buffer -nargs=1 -complete=customlist,<SID>ComplInCmdwin_LocalCompletionList
|
|
|
|
|
\ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
|
|
|
|
|
|
|
|
|
|
call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
|
|
|
|
|
|
|
|
|
|
func! s:ComplInCmdwin_CheckCompletion(arg)
|
|
|
|
|
call assert_equal('global', a:arg)
|
|
|
|
|
endfunc
|
|
|
|
|
new
|
|
|
|
|
call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
|
|
|
|
|
quit
|
|
|
|
|
|
|
|
|
|
delfunc s:ComplInCmdwin_GlobalCompletion
|
|
|
|
|
delfunc s:ComplInCmdwin_LocalCompletion
|
|
|
|
|
delfunc s:ComplInCmdwin_GlobalCompletionList
|
|
|
|
|
delfunc s:ComplInCmdwin_LocalCompletionList
|
|
|
|
|
delfunc s:ComplInCmdwin_CheckCompletion
|
|
|
|
|
|
|
|
|
|
delcom -buffer TestCommand
|
2019-11-24 19:50:24 -07:00
|
|
|
|
delcom TestCommand
|
|
|
|
|
delcom GetInput
|
2020-10-25 09:38:52 -07:00
|
|
|
|
unlet w:test_winvar
|
|
|
|
|
unlet b:test_bufvar
|
2019-11-24 19:50:24 -07:00
|
|
|
|
set wildmenu& wildchar&
|
|
|
|
|
endfunc
|
2020-10-08 15:52:18 -07:00
|
|
|
|
|
2020-10-18 19:36:30 -07:00
|
|
|
|
" Test for insert path completion with completeslash option
|
|
|
|
|
func Test_ins_completeslash()
|
2020-10-25 16:48:41 -07:00
|
|
|
|
CheckMSWindows
|
|
|
|
|
|
2020-10-18 19:36:30 -07:00
|
|
|
|
call mkdir('Xdir')
|
|
|
|
|
let orig_shellslash = &shellslash
|
|
|
|
|
set cpt&
|
|
|
|
|
new
|
2020-10-25 16:48:41 -07:00
|
|
|
|
|
2020-10-18 19:36:30 -07:00
|
|
|
|
set noshellslash
|
|
|
|
|
|
|
|
|
|
set completeslash=
|
|
|
|
|
exe "normal oXd\<C-X>\<C-F>"
|
|
|
|
|
call assert_equal('Xdir\', getline('.'))
|
|
|
|
|
|
|
|
|
|
set completeslash=backslash
|
|
|
|
|
exe "normal oXd\<C-X>\<C-F>"
|
|
|
|
|
call assert_equal('Xdir\', getline('.'))
|
|
|
|
|
|
|
|
|
|
set completeslash=slash
|
|
|
|
|
exe "normal oXd\<C-X>\<C-F>"
|
|
|
|
|
call assert_equal('Xdir/', getline('.'))
|
|
|
|
|
|
|
|
|
|
set shellslash
|
|
|
|
|
|
|
|
|
|
set completeslash=
|
|
|
|
|
exe "normal oXd\<C-X>\<C-F>"
|
|
|
|
|
call assert_equal('Xdir/', getline('.'))
|
|
|
|
|
|
|
|
|
|
set completeslash=backslash
|
|
|
|
|
exe "normal oXd\<C-X>\<C-F>"
|
|
|
|
|
call assert_equal('Xdir\', getline('.'))
|
|
|
|
|
|
|
|
|
|
set completeslash=slash
|
|
|
|
|
exe "normal oXd\<C-X>\<C-F>"
|
|
|
|
|
call assert_equal('Xdir/', getline('.'))
|
|
|
|
|
%bw!
|
|
|
|
|
call delete('Xdir', 'rf')
|
|
|
|
|
|
2020-10-25 16:48:41 -07:00
|
|
|
|
set noshellslash
|
|
|
|
|
set completeslash=slash
|
|
|
|
|
call assert_true(stridx(globpath(&rtp, 'syntax/*.vim', 1, 1)[0], '\') != -1)
|
|
|
|
|
|
2020-10-18 19:36:30 -07:00
|
|
|
|
let &shellslash = orig_shellslash
|
2020-10-25 16:48:41 -07:00
|
|
|
|
set completeslash=
|
2020-10-18 19:36:30 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-01-15 07:33:16 -07:00
|
|
|
|
func Test_pum_stopped_by_timer()
|
|
|
|
|
CheckScreendump
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
call setline(1, ['hello', 'hullo', 'heeee', ''])
|
|
|
|
|
func StartCompl()
|
|
|
|
|
call timer_start(100, { -> execute('stopinsert') })
|
|
|
|
|
call feedkeys("Gah\<C-N>")
|
|
|
|
|
endfunc
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
call writefile(lines, 'Xpumscript')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xpumscript', #{rows: 12})
|
|
|
|
|
call term_sendkeys(buf, ":call StartCompl()\<CR>")
|
|
|
|
|
call TermWait(buf, 200)
|
|
|
|
|
call term_sendkeys(buf, "k")
|
|
|
|
|
call VerifyScreenDump(buf, 'Test_pum_stopped_by_timer', {})
|
|
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
call delete('Xpumscript')
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-05-04 15:58:20 -07:00
|
|
|
|
func Test_complete_stopinsert_startinsert()
|
|
|
|
|
nnoremap <F2> <Cmd>startinsert<CR>
|
|
|
|
|
inoremap <F2> <Cmd>stopinsert<CR>
|
|
|
|
|
" This just checks if this causes an error
|
|
|
|
|
call feedkeys("i\<C-X>\<C-N>\<F2>\<F2>", 'x')
|
|
|
|
|
nunmap <F2>
|
|
|
|
|
iunmap <F2>
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-10-08 15:52:18 -07:00
|
|
|
|
func Test_pum_with_folds_two_tabs()
|
|
|
|
|
CheckScreendump
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set fdm=marker
|
|
|
|
|
call setline(1, ['" x {{{1', '" a some text'])
|
|
|
|
|
call setline(3, range(&lines)->map({_, val -> '" a' .. val}))
|
|
|
|
|
norm! zm
|
|
|
|
|
tab sp
|
|
|
|
|
call feedkeys('2Gzv', 'xt')
|
|
|
|
|
call feedkeys("0fa", 'xt')
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
call writefile(lines, 'Xpumscript')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xpumscript', #{rows: 10})
|
2023-08-20 23:59:52 -07:00
|
|
|
|
call TermWait(buf, 50)
|
2020-10-08 15:52:18 -07:00
|
|
|
|
call term_sendkeys(buf, "a\<C-N>")
|
|
|
|
|
call VerifyScreenDump(buf, 'Test_pum_with_folds_two_tabs', {})
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "\<Esc>")
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
call delete('Xpumscript')
|
|
|
|
|
endfunc
|
2020-12-12 07:52:23 -07:00
|
|
|
|
|
2023-01-21 05:50:46 -07:00
|
|
|
|
func Test_pum_with_preview_win()
|
|
|
|
|
CheckScreendump
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
2024-05-27 07:02:24 -07:00
|
|
|
|
funct Omni_test(findstart, base)
|
|
|
|
|
if a:findstart
|
|
|
|
|
return col(".") - 1
|
|
|
|
|
endif
|
|
|
|
|
return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}]
|
|
|
|
|
endfunc
|
|
|
|
|
set omnifunc=Omni_test
|
|
|
|
|
set completeopt+=longest
|
2023-01-21 05:50:46 -07:00
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
call writefile(lines, 'Xpreviewscript')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12})
|
|
|
|
|
call term_sendkeys(buf, "Gi\<C-X>\<C-O>")
|
2023-08-22 07:48:55 -07:00
|
|
|
|
call TermWait(buf, 200)
|
2023-01-21 05:50:46 -07:00
|
|
|
|
call term_sendkeys(buf, "\<C-N>")
|
|
|
|
|
call VerifyScreenDump(buf, 'Test_pum_with_preview_win', {})
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "\<Esc>")
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
call delete('Xpreviewscript')
|
2023-10-17 15:40:08 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_scrollbar_on_wide_char()
|
|
|
|
|
CheckScreendump
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
call setline(1, ['a', ' 啊啊啊',
|
|
|
|
|
\ ' 哦哦哦',
|
|
|
|
|
\ ' 呃呃呃'])
|
|
|
|
|
call setline(5, range(10)->map({i, v -> 'aa' .. v .. 'bb'}))
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'Xwidescript')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xwidescript', #{rows: 10})
|
|
|
|
|
call term_sendkeys(buf, "A\<C-N>")
|
|
|
|
|
call VerifyScreenDump(buf, 'Test_scrollbar_on_wide_char', {})
|
|
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
call delete('Xwidescript')
|
2023-01-21 05:50:46 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2021-03-21 07:16:12 -07:00
|
|
|
|
" Test for inserting the tag search pattern in insert mode
|
|
|
|
|
func Test_ins_compl_tag_sft()
|
|
|
|
|
call writefile([
|
|
|
|
|
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
|
|
|
|
|
\ "first\tXfoo\t/^int first() {}$/",
|
|
|
|
|
\ "second\tXfoo\t/^int second() {}$/",
|
|
|
|
|
\ "third\tXfoo\t/^int third() {}$/"],
|
|
|
|
|
\ 'Xtags')
|
|
|
|
|
set tags=Xtags
|
|
|
|
|
let code =<< trim [CODE]
|
|
|
|
|
int first() {}
|
|
|
|
|
int second() {}
|
|
|
|
|
int third() {}
|
|
|
|
|
[CODE]
|
|
|
|
|
call writefile(code, 'Xfoo')
|
|
|
|
|
|
|
|
|
|
enew
|
|
|
|
|
set showfulltag
|
|
|
|
|
exe "normal isec\<C-X>\<C-]>\<C-N>\<CR>"
|
|
|
|
|
call assert_equal('int second() {}', getline(1))
|
|
|
|
|
set noshowfulltag
|
|
|
|
|
|
|
|
|
|
call delete('Xtags')
|
|
|
|
|
call delete('Xfoo')
|
|
|
|
|
set tags&
|
|
|
|
|
%bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-16 20:57:42 -07:00
|
|
|
|
" Test for 'completefunc' deleting text
|
|
|
|
|
func Test_completefunc_error()
|
|
|
|
|
new
|
|
|
|
|
" delete text when called for the first time
|
|
|
|
|
func CompleteFunc(findstart, base)
|
|
|
|
|
if a:findstart == 1
|
|
|
|
|
normal dd
|
|
|
|
|
return col('.') - 1
|
|
|
|
|
endif
|
|
|
|
|
return ['a', 'b']
|
|
|
|
|
endfunc
|
|
|
|
|
set completefunc=CompleteFunc
|
|
|
|
|
call setline(1, ['', 'abcd', ''])
|
2022-07-16 21:21:39 -07:00
|
|
|
|
call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E565:')
|
2022-07-16 20:57:42 -07:00
|
|
|
|
|
|
|
|
|
" delete text when called for the second time
|
|
|
|
|
func CompleteFunc2(findstart, base)
|
|
|
|
|
if a:findstart == 1
|
|
|
|
|
return col('.') - 1
|
|
|
|
|
endif
|
|
|
|
|
normal dd
|
|
|
|
|
return ['a', 'b']
|
|
|
|
|
endfunc
|
|
|
|
|
set completefunc=CompleteFunc2
|
|
|
|
|
call setline(1, ['', 'abcd', ''])
|
|
|
|
|
call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E565:')
|
|
|
|
|
|
2022-07-16 21:13:29 -07:00
|
|
|
|
" Jump to a different window from the complete function
|
2022-07-16 20:47:34 -07:00
|
|
|
|
func CompleteFunc3(findstart, base)
|
2022-07-16 21:13:29 -07:00
|
|
|
|
if a:findstart == 1
|
|
|
|
|
return col('.') - 1
|
|
|
|
|
endif
|
|
|
|
|
wincmd p
|
|
|
|
|
return ['a', 'b']
|
|
|
|
|
endfunc
|
2022-07-16 20:47:34 -07:00
|
|
|
|
set completefunc=CompleteFunc3
|
2022-07-16 21:13:29 -07:00
|
|
|
|
new
|
2022-07-16 20:47:34 -07:00
|
|
|
|
call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E565:')
|
2022-07-16 21:13:29 -07:00
|
|
|
|
close!
|
|
|
|
|
|
|
|
|
|
set completefunc&
|
|
|
|
|
delfunc CompleteFunc
|
2022-07-16 20:47:34 -07:00
|
|
|
|
delfunc CompleteFunc2
|
|
|
|
|
delfunc CompleteFunc3
|
|
|
|
|
close!
|
2022-07-16 21:13:29 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-16 20:57:42 -07:00
|
|
|
|
" Test for returning non-string values from 'completefunc'
|
|
|
|
|
func Test_completefunc_invalid_data()
|
|
|
|
|
new
|
|
|
|
|
func! CompleteFunc(findstart, base)
|
|
|
|
|
if a:findstart == 1
|
|
|
|
|
return col('.') - 1
|
|
|
|
|
endif
|
|
|
|
|
return [{}, '', 'moon']
|
|
|
|
|
endfunc
|
|
|
|
|
set completefunc=CompleteFunc
|
|
|
|
|
exe "normal i\<C-X>\<C-U>"
|
|
|
|
|
call assert_equal('moon', getline(1))
|
|
|
|
|
set completefunc&
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for errors in using complete() function
|
|
|
|
|
func Test_complete_func_error()
|
|
|
|
|
call assert_fails('call complete(1, ["a"])', 'E785:')
|
|
|
|
|
func ListColors()
|
|
|
|
|
call complete(col('.'), "blue")
|
|
|
|
|
endfunc
|
|
|
|
|
call assert_fails('exe "normal i\<C-R>=ListColors()\<CR>"', 'E474:')
|
|
|
|
|
func ListMonths()
|
|
|
|
|
call complete(col('.'), test_null_list())
|
|
|
|
|
endfunc
|
|
|
|
|
" Nvim allows a NULL list
|
|
|
|
|
" call assert_fails('exe "normal i\<C-R>=ListMonths()\<CR>"', 'E474:')
|
|
|
|
|
delfunc ListColors
|
|
|
|
|
delfunc ListMonths
|
|
|
|
|
call assert_fails('call complete_info({})', 'E714:')
|
|
|
|
|
call assert_equal([], complete_info(['items']).items)
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 16:45:00 -07:00
|
|
|
|
" Test for recursively starting completion mode using complete()
|
|
|
|
|
func Test_recursive_complete_func()
|
|
|
|
|
func ListColors()
|
|
|
|
|
call complete(5, ["red", "blue"])
|
|
|
|
|
return ''
|
|
|
|
|
endfunc
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['a1', 'a2'])
|
|
|
|
|
set complete=.
|
|
|
|
|
exe "normal Goa\<C-X>\<C-L>\<C-R>=ListColors()\<CR>\<C-N>"
|
|
|
|
|
call assert_equal('a2blue', getline(3))
|
|
|
|
|
delfunc ListColors
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-09-24 06:13:32 -07:00
|
|
|
|
" Test for using complete() with completeopt+=longest
|
|
|
|
|
func Test_complete_with_longest()
|
|
|
|
|
new
|
2022-09-24 06:16:50 -07:00
|
|
|
|
inoremap <buffer> <f3> <cmd>call complete(1, ["iaax", "iaay", "iaaz"])<cr>
|
2022-09-24 06:13:32 -07:00
|
|
|
|
|
|
|
|
|
" default: insert first match
|
|
|
|
|
set completeopt&
|
|
|
|
|
call setline(1, ['i'])
|
|
|
|
|
exe "normal Aa\<f3>\<esc>"
|
|
|
|
|
call assert_equal('iaax', getline(1))
|
|
|
|
|
|
|
|
|
|
" with longest: insert longest prefix
|
|
|
|
|
set completeopt+=longest
|
|
|
|
|
call setline(1, ['i'])
|
|
|
|
|
exe "normal Aa\<f3>\<esc>"
|
|
|
|
|
call assert_equal('iaa', getline(1))
|
|
|
|
|
set completeopt&
|
2022-09-24 06:16:50 -07:00
|
|
|
|
bwipe!
|
2022-09-24 06:13:32 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2024-06-05 14:50:44 -07:00
|
|
|
|
" Test for buffer-local value of 'completeopt'
|
|
|
|
|
func Test_completeopt_buffer_local()
|
|
|
|
|
set completeopt=menu
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
|
|
|
|
|
call assert_equal('', &l:completeopt)
|
|
|
|
|
call assert_equal('menu', &completeopt)
|
|
|
|
|
call assert_equal('menu', &g:completeopt)
|
|
|
|
|
|
|
|
|
|
setlocal bufhidden=hide
|
|
|
|
|
enew
|
|
|
|
|
call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
|
|
|
|
|
call assert_equal('', &l:completeopt)
|
|
|
|
|
call assert_equal('menu', &completeopt)
|
|
|
|
|
call assert_equal('menu', &g:completeopt)
|
|
|
|
|
|
|
|
|
|
setlocal completeopt+=fuzzy,noinsert
|
|
|
|
|
call assert_equal('menu,fuzzy,noinsert', &l:completeopt)
|
|
|
|
|
call assert_equal('menu,fuzzy,noinsert', &completeopt)
|
|
|
|
|
call assert_equal('menu', &g:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>bz\<C-Y>", 'tnix')
|
|
|
|
|
call assert_equal('foobaz', getline('.'))
|
|
|
|
|
|
|
|
|
|
setlocal completeopt=
|
|
|
|
|
call assert_equal('', &l:completeopt)
|
|
|
|
|
call assert_equal('menu', &completeopt)
|
|
|
|
|
call assert_equal('menu', &g:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>\<C-Y>", 'tnix')
|
|
|
|
|
call assert_equal('foofoo', getline('.'))
|
|
|
|
|
|
|
|
|
|
setlocal completeopt+=longest
|
|
|
|
|
call assert_equal('menu,longest', &l:completeopt)
|
|
|
|
|
call assert_equal('menu,longest', &completeopt)
|
|
|
|
|
call assert_equal('menu', &g:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>\<C-X>\<C-Z>", 'tnix')
|
|
|
|
|
call assert_equal('foo', getline('.'))
|
|
|
|
|
|
|
|
|
|
setlocal bufhidden=hide
|
|
|
|
|
buffer #
|
|
|
|
|
call assert_equal('', &l:completeopt)
|
|
|
|
|
call assert_equal('menu', &completeopt)
|
|
|
|
|
call assert_equal('menu', &g:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>\<C-Y>", 'tnix')
|
|
|
|
|
call assert_equal('foofoo', getline('.'))
|
|
|
|
|
|
|
|
|
|
setlocal completeopt+=fuzzy,noinsert
|
|
|
|
|
call assert_equal('menu,fuzzy,noinsert', &l:completeopt)
|
|
|
|
|
call assert_equal('menu,fuzzy,noinsert', &completeopt)
|
|
|
|
|
call assert_equal('menu', &g:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>bz\<C-Y>", 'tnix')
|
|
|
|
|
call assert_equal('foobaz', getline('.'))
|
|
|
|
|
|
|
|
|
|
buffer #
|
|
|
|
|
call assert_equal('menu,longest', &l:completeopt)
|
|
|
|
|
call assert_equal('menu,longest', &completeopt)
|
|
|
|
|
call assert_equal('menu', &g:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>\<C-X>\<C-Z>", 'tnix')
|
|
|
|
|
call assert_equal('foo', getline('.'))
|
|
|
|
|
|
|
|
|
|
setlocal bufhidden=wipe
|
|
|
|
|
buffer! #
|
|
|
|
|
bwipe!
|
|
|
|
|
call assert_equal('', &l:completeopt)
|
|
|
|
|
call assert_equal('menu', &completeopt)
|
|
|
|
|
call assert_equal('menu', &g:completeopt)
|
|
|
|
|
|
2024-11-03 01:52:20 -07:00
|
|
|
|
new | only
|
|
|
|
|
call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
|
|
|
|
|
set completeopt&
|
|
|
|
|
setlocal completeopt=menu,fuzzy,noinsert
|
|
|
|
|
setglobal completeopt=menu,longest
|
|
|
|
|
call assert_equal('menu,fuzzy,noinsert', &completeopt)
|
|
|
|
|
call assert_equal('menu,fuzzy,noinsert', &l:completeopt)
|
|
|
|
|
call assert_equal('menu,longest', &g:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>bz\<C-Y>", 'tnix')
|
|
|
|
|
call assert_equal('foobaz', getline('.'))
|
|
|
|
|
setlocal bufhidden=wipe
|
|
|
|
|
new | only!
|
|
|
|
|
call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
|
|
|
|
|
call assert_equal('menu,longest', &completeopt)
|
|
|
|
|
call assert_equal('menu,longest', &g:completeopt)
|
|
|
|
|
call assert_equal('', &l:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>\<C-X>\<C-Z>", 'tnix')
|
|
|
|
|
call assert_equal('foo', getline('.'))
|
|
|
|
|
bwipe!
|
|
|
|
|
|
|
|
|
|
new | only
|
|
|
|
|
call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
|
|
|
|
|
set completeopt&
|
|
|
|
|
setlocal completeopt=menu,fuzzy,noinsert
|
|
|
|
|
set completeopt=menu,longest
|
|
|
|
|
call assert_equal('menu,longest', &completeopt)
|
|
|
|
|
call assert_equal('menu,longest', &g:completeopt)
|
|
|
|
|
call assert_equal('', &l:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>\<C-X>\<C-Z>", 'tnix')
|
|
|
|
|
call assert_equal('foo', getline('.'))
|
|
|
|
|
setlocal bufhidden=wipe
|
|
|
|
|
new | only!
|
|
|
|
|
call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
|
|
|
|
|
call assert_equal('menu,longest', &completeopt)
|
|
|
|
|
call assert_equal('menu,longest', &g:completeopt)
|
|
|
|
|
call assert_equal('', &l:completeopt)
|
|
|
|
|
call feedkeys("Gccf\<C-X>\<C-N>\<C-X>\<C-Z>", 'tnix')
|
|
|
|
|
call assert_equal('foo', getline('.'))
|
|
|
|
|
bwipe!
|
|
|
|
|
|
2024-06-05 14:50:44 -07:00
|
|
|
|
set completeopt&
|
|
|
|
|
endfunc
|
2022-09-24 06:13:32 -07:00
|
|
|
|
|
2022-07-16 18:23:49 -07:00
|
|
|
|
" Test for completing words following a completed word in a line
|
|
|
|
|
func Test_complete_wrapscan()
|
|
|
|
|
" complete words from another buffer
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['one two', 'three four'])
|
|
|
|
|
new
|
|
|
|
|
setlocal complete=w
|
|
|
|
|
call feedkeys("itw\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt')
|
|
|
|
|
call assert_equal('two three four', getline(1))
|
|
|
|
|
close!
|
|
|
|
|
" complete words from the current buffer
|
|
|
|
|
setlocal complete=.
|
|
|
|
|
%d
|
|
|
|
|
call setline(1, ['one two', ''])
|
|
|
|
|
call cursor(2, 1)
|
|
|
|
|
call feedkeys("ion\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt')
|
|
|
|
|
call assert_equal('one two one two', getline(2))
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-09-10 17:14:32 -07:00
|
|
|
|
" Test for completing special characters
|
|
|
|
|
func Test_complete_special_chars()
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'int .*[-\^$ func float')
|
|
|
|
|
call feedkeys("oin\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>", 'xt')
|
|
|
|
|
call assert_equal('int .*[-\^$ func float', getline(2))
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for completion when text is wrapped across lines.
|
|
|
|
|
func Test_complete_across_line()
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['red green blue', 'one two three'])
|
|
|
|
|
setlocal textwidth=20
|
|
|
|
|
exe "normal 2G$a re\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal(['one two three red', 'green blue one'], getline(2, '$'))
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-23 22:33:15 -07:00
|
|
|
|
" Test for completing words with a '.' at the end of a word.
|
|
|
|
|
func Test_complete_joinspaces()
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['one two.', 'three. four'])
|
|
|
|
|
set joinspaces
|
|
|
|
|
exe "normal Goon\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal("one two. three. four", getline(3))
|
|
|
|
|
set joinspaces&
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-09-10 17:14:32 -07:00
|
|
|
|
" Test for using CTRL-L to add one character when completing matching
|
|
|
|
|
func Test_complete_add_onechar()
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['wool', 'woodwork'])
|
|
|
|
|
call feedkeys("Gowoo\<C-P>\<C-P>\<C-P>\<C-L>f", 'xt')
|
|
|
|
|
call assert_equal('woof', getline(3))
|
|
|
|
|
|
|
|
|
|
" use 'ignorecase' and backspace to erase characters from the prefix string
|
|
|
|
|
" and then add letters using CTRL-L
|
|
|
|
|
%d
|
|
|
|
|
set ignorecase backspace=2
|
|
|
|
|
setlocal complete=.
|
|
|
|
|
call setline(1, ['workhorse', 'workload'])
|
|
|
|
|
normal Go
|
2023-10-17 02:49:22 -07:00
|
|
|
|
exe "normal aWOR\<C-P>\<bs>\<bs>\<bs>\<bs>\<bs>\<bs>\<C-L>\<C-L>\<C-L>"
|
2021-09-10 17:14:32 -07:00
|
|
|
|
call assert_equal('workh', getline(3))
|
|
|
|
|
set ignorecase& backspace&
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-23 22:33:15 -07:00
|
|
|
|
" Test for using CTRL-X CTRL-L to complete whole lines lines
|
|
|
|
|
func Test_complete_wholeline()
|
|
|
|
|
new
|
|
|
|
|
" complete one-line
|
|
|
|
|
call setline(1, ['a1', 'a2'])
|
|
|
|
|
exe "normal ggoa\<C-X>\<C-L>"
|
|
|
|
|
call assert_equal(['a1', 'a1', 'a2'], getline(1, '$'))
|
|
|
|
|
" go to the next match (wrapping around the buffer)
|
|
|
|
|
exe "normal 2GCa\<C-X>\<C-L>\<C-N>"
|
|
|
|
|
call assert_equal(['a1', 'a', 'a2'], getline(1, '$'))
|
|
|
|
|
" go to the next match
|
|
|
|
|
exe "normal 2GCa\<C-X>\<C-L>\<C-N>\<C-N>"
|
|
|
|
|
call assert_equal(['a1', 'a2', 'a2'], getline(1, '$'))
|
|
|
|
|
exe "normal 2GCa\<C-X>\<C-L>\<C-N>\<C-N>\<C-N>"
|
|
|
|
|
call assert_equal(['a1', 'a1', 'a2'], getline(1, '$'))
|
|
|
|
|
" repeat the test using CTRL-L
|
|
|
|
|
" go to the next match (wrapping around the buffer)
|
|
|
|
|
exe "normal 2GCa\<C-X>\<C-L>\<C-L>"
|
|
|
|
|
call assert_equal(['a1', 'a2', 'a2'], getline(1, '$'))
|
|
|
|
|
" go to the next match
|
|
|
|
|
exe "normal 2GCa\<C-X>\<C-L>\<C-L>\<C-L>"
|
|
|
|
|
call assert_equal(['a1', 'a', 'a2'], getline(1, '$'))
|
|
|
|
|
exe "normal 2GCa\<C-X>\<C-L>\<C-L>\<C-L>\<C-L>"
|
|
|
|
|
call assert_equal(['a1', 'a1', 'a2'], getline(1, '$'))
|
|
|
|
|
%d
|
|
|
|
|
" use CTRL-X CTRL-L to add one more line
|
|
|
|
|
call setline(1, ['a1', 'b1'])
|
|
|
|
|
setlocal complete=.
|
|
|
|
|
exe "normal ggOa\<C-X>\<C-L>\<C-X>\<C-L>\<C-X>\<C-L>"
|
|
|
|
|
call assert_equal(['a1', 'b1', '', 'a1', 'b1'], getline(1, '$'))
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-09-10 17:14:32 -07:00
|
|
|
|
" Test insert completion with 'cindent' (adjust the indent)
|
|
|
|
|
func Test_complete_with_cindent()
|
|
|
|
|
new
|
|
|
|
|
setlocal cindent
|
|
|
|
|
call setline(1, ['if (i == 1)', " j = 2;"])
|
|
|
|
|
exe "normal Go{\<CR>i\<C-X>\<C-L>\<C-X>\<C-L>\<CR>}"
|
|
|
|
|
call assert_equal(['{', "\tif (i == 1)", "\t\tj = 2;", '}'], getline(3, '$'))
|
|
|
|
|
|
|
|
|
|
%d
|
|
|
|
|
call setline(1, ['when while', '{', ''])
|
|
|
|
|
setlocal cinkeys+==while
|
|
|
|
|
exe "normal Giwh\<C-P> "
|
|
|
|
|
call assert_equal("\twhile ", getline('$'))
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for <CTRL-X> <CTRL-V> completion. Complete commands and functions
|
|
|
|
|
func Test_complete_cmdline()
|
|
|
|
|
new
|
|
|
|
|
exe "normal icaddb\<C-X>\<C-V>"
|
|
|
|
|
call assert_equal('caddbuffer', getline(1))
|
|
|
|
|
exe "normal ocall getqf\<C-X>\<C-V>"
|
|
|
|
|
call assert_equal('call getqflist(', getline(2))
|
|
|
|
|
exe "normal oabcxyz(\<C-X>\<C-V>"
|
|
|
|
|
call assert_equal('abcxyz(', getline(3))
|
|
|
|
|
com! -buffer TestCommand1 echo 'TestCommand1'
|
|
|
|
|
com! -buffer TestCommand2 echo 'TestCommand2'
|
|
|
|
|
write TestCommand1Test
|
|
|
|
|
write TestCommand2Test
|
|
|
|
|
" Test repeating <CTRL-X> <CTRL-V> and switching to another CTRL-X mode
|
|
|
|
|
exe "normal oT\<C-X>\<C-V>\<C-X>\<C-V>\<C-X>\<C-F>\<Esc>"
|
|
|
|
|
call assert_equal('TestCommand2Test', getline(4))
|
|
|
|
|
call delete('TestCommand1Test')
|
|
|
|
|
call delete('TestCommand2Test')
|
|
|
|
|
delcom TestCommand1
|
|
|
|
|
delcom TestCommand2
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for <CTRL-X> <CTRL-Z> stopping completion without changing the match
|
|
|
|
|
func Test_complete_stop()
|
|
|
|
|
new
|
|
|
|
|
func Save_mode1()
|
|
|
|
|
let g:mode1 = mode(1)
|
|
|
|
|
return ''
|
|
|
|
|
endfunc
|
|
|
|
|
func Save_mode2()
|
|
|
|
|
let g:mode2 = mode(1)
|
|
|
|
|
return ''
|
|
|
|
|
endfunc
|
|
|
|
|
inoremap <F1> <C-R>=Save_mode1()<CR>
|
|
|
|
|
inoremap <F2> <C-R>=Save_mode2()<CR>
|
|
|
|
|
call setline(1, ['aaa bbb ccc '])
|
|
|
|
|
exe "normal A\<C-N>\<C-P>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
|
|
|
|
|
call assert_equal('ic', g:mode1)
|
|
|
|
|
call assert_equal('i', g:mode2)
|
|
|
|
|
call assert_equal('aaa bbb ccc ', getline(1))
|
|
|
|
|
exe "normal A\<C-N>\<Down>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
|
|
|
|
|
call assert_equal('ic', g:mode1)
|
|
|
|
|
call assert_equal('i', g:mode2)
|
|
|
|
|
call assert_equal('aaa bbb ccc aaa', getline(1))
|
|
|
|
|
set completeopt+=noselect
|
|
|
|
|
exe "normal A \<C-N>\<Down>\<Down>\<C-L>\<C-L>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
|
|
|
|
|
call assert_equal('ic', g:mode1)
|
|
|
|
|
call assert_equal('i', g:mode2)
|
|
|
|
|
call assert_equal('aaa bbb ccc aaa bb', getline(1))
|
|
|
|
|
set completeopt&
|
|
|
|
|
exe "normal A d\<C-N>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
|
|
|
|
|
call assert_equal('ic', g:mode1)
|
|
|
|
|
call assert_equal('i', g:mode2)
|
|
|
|
|
call assert_equal('aaa bbb ccc aaa bb d', getline(1))
|
|
|
|
|
com! -buffer TestCommand1 echo 'TestCommand1'
|
|
|
|
|
com! -buffer TestCommand2 echo 'TestCommand2'
|
|
|
|
|
exe "normal oT\<C-X>\<C-V>\<C-X>\<C-V>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
|
|
|
|
|
call assert_equal('ic', g:mode1)
|
|
|
|
|
call assert_equal('i', g:mode2)
|
|
|
|
|
call assert_equal('TestCommand2', getline(2))
|
|
|
|
|
delcom TestCommand1
|
|
|
|
|
delcom TestCommand2
|
|
|
|
|
unlet g:mode1
|
|
|
|
|
unlet g:mode2
|
|
|
|
|
iunmap <F1>
|
|
|
|
|
iunmap <F2>
|
|
|
|
|
delfunc Save_mode1
|
|
|
|
|
delfunc Save_mode2
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-23 22:15:38 -07:00
|
|
|
|
" Test for typing CTRL-R in insert completion mode to insert a register
|
|
|
|
|
" content.
|
|
|
|
|
func Test_complete_reginsert()
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['a1', 'a12', 'a123', 'a1234'])
|
|
|
|
|
|
|
|
|
|
" if a valid CTRL-X mode key is returned from <C-R>=, then it should be
|
|
|
|
|
" processed. Otherwise, CTRL-X mode should be stopped and the key should be
|
|
|
|
|
" inserted.
|
|
|
|
|
exe "normal Goa\<C-P>\<C-R>=\"\\<C-P>\"\<CR>"
|
|
|
|
|
call assert_equal('a123', getline(5))
|
|
|
|
|
let @r = "\<C-P>\<C-P>"
|
|
|
|
|
exe "normal GCa\<C-P>\<C-R>r"
|
|
|
|
|
call assert_equal('a12', getline(5))
|
|
|
|
|
exe "normal GCa\<C-P>\<C-R>=\"x\"\<CR>"
|
|
|
|
|
call assert_equal('a1234x', getline(5))
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-20 15:00:16 -07:00
|
|
|
|
func Test_issue_7021()
|
|
|
|
|
CheckMSWindows
|
|
|
|
|
|
|
|
|
|
let orig_shellslash = &shellslash
|
|
|
|
|
set noshellslash
|
|
|
|
|
|
|
|
|
|
set completeslash=slash
|
|
|
|
|
call assert_false(expand('~') =~ '/')
|
|
|
|
|
|
|
|
|
|
let &shellslash = orig_shellslash
|
|
|
|
|
set completeslash=
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 16:45:00 -07:00
|
|
|
|
" Test for 'longest' setting in 'completeopt' with latin1 and utf-8 encodings
|
|
|
|
|
func Test_complete_longest_match()
|
|
|
|
|
" for e in ['latin1', 'utf-8']
|
|
|
|
|
for e in ['utf-8']
|
|
|
|
|
exe 'set encoding=' .. e
|
|
|
|
|
new
|
|
|
|
|
set complete=.
|
|
|
|
|
set completeopt=menu,longest
|
|
|
|
|
call setline(1, ['pfx_a1', 'pfx_a12', 'pfx_a123', 'pfx_b1'])
|
|
|
|
|
exe "normal Gopfx\<C-P>"
|
|
|
|
|
call assert_equal('pfx_', getline(5))
|
|
|
|
|
bw!
|
|
|
|
|
endfor
|
|
|
|
|
|
|
|
|
|
" Test for completing additional words with longest match set
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['abc1', 'abd2'])
|
|
|
|
|
exe "normal Goab\<C-P>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal('ab', getline(3))
|
|
|
|
|
bw!
|
|
|
|
|
set complete& completeopt&
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for removing the first displayed completion match and selecting the
|
|
|
|
|
" match just before that.
|
|
|
|
|
func Test_complete_erase_firstmatch()
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['a12', 'a34', 'a56'])
|
|
|
|
|
set complete=.
|
|
|
|
|
exe "normal Goa\<C-P>\<BS>\<BS>3\<CR>"
|
|
|
|
|
call assert_equal('a34', getline('$'))
|
|
|
|
|
set complete&
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 17:04:25 -07:00
|
|
|
|
" Test for completing words from unloaded buffers
|
|
|
|
|
func Test_complete_from_unloadedbuf()
|
|
|
|
|
call writefile(['abc'], "Xfile1")
|
|
|
|
|
call writefile(['def'], "Xfile2")
|
|
|
|
|
edit Xfile1
|
|
|
|
|
edit Xfile2
|
|
|
|
|
new | close
|
|
|
|
|
enew
|
|
|
|
|
bunload Xfile1 Xfile2
|
|
|
|
|
set complete=u
|
|
|
|
|
" complete from an unloaded buffer
|
|
|
|
|
exe "normal! ia\<C-P>"
|
|
|
|
|
call assert_equal('abc', getline(1))
|
|
|
|
|
exe "normal! od\<C-P>"
|
|
|
|
|
call assert_equal('def', getline(2))
|
|
|
|
|
set complete&
|
|
|
|
|
%bw!
|
|
|
|
|
call delete("Xfile1")
|
|
|
|
|
call delete("Xfile2")
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 16:45:00 -07:00
|
|
|
|
" Test for completing whole lines from unloaded buffers
|
|
|
|
|
func Test_complete_wholeline_unloadedbuf()
|
|
|
|
|
call writefile(['a line1', 'a line2', 'a line3'], "Xfile1")
|
|
|
|
|
edit Xfile1
|
|
|
|
|
enew
|
|
|
|
|
set complete=u
|
|
|
|
|
exe "normal! ia\<C-X>\<C-L>\<C-P>"
|
|
|
|
|
call assert_equal('a line2', getline(1))
|
|
|
|
|
%d
|
|
|
|
|
" completing from an unlisted buffer should fail
|
|
|
|
|
bdel Xfile1
|
|
|
|
|
exe "normal! ia\<C-X>\<C-L>\<C-P>"
|
|
|
|
|
call assert_equal('a', getline(1))
|
|
|
|
|
set complete&
|
|
|
|
|
%bw!
|
|
|
|
|
call delete("Xfile1")
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 17:04:25 -07:00
|
|
|
|
" Test for completing words from unlisted buffers
|
|
|
|
|
func Test_complete_from_unlistedbuf()
|
|
|
|
|
call writefile(['abc'], "Xfile1")
|
|
|
|
|
call writefile(['def'], "Xfile2")
|
|
|
|
|
edit Xfile1
|
|
|
|
|
edit Xfile2
|
|
|
|
|
new | close
|
|
|
|
|
bdel Xfile1 Xfile2
|
|
|
|
|
set complete=U
|
|
|
|
|
" complete from an unlisted buffer
|
|
|
|
|
exe "normal! ia\<C-P>"
|
|
|
|
|
call assert_equal('abc', getline(1))
|
|
|
|
|
exe "normal! od\<C-P>"
|
|
|
|
|
call assert_equal('def', getline(2))
|
|
|
|
|
set complete&
|
|
|
|
|
%bw!
|
|
|
|
|
call delete("Xfile1")
|
|
|
|
|
call delete("Xfile2")
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 16:45:00 -07:00
|
|
|
|
" Test for completing whole lines from unlisted buffers
|
|
|
|
|
func Test_complete_wholeline_unlistedbuf()
|
|
|
|
|
call writefile(['a line1', 'a line2', 'a line3'], "Xfile1")
|
|
|
|
|
edit Xfile1
|
|
|
|
|
enew
|
|
|
|
|
set complete=U
|
2024-03-28 04:03:27 -07:00
|
|
|
|
" completing from an unloaded buffer should fail
|
2022-08-24 16:45:00 -07:00
|
|
|
|
exe "normal! ia\<C-X>\<C-L>\<C-P>"
|
|
|
|
|
call assert_equal('a', getline(1))
|
|
|
|
|
%d
|
|
|
|
|
bdel Xfile1
|
|
|
|
|
exe "normal! ia\<C-X>\<C-L>\<C-P>"
|
|
|
|
|
call assert_equal('a line2', getline(1))
|
|
|
|
|
set complete&
|
|
|
|
|
%bw!
|
|
|
|
|
call delete("Xfile1")
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for adding a multibyte character using CTRL-L in completion mode
|
|
|
|
|
func Test_complete_mbyte_char_add()
|
|
|
|
|
new
|
|
|
|
|
set complete=.
|
|
|
|
|
call setline(1, 'abė')
|
|
|
|
|
exe "normal! oa\<C-P>\<BS>\<BS>\<C-L>\<C-L>"
|
|
|
|
|
call assert_equal('abė', getline(2))
|
|
|
|
|
" Test for a leader with multibyte character
|
|
|
|
|
%d
|
|
|
|
|
call setline(1, 'abėĕ')
|
|
|
|
|
exe "normal! oabė\<C-P>"
|
|
|
|
|
call assert_equal('abėĕ', getline(2))
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 17:04:25 -07:00
|
|
|
|
" Test for using <C-X><C-P> for local expansion even if 'complete' is set to
|
|
|
|
|
" not to complete matches from the local buffer. Also test using multiple
|
|
|
|
|
" <C-X> to cancel the current completion mode.
|
|
|
|
|
func Test_complete_local_expansion()
|
|
|
|
|
new
|
|
|
|
|
set complete=t
|
|
|
|
|
call setline(1, ['abc', 'def'])
|
|
|
|
|
exe "normal! Go\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal("def", getline(3))
|
|
|
|
|
exe "normal! Go\<C-P>"
|
|
|
|
|
call assert_equal("", getline(4))
|
|
|
|
|
exe "normal! Go\<C-X>\<C-N>"
|
|
|
|
|
call assert_equal("abc", getline(5))
|
|
|
|
|
exe "normal! Go\<C-N>"
|
|
|
|
|
call assert_equal("", getline(6))
|
|
|
|
|
|
|
|
|
|
" use multiple <C-X> to cancel the previous completion mode
|
|
|
|
|
exe "normal! Go\<C-P>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal("", getline(7))
|
|
|
|
|
exe "normal! Go\<C-P>\<C-X>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal("", getline(8))
|
|
|
|
|
exe "normal! Go\<C-P>\<C-X>\<C-X>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal("abc", getline(9))
|
|
|
|
|
|
|
|
|
|
" interrupt the current completion mode
|
|
|
|
|
set completeopt=menu,noinsert
|
|
|
|
|
exe "normal! Go\<C-X>\<C-F>\<C-X>\<C-X>\<C-P>\<C-Y>"
|
|
|
|
|
call assert_equal("abc", getline(10))
|
|
|
|
|
|
|
|
|
|
" when only one <C-X> is used to interrupt, do normal expansion
|
|
|
|
|
exe "normal! Go\<C-X>\<C-F>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal("", getline(11))
|
|
|
|
|
set completeopt&
|
|
|
|
|
|
|
|
|
|
" using two <C-X> in non-completion mode and restarting the same mode
|
|
|
|
|
exe "normal! God\<C-X>\<C-X>\<C-P>\<C-X>\<C-X>\<C-P>\<C-Y>"
|
|
|
|
|
call assert_equal("def", getline(12))
|
|
|
|
|
|
|
|
|
|
" test for adding a match from the original empty text
|
|
|
|
|
%d
|
|
|
|
|
call setline(1, 'abc def g')
|
|
|
|
|
exe "normal! o\<C-X>\<C-P>\<C-N>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal('def', getline(2))
|
|
|
|
|
exe "normal! 0C\<C-X>\<C-N>\<C-P>\<C-X>\<C-N>"
|
|
|
|
|
call assert_equal('abc', getline(2))
|
|
|
|
|
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for undoing changes after a insert-mode completion
|
|
|
|
|
func Test_complete_undo()
|
|
|
|
|
new
|
|
|
|
|
set complete=.
|
|
|
|
|
" undo with 'ignorecase'
|
|
|
|
|
call setline(1, ['ABOVE', 'BELOW'])
|
|
|
|
|
set ignorecase
|
|
|
|
|
exe "normal! Goab\<C-G>u\<C-P>"
|
|
|
|
|
call assert_equal("ABOVE", getline(3))
|
|
|
|
|
undo
|
|
|
|
|
call assert_equal("ab", getline(3))
|
|
|
|
|
set ignorecase&
|
|
|
|
|
%d
|
|
|
|
|
" undo with longest match
|
|
|
|
|
set completeopt=menu,longest
|
|
|
|
|
call setline(1, ['above', 'about'])
|
|
|
|
|
exe "normal! Goa\<C-G>u\<C-P>"
|
|
|
|
|
call assert_equal("abo", getline(3))
|
|
|
|
|
undo
|
|
|
|
|
call assert_equal("a", getline(3))
|
|
|
|
|
set completeopt&
|
|
|
|
|
%d
|
|
|
|
|
" undo for line completion
|
|
|
|
|
call setline(1, ['above that change', 'below that change'])
|
|
|
|
|
exe "normal! Goabove\<C-G>u\<C-X>\<C-L>"
|
|
|
|
|
call assert_equal("above that change", getline(3))
|
|
|
|
|
undo
|
|
|
|
|
call assert_equal("above", getline(3))
|
|
|
|
|
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for completing a very long word
|
|
|
|
|
func Test_complete_long_word()
|
|
|
|
|
set complete&
|
|
|
|
|
new
|
|
|
|
|
call setline(1, repeat('x', 950) .. ' one two three')
|
|
|
|
|
exe "normal! Gox\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal(repeat('x', 950) .. ' one two three', getline(2))
|
|
|
|
|
%d
|
|
|
|
|
" should fail when more than 950 characters are in a word
|
|
|
|
|
call setline(1, repeat('x', 951) .. ' one two three')
|
|
|
|
|
exe "normal! Gox\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal(repeat('x', 951), getline(2))
|
|
|
|
|
|
|
|
|
|
" Test for adding a very long word to an existing completion
|
|
|
|
|
%d
|
|
|
|
|
call setline(1, ['abc', repeat('x', 1016) .. '012345'])
|
|
|
|
|
exe "normal! Goab\<C-P>\<C-X>\<C-P>"
|
|
|
|
|
call assert_equal('abc ' .. repeat('x', 1016) .. '0123', getline(3))
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for some fields in the complete items used by complete()
|
|
|
|
|
func Test_complete_items()
|
|
|
|
|
func CompleteItems(idx)
|
|
|
|
|
let items = [[#{word: "one", dup: 1, user_data: 'u1'}, #{word: "one", dup: 1, user_data: 'u2'}],
|
|
|
|
|
\ [#{word: "one", dup: 0, user_data: 'u3'}, #{word: "one", dup: 0, user_data: 'u4'}],
|
|
|
|
|
\ [#{word: "one", icase: 1, user_data: 'u7'}, #{word: "oNE", icase: 1, user_data: 'u8'}],
|
|
|
|
|
\ [#{user_data: 'u9'}],
|
|
|
|
|
\ [#{word: "", user_data: 'u10'}],
|
|
|
|
|
\ [#{word: "", empty: 1, user_data: 'u11'}]]
|
|
|
|
|
call complete(col('.'), items[a:idx])
|
|
|
|
|
return ''
|
|
|
|
|
endfunc
|
|
|
|
|
new
|
|
|
|
|
exe "normal! i\<C-R>=CompleteItems(0)\<CR>\<C-N>\<C-Y>"
|
|
|
|
|
call assert_equal('u2', v:completed_item.user_data)
|
|
|
|
|
call assert_equal('one', getline(1))
|
|
|
|
|
exe "normal! o\<C-R>=CompleteItems(1)\<CR>\<C-Y>"
|
|
|
|
|
call assert_equal('u3', v:completed_item.user_data)
|
|
|
|
|
call assert_equal('one', getline(2))
|
|
|
|
|
exe "normal! o\<C-R>=CompleteItems(1)\<CR>\<C-N>"
|
|
|
|
|
call assert_equal('', getline(3))
|
|
|
|
|
set completeopt=menu,noinsert
|
|
|
|
|
exe "normal! o\<C-R>=CompleteItems(2)\<CR>one\<C-N>\<C-Y>"
|
|
|
|
|
call assert_equal('oNE', getline(4))
|
|
|
|
|
call assert_equal('u8', v:completed_item.user_data)
|
|
|
|
|
set completeopt&
|
|
|
|
|
exe "normal! o\<C-R>=CompleteItems(3)\<CR>"
|
|
|
|
|
call assert_equal('', getline(5))
|
|
|
|
|
exe "normal! o\<C-R>=CompleteItems(4)\<CR>"
|
|
|
|
|
call assert_equal('', getline(6))
|
|
|
|
|
exe "normal! o\<C-R>=CompleteItems(5)\<CR>"
|
|
|
|
|
call assert_equal('', getline(7))
|
|
|
|
|
call assert_equal('u11', v:completed_item.user_data)
|
|
|
|
|
" pass invalid argument to complete()
|
|
|
|
|
let cmd = "normal! o\<C-R>=complete(1, [[]])\<CR>"
|
|
|
|
|
call assert_fails('exe cmd', 'E730:')
|
|
|
|
|
bw!
|
|
|
|
|
delfunc CompleteItems
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for the "refresh" item in the dict returned by an insert completion
|
|
|
|
|
" function
|
|
|
|
|
func Test_complete_item_refresh_always()
|
|
|
|
|
let g:CallCount = 0
|
|
|
|
|
func! Tcomplete(findstart, base)
|
|
|
|
|
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
|
|
|
|
|
let g:CallCount += 1
|
|
|
|
|
let res = ["update1", "update12", "update123"]
|
|
|
|
|
return #{words: res, refresh: 'always'}
|
|
|
|
|
endif
|
|
|
|
|
endfunc
|
|
|
|
|
new
|
|
|
|
|
set completeopt=menu,longest
|
|
|
|
|
set completefunc=Tcomplete
|
|
|
|
|
exe "normal! iup\<C-X>\<C-U>\<BS>\<BS>\<BS>\<BS>\<BS>"
|
|
|
|
|
call assert_equal('up', getline(1))
|
2024-12-01 17:06:57 -07:00
|
|
|
|
call assert_equal(6, g:CallCount)
|
2022-08-24 17:04:25 -07:00
|
|
|
|
set completeopt&
|
|
|
|
|
set completefunc&
|
|
|
|
|
bw!
|
|
|
|
|
delfunc Tcomplete
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for completing from a thesaurus file without read permission
|
|
|
|
|
func Test_complete_unreadable_thesaurus_file()
|
|
|
|
|
CheckUnix
|
|
|
|
|
CheckNotRoot
|
|
|
|
|
|
|
|
|
|
call writefile(['about', 'above'], 'Xfile')
|
|
|
|
|
call setfperm('Xfile', '---r--r--')
|
|
|
|
|
new
|
|
|
|
|
set complete=sXfile
|
|
|
|
|
exe "normal! ia\<C-P>"
|
|
|
|
|
call assert_equal('a', getline(1))
|
|
|
|
|
bw!
|
|
|
|
|
call delete('Xfile')
|
|
|
|
|
set complete&
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-12-12 07:52:23 -07:00
|
|
|
|
" Test to ensure 'Scanning...' messages are not recorded in messages history
|
|
|
|
|
func Test_z1_complete_no_history()
|
|
|
|
|
new
|
|
|
|
|
messages clear
|
|
|
|
|
let currmess = execute('messages')
|
|
|
|
|
setlocal dictionary=README.txt
|
|
|
|
|
exe "normal owh\<C-X>\<C-K>"
|
|
|
|
|
exe "normal owh\<C-N>"
|
|
|
|
|
call assert_equal(currmess, execute('messages'))
|
2022-07-20 15:00:16 -07:00
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" A mapping is not used for the key after CTRL-X.
|
|
|
|
|
func Test_no_mapping_for_ctrl_x_key()
|
|
|
|
|
new
|
2022-09-24 06:16:50 -07:00
|
|
|
|
inoremap <buffer> <C-K> <Cmd>let was_mapped = 'yes'<CR>
|
2022-07-20 15:00:16 -07:00
|
|
|
|
setlocal dictionary=README.txt
|
|
|
|
|
call feedkeys("aexam\<C-X>\<C-K> ", 'xt')
|
|
|
|
|
call assert_equal('example ', getline(1))
|
|
|
|
|
call assert_false(exists('was_mapped'))
|
|
|
|
|
bwipe!
|
2020-12-12 07:52:23 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-19 17:45:15 -07:00
|
|
|
|
" Test for different ways of setting the 'completefunc' option
|
|
|
|
|
func Test_completefunc_callback()
|
2022-11-06 23:08:29 -07:00
|
|
|
|
func CompleteFunc1(callnr, findstart, base)
|
|
|
|
|
call add(g:CompleteFunc1Args, [a:callnr, a:findstart, a:base])
|
|
|
|
|
return a:findstart ? 0 : []
|
|
|
|
|
endfunc
|
|
|
|
|
func CompleteFunc2(findstart, base)
|
|
|
|
|
call add(g:CompleteFunc2Args, [a:findstart, a:base])
|
2022-08-19 17:45:15 -07:00
|
|
|
|
return a:findstart ? 0 : []
|
|
|
|
|
endfunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
let lines =<< trim END
|
2022-12-02 05:47:52 -07:00
|
|
|
|
#" Test for using a global function name
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET &completefunc = 'g:CompleteFunc2'
|
|
|
|
|
new
|
2022-12-02 05:47:52 -07:00
|
|
|
|
call setline(1, 'global')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc2Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-12-02 05:47:52 -07:00
|
|
|
|
call assert_equal([[1, ''], [0, 'global']], g:CompleteFunc2Args)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
bw!
|
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a function()
|
2022-11-06 23:08:29 -07:00
|
|
|
|
set completefunc=function('g:CompleteFunc1',\ [10])
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'one')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[10, 1, ''], [10, 0, 'one']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a funcref variable to set 'completefunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
VAR Fn = function('g:CompleteFunc1', [11])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &completefunc = Fn
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'two')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[11, 1, ''], [11, 0, 'two']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using string(funcref_variable) to set 'completefunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Fn = function('g:CompleteFunc1', [12])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &completefunc = string(Fn)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'two')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[12, 1, ''], [12, 0, 'two']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a funcref()
|
2022-11-06 23:08:29 -07:00
|
|
|
|
set completefunc=funcref('g:CompleteFunc1',\ [13])
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'three')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[13, 1, ''], [13, 0, 'three']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a funcref variable to set 'completefunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Fn = funcref('g:CompleteFunc1', [14])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &completefunc = Fn
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'four')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[14, 1, ''], [14, 0, 'four']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a string(funcref_variable) to set 'completefunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Fn = funcref('g:CompleteFunc1', [15])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &completefunc = string(Fn)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'four')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[15, 1, ''], [15, 0, 'four']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a lambda function with set
|
2022-11-06 23:08:29 -07:00
|
|
|
|
VAR optval = "LSTART a, b LMIDDLE CompleteFunc1(16, a, b) LEND"
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET optval = substitute(optval, ' ', '\\ ', 'g')
|
|
|
|
|
exe "set completefunc=" .. optval
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'five')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[16, 1, ''], [16, 0, 'five']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'completefunc' to a lambda expression
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET &completefunc = LSTART a, b LMIDDLE CompleteFunc1(17, a, b) LEND
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'six')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[17, 1, ''], [17, 0, 'six']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'completefunc' to string(lambda_expression)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET &completefunc = 'LSTART a, b LMIDDLE CompleteFunc1(18, a, b) LEND'
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'six')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[18, 1, ''], [18, 0, 'six']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'completefunc' to a variable with a lambda expression
|
2022-11-06 23:08:29 -07:00
|
|
|
|
VAR Lambda = LSTART a, b LMIDDLE CompleteFunc1(19, a, b) LEND
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &completefunc = Lambda
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'seven')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'completefunc' to a string(variable with a lambda expression)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Lambda = LSTART a, b LMIDDLE CompleteFunc1(20, a, b) LEND
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &completefunc = string(Lambda)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'seven')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:CompleteFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a lambda function with incorrect return value
|
|
|
|
|
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
|
|
|
|
|
LET &completefunc = Lambda
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'eight')
|
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for clearing the 'completefunc' option
|
|
|
|
|
set completefunc=''
|
|
|
|
|
set completefunc&
|
|
|
|
|
call assert_fails("set completefunc=function('abc')", "E700:")
|
|
|
|
|
call assert_fails("set completefunc=funcref('abc')", "E700:")
|
|
|
|
|
|
|
|
|
|
#" set 'completefunc' to a non-existing function
|
2022-11-06 23:08:29 -07:00
|
|
|
|
set completefunc=CompleteFunc2
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'five')
|
|
|
|
|
call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:')
|
|
|
|
|
call assert_fails("LET &completefunc = function('NonExistingFunc')", 'E700:')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:CompleteFunc2Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[1, ''], [0, 'five']], g:CompleteFunc2Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
|
|
|
|
END
|
|
|
|
|
call CheckLegacyAndVim9Success(lines)
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-12-02 05:47:52 -07:00
|
|
|
|
" Test for using a script-local function name
|
|
|
|
|
func s:CompleteFunc3(findstart, base)
|
|
|
|
|
call add(g:CompleteFunc3Args, [a:findstart, a:base])
|
|
|
|
|
return a:findstart ? 0 : []
|
|
|
|
|
endfunc
|
|
|
|
|
set completefunc=s:CompleteFunc3
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'script1')
|
|
|
|
|
let g:CompleteFunc3Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'script1']], g:CompleteFunc3Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
let &completefunc = 's:CompleteFunc3'
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'script2')
|
|
|
|
|
let g:CompleteFunc3Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'script2']], g:CompleteFunc3Args)
|
|
|
|
|
bw!
|
|
|
|
|
delfunc s:CompleteFunc3
|
|
|
|
|
|
2024-08-01 19:58:10 -07:00
|
|
|
|
" In Vim9 script s: can be omitted
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
vim9script
|
|
|
|
|
var CompleteFunc4Args = []
|
|
|
|
|
def CompleteFunc4(findstart: bool, base: string): any
|
|
|
|
|
add(CompleteFunc4Args, [findstart, base])
|
|
|
|
|
return findstart ? 0 : []
|
|
|
|
|
enddef
|
|
|
|
|
set completefunc=CompleteFunc4
|
|
|
|
|
new
|
|
|
|
|
setline(1, 'script1')
|
|
|
|
|
feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
|
|
|
|
assert_equal([[1, ''], [0, 'script1']], CompleteFunc4Args)
|
|
|
|
|
bw!
|
|
|
|
|
END
|
|
|
|
|
call CheckScriptSuccess(lines)
|
|
|
|
|
|
2022-12-02 05:47:52 -07:00
|
|
|
|
" invalid return value
|
2022-11-06 19:26:54 -07:00
|
|
|
|
let &completefunc = {a -> 'abc'}
|
2022-08-19 17:45:15 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
|
|
|
|
|
2022-11-06 20:20:42 -07:00
|
|
|
|
" Using Vim9 lambda expression in legacy context should fail
|
2024-11-02 19:06:41 -07:00
|
|
|
|
set completefunc=(a,\ b)\ =>\ CompleteFunc1(21,\ a,\ b)
|
2022-11-06 20:20:42 -07:00
|
|
|
|
new | only
|
2022-11-06 23:08:29 -07:00
|
|
|
|
let g:CompleteFunc1Args = []
|
2024-11-02 19:06:41 -07:00
|
|
|
|
call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([], g:CompleteFunc1Args)
|
2022-11-06 20:20:42 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
" set 'completefunc' to a partial with dict. This used to cause a crash.
|
|
|
|
|
func SetCompleteFunc()
|
|
|
|
|
let params = {'complete': function('g:DictCompleteFunc')}
|
|
|
|
|
let &completefunc = params.complete
|
2022-11-06 20:20:42 -07:00
|
|
|
|
endfunc
|
2022-11-06 22:37:22 -07:00
|
|
|
|
func g:DictCompleteFunc(_) dict
|
|
|
|
|
endfunc
|
|
|
|
|
call SetCompleteFunc()
|
|
|
|
|
new
|
|
|
|
|
call SetCompleteFunc()
|
|
|
|
|
bw
|
|
|
|
|
call test_garbagecollect_now()
|
|
|
|
|
new
|
|
|
|
|
set completefunc=
|
|
|
|
|
wincmd w
|
|
|
|
|
set completefunc=
|
|
|
|
|
%bw!
|
|
|
|
|
delfunc g:DictCompleteFunc
|
|
|
|
|
delfunc SetCompleteFunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
|
2022-08-19 17:45:15 -07:00
|
|
|
|
" Vim9 tests
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
vim9script
|
|
|
|
|
|
2022-12-02 05:47:52 -07:00
|
|
|
|
def Vim9CompleteFunc(callnr: number, findstart: number, base: string): any
|
|
|
|
|
add(g:Vim9completeFuncArgs, [callnr, findstart, base])
|
2022-08-19 17:45:15 -07:00
|
|
|
|
return findstart ? 0 : []
|
|
|
|
|
enddef
|
2022-12-02 05:47:52 -07:00
|
|
|
|
|
|
|
|
|
# Test for using a def function with completefunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
set completefunc=function('Vim9CompleteFunc',\ [60])
|
2022-08-19 17:45:15 -07:00
|
|
|
|
new | only
|
|
|
|
|
setline(1, 'one')
|
2022-11-06 20:20:42 -07:00
|
|
|
|
g:Vim9completeFuncArgs = []
|
2022-08-19 17:45:15 -07:00
|
|
|
|
feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
2022-11-06 20:20:42 -07:00
|
|
|
|
assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9completeFuncArgs)
|
2022-08-19 17:45:15 -07:00
|
|
|
|
bw!
|
2022-12-02 05:47:52 -07:00
|
|
|
|
|
|
|
|
|
# Test for using a global function name
|
|
|
|
|
&completefunc = g:CompleteFunc2
|
|
|
|
|
new | only
|
|
|
|
|
setline(1, 'two')
|
|
|
|
|
g:CompleteFunc2Args = []
|
|
|
|
|
feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
|
|
|
|
assert_equal([[1, ''], [0, 'two']], g:CompleteFunc2Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
# Test for using a script-local function name
|
2023-04-15 02:12:59 -07:00
|
|
|
|
def LocalCompleteFunc(findstart: number, base: string): any
|
2022-12-02 05:47:52 -07:00
|
|
|
|
add(g:LocalCompleteFuncArgs, [findstart, base])
|
|
|
|
|
return findstart ? 0 : []
|
|
|
|
|
enddef
|
2023-04-15 02:12:59 -07:00
|
|
|
|
&completefunc = LocalCompleteFunc
|
2022-12-02 05:47:52 -07:00
|
|
|
|
new | only
|
|
|
|
|
setline(1, 'three')
|
|
|
|
|
g:LocalCompleteFuncArgs = []
|
|
|
|
|
feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
|
|
|
|
assert_equal([[1, ''], [0, 'three']], g:LocalCompleteFuncArgs)
|
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
END
|
2022-12-03 05:27:09 -07:00
|
|
|
|
call CheckScriptSuccess(lines)
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
|
|
|
|
" cleanup
|
|
|
|
|
set completefunc&
|
2022-11-06 23:08:29 -07:00
|
|
|
|
delfunc CompleteFunc1
|
|
|
|
|
delfunc CompleteFunc2
|
|
|
|
|
unlet g:CompleteFunc1Args g:CompleteFunc2Args
|
2022-08-19 17:45:15 -07:00
|
|
|
|
%bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for different ways of setting the 'omnifunc' option
|
|
|
|
|
func Test_omnifunc_callback()
|
2022-11-06 23:08:29 -07:00
|
|
|
|
func OmniFunc1(callnr, findstart, base)
|
|
|
|
|
call add(g:OmniFunc1Args, [a:callnr, a:findstart, a:base])
|
|
|
|
|
return a:findstart ? 0 : []
|
|
|
|
|
endfunc
|
|
|
|
|
func OmniFunc2(findstart, base)
|
|
|
|
|
call add(g:OmniFunc2Args, [a:findstart, a:base])
|
2022-08-19 17:45:15 -07:00
|
|
|
|
return a:findstart ? 0 : []
|
|
|
|
|
endfunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
let lines =<< trim END
|
2022-11-06 23:08:29 -07:00
|
|
|
|
#" Test for using a function name
|
|
|
|
|
LET &omnifunc = 'g:OmniFunc2'
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'zero')
|
|
|
|
|
LET g:OmniFunc2Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'zero']], g:OmniFunc2Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a function()
|
2022-11-06 23:08:29 -07:00
|
|
|
|
set omnifunc=function('g:OmniFunc1',\ [10])
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'one')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[10, 1, ''], [10, 0, 'one']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a funcref variable to set 'omnifunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
VAR Fn = function('g:OmniFunc1', [11])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &omnifunc = Fn
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'two')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[11, 1, ''], [11, 0, 'two']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a string(funcref_variable) to set 'omnifunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Fn = function('g:OmniFunc1', [12])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &omnifunc = string(Fn)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'two')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[12, 1, ''], [12, 0, 'two']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a funcref()
|
2022-11-06 23:08:29 -07:00
|
|
|
|
set omnifunc=funcref('g:OmniFunc1',\ [13])
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'three')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[13, 1, ''], [13, 0, 'three']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Use let to set 'omnifunc' to a funcref
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Fn = funcref('g:OmniFunc1', [14])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &omnifunc = Fn
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'four')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[14, 1, ''], [14, 0, 'four']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a string(funcref) to set 'omnifunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Fn = funcref("g:OmniFunc1", [15])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &omnifunc = string(Fn)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'four')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[15, 1, ''], [15, 0, 'four']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a lambda function with set
|
2022-11-06 23:08:29 -07:00
|
|
|
|
VAR optval = "LSTART a, b LMIDDLE OmniFunc1(16, a, b) LEND"
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET optval = substitute(optval, ' ', '\\ ', 'g')
|
|
|
|
|
exe "set omnifunc=" .. optval
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'five')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[16, 1, ''], [16, 0, 'five']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'omnifunc' to a lambda expression
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET &omnifunc = LSTART a, b LMIDDLE OmniFunc1(17, a, b) LEND
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'six')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[17, 1, ''], [17, 0, 'six']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'omnifunc' to a string(lambda_expression)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET &omnifunc = 'LSTART a, b LMIDDLE OmniFunc1(18, a, b) LEND'
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'six')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[18, 1, ''], [18, 0, 'six']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'omnifunc' to a variable with a lambda expression
|
2022-11-06 23:08:29 -07:00
|
|
|
|
VAR Lambda = LSTART a, b LMIDDLE OmniFunc1(19, a, b) LEND
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &omnifunc = Lambda
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'seven')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'omnifunc' to a string(variable with a lambda expression)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Lambda = LSTART a, b LMIDDLE OmniFunc1(20, a, b) LEND
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &omnifunc = string(Lambda)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'seven')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:OmniFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a lambda function with incorrect return value
|
|
|
|
|
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
|
|
|
|
|
LET &omnifunc = Lambda
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'eight')
|
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for clearing the 'omnifunc' option
|
|
|
|
|
set omnifunc=''
|
|
|
|
|
set omnifunc&
|
|
|
|
|
call assert_fails("set omnifunc=function('abc')", "E700:")
|
|
|
|
|
call assert_fails("set omnifunc=funcref('abc')", "E700:")
|
|
|
|
|
|
|
|
|
|
#" set 'omnifunc' to a non-existing function
|
2022-11-06 23:08:29 -07:00
|
|
|
|
set omnifunc=OmniFunc2
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'nine')
|
|
|
|
|
call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:')
|
|
|
|
|
call assert_fails("LET &omnifunc = function('NonExistingFunc')", 'E700:')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:OmniFunc2Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[1, ''], [0, 'nine']], g:OmniFunc2Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
|
|
|
|
END
|
|
|
|
|
call CheckLegacyAndVim9Success(lines)
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-12-02 05:47:52 -07:00
|
|
|
|
" Test for using a script-local function name
|
|
|
|
|
func s:OmniFunc3(findstart, base)
|
|
|
|
|
call add(g:OmniFunc3Args, [a:findstart, a:base])
|
|
|
|
|
return a:findstart ? 0 : []
|
|
|
|
|
endfunc
|
|
|
|
|
set omnifunc=s:OmniFunc3
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'script1')
|
|
|
|
|
let g:OmniFunc3Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'script1']], g:OmniFunc3Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
let &omnifunc = 's:OmniFunc3'
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'script2')
|
|
|
|
|
let g:OmniFunc3Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'script2']], g:OmniFunc3Args)
|
|
|
|
|
bw!
|
|
|
|
|
delfunc s:OmniFunc3
|
|
|
|
|
|
|
|
|
|
" invalid return value
|
2022-11-06 19:26:54 -07:00
|
|
|
|
let &omnifunc = {a -> 'abc'}
|
2022-08-19 17:45:15 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
|
|
|
|
|
2022-11-06 20:20:42 -07:00
|
|
|
|
" Using Vim9 lambda expression in legacy context should fail
|
2024-11-02 19:06:41 -07:00
|
|
|
|
set omnifunc=(a,\ b)\ =>\ OmniFunc1(21,\ a,\ b)
|
2022-11-06 20:20:42 -07:00
|
|
|
|
new | only
|
2022-11-06 23:08:29 -07:00
|
|
|
|
let g:OmniFunc1Args = []
|
2024-11-02 19:06:41 -07:00
|
|
|
|
call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([], g:OmniFunc1Args)
|
2022-11-06 20:20:42 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
" set 'omnifunc' to a partial with dict. This used to cause a crash.
|
|
|
|
|
func SetOmniFunc()
|
|
|
|
|
let params = {'omni': function('g:DictOmniFunc')}
|
|
|
|
|
let &omnifunc = params.omni
|
2022-11-06 20:20:42 -07:00
|
|
|
|
endfunc
|
2022-11-06 22:37:22 -07:00
|
|
|
|
func g:DictOmniFunc(_) dict
|
|
|
|
|
endfunc
|
|
|
|
|
call SetOmniFunc()
|
|
|
|
|
new
|
|
|
|
|
call SetOmniFunc()
|
|
|
|
|
bw
|
|
|
|
|
call test_garbagecollect_now()
|
|
|
|
|
new
|
|
|
|
|
set omnifunc=
|
|
|
|
|
wincmd w
|
|
|
|
|
set omnifunc=
|
|
|
|
|
%bw!
|
|
|
|
|
delfunc g:DictOmniFunc
|
|
|
|
|
delfunc SetOmniFunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
|
2022-08-19 17:45:15 -07:00
|
|
|
|
" Vim9 tests
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
vim9script
|
|
|
|
|
|
2022-12-02 05:47:52 -07:00
|
|
|
|
def Vim9omniFunc(callnr: number, findstart: number, base: string): any
|
|
|
|
|
add(g:Vim9omniFunc_Args, [callnr, findstart, base])
|
2022-08-19 17:45:15 -07:00
|
|
|
|
return findstart ? 0 : []
|
|
|
|
|
enddef
|
2022-12-02 05:47:52 -07:00
|
|
|
|
|
|
|
|
|
# Test for using a def function with omnifunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
set omnifunc=function('Vim9omniFunc',\ [60])
|
2022-08-19 17:45:15 -07:00
|
|
|
|
new | only
|
|
|
|
|
setline(1, 'one')
|
2022-11-06 20:20:42 -07:00
|
|
|
|
g:Vim9omniFunc_Args = []
|
2022-08-19 17:45:15 -07:00
|
|
|
|
feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
2022-11-06 20:20:42 -07:00
|
|
|
|
assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9omniFunc_Args)
|
2022-08-19 17:45:15 -07:00
|
|
|
|
bw!
|
2022-12-02 05:47:52 -07:00
|
|
|
|
|
|
|
|
|
# Test for using a global function name
|
|
|
|
|
&omnifunc = g:OmniFunc2
|
|
|
|
|
new | only
|
|
|
|
|
setline(1, 'two')
|
|
|
|
|
g:OmniFunc2Args = []
|
|
|
|
|
feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
|
|
|
|
assert_equal([[1, ''], [0, 'two']], g:OmniFunc2Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
# Test for using a script-local function name
|
2023-04-15 02:12:59 -07:00
|
|
|
|
def LocalOmniFunc(findstart: number, base: string): any
|
2022-12-02 05:47:52 -07:00
|
|
|
|
add(g:LocalOmniFuncArgs, [findstart, base])
|
|
|
|
|
return findstart ? 0 : []
|
|
|
|
|
enddef
|
2023-04-15 02:12:59 -07:00
|
|
|
|
&omnifunc = LocalOmniFunc
|
2022-12-02 05:47:52 -07:00
|
|
|
|
new | only
|
|
|
|
|
setline(1, 'three')
|
|
|
|
|
g:LocalOmniFuncArgs = []
|
|
|
|
|
feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
|
|
|
|
assert_equal([[1, ''], [0, 'three']], g:LocalOmniFuncArgs)
|
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
END
|
2022-12-03 05:27:09 -07:00
|
|
|
|
call CheckScriptSuccess(lines)
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
|
|
|
|
" cleanup
|
|
|
|
|
set omnifunc&
|
2022-11-06 23:08:29 -07:00
|
|
|
|
delfunc OmniFunc1
|
|
|
|
|
delfunc OmniFunc2
|
|
|
|
|
unlet g:OmniFunc1Args g:OmniFunc2Args
|
2022-08-19 17:45:15 -07:00
|
|
|
|
%bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for different ways of setting the 'thesaurusfunc' option
|
|
|
|
|
func Test_thesaurusfunc_callback()
|
2022-11-06 23:08:29 -07:00
|
|
|
|
func TsrFunc1(callnr, findstart, base)
|
|
|
|
|
call add(g:TsrFunc1Args, [a:callnr, a:findstart, a:base])
|
2022-08-19 17:45:15 -07:00
|
|
|
|
return a:findstart ? 0 : []
|
|
|
|
|
endfunc
|
2022-11-06 23:08:29 -07:00
|
|
|
|
func TsrFunc2(findstart, base)
|
|
|
|
|
call add(g:TsrFunc2Args, [a:findstart, a:base])
|
|
|
|
|
return a:findstart ? 0 : ['sunday']
|
|
|
|
|
endfunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
let lines =<< trim END
|
2022-11-06 23:08:29 -07:00
|
|
|
|
#" Test for using a function name
|
|
|
|
|
LET &thesaurusfunc = 'g:TsrFunc2'
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'zero')
|
|
|
|
|
LET g:TsrFunc2Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'zero']], g:TsrFunc2Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a function()
|
2022-11-06 23:08:29 -07:00
|
|
|
|
set thesaurusfunc=function('g:TsrFunc1',\ [10])
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'one')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[10, 1, ''], [10, 0, 'one']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a funcref variable to set 'thesaurusfunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
VAR Fn = function('g:TsrFunc1', [11])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &thesaurusfunc = Fn
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'two')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[11, 1, ''], [11, 0, 'two']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a string(funcref_variable) to set 'thesaurusfunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Fn = function('g:TsrFunc1', [12])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &thesaurusfunc = string(Fn)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'two')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[12, 1, ''], [12, 0, 'two']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a funcref()
|
2022-11-06 23:08:29 -07:00
|
|
|
|
set thesaurusfunc=funcref('g:TsrFunc1',\ [13])
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'three')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[13, 1, ''], [13, 0, 'three']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a funcref variable to set 'thesaurusfunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Fn = funcref('g:TsrFunc1', [14])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &thesaurusfunc = Fn
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'four')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[14, 1, ''], [14, 0, 'four']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Using a string(funcref_variable) to set 'thesaurusfunc'
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Fn = funcref('g:TsrFunc1', [15])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &thesaurusfunc = string(Fn)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'four')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[15, 1, ''], [15, 0, 'four']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a lambda function
|
2022-11-06 23:08:29 -07:00
|
|
|
|
VAR optval = "LSTART a, b LMIDDLE TsrFunc1(16, a, b) LEND"
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET optval = substitute(optval, ' ', '\\ ', 'g')
|
|
|
|
|
exe "set thesaurusfunc=" .. optval
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'five')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[16, 1, ''], [16, 0, 'five']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a lambda function with set
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET &thesaurusfunc = LSTART a, b LMIDDLE TsrFunc1(17, a, b) LEND
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'six')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[17, 1, ''], [17, 0, 'six']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'thesaurusfunc' to a string(lambda expression)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET &thesaurusfunc = 'LSTART a, b LMIDDLE TsrFunc1(18, a, b) LEND'
|
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'six')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[18, 1, ''], [18, 0, 'six']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'thesaurusfunc' to a variable with a lambda expression
|
2022-11-06 23:08:29 -07:00
|
|
|
|
VAR Lambda = LSTART a, b LMIDDLE TsrFunc1(19, a, b) LEND
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &thesaurusfunc = Lambda
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'seven')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-11-06 19:26:54 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Set 'thesaurusfunc' to a string(variable with a lambda expression)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET Lambda = LSTART a, b LMIDDLE TsrFunc1(20, a, b) LEND
|
2022-11-06 22:37:22 -07:00
|
|
|
|
LET &thesaurusfunc = string(Lambda)
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'seven')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for using a lambda function with incorrect return value
|
|
|
|
|
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
|
|
|
|
|
LET &thesaurusfunc = Lambda
|
2022-11-06 23:08:29 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'eight')
|
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
#" Test for clearing the 'thesaurusfunc' option
|
|
|
|
|
set thesaurusfunc=''
|
|
|
|
|
set thesaurusfunc&
|
|
|
|
|
call assert_fails("set thesaurusfunc=function('abc')", "E700:")
|
|
|
|
|
call assert_fails("set thesaurusfunc=funcref('abc')", "E700:")
|
|
|
|
|
|
|
|
|
|
#" set 'thesaurusfunc' to a non-existing function
|
2022-11-06 23:08:29 -07:00
|
|
|
|
set thesaurusfunc=TsrFunc2
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'ten')
|
|
|
|
|
call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:')
|
|
|
|
|
call assert_fails("LET &thesaurusfunc = function('NonExistingFunc')", 'E700:')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc2Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[1, ''], [0, 'ten']], g:TsrFunc2Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
#" Use a buffer-local value and a global value
|
|
|
|
|
set thesaurusfunc&
|
2022-11-06 23:08:29 -07:00
|
|
|
|
setlocal thesaurusfunc=function('g:TsrFunc1',\ [22])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call setline(1, 'sun')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
|
|
|
|
|
call assert_equal('sun', getline(1))
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
new
|
|
|
|
|
call setline(1, 'sun')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
|
|
|
|
|
call assert_equal('sun', getline(1))
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([], g:TsrFunc1Args)
|
|
|
|
|
set thesaurusfunc=function('g:TsrFunc1',\ [23])
|
2022-11-06 22:37:22 -07:00
|
|
|
|
wincmd w
|
|
|
|
|
call setline(1, 'sun')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
LET g:TsrFunc1Args = []
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
|
|
|
|
|
call assert_equal('sun', getline(1))
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
|
2022-11-06 22:37:22 -07:00
|
|
|
|
:%bw!
|
|
|
|
|
END
|
|
|
|
|
call CheckLegacyAndVim9Success(lines)
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
2022-12-02 05:47:52 -07:00
|
|
|
|
" Test for using a script-local function name
|
|
|
|
|
func s:TsrFunc3(findstart, base)
|
|
|
|
|
call add(g:TsrFunc3Args, [a:findstart, a:base])
|
|
|
|
|
return a:findstart ? 0 : []
|
|
|
|
|
endfunc
|
2024-11-03 01:54:25 -07:00
|
|
|
|
|
2022-12-02 05:47:52 -07:00
|
|
|
|
set tsrfu=s:TsrFunc3
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'script1')
|
|
|
|
|
let g:TsrFunc3Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
let &tsrfu = 's:TsrFunc3'
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'script2')
|
|
|
|
|
let g:TsrFunc3Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'script2']], g:TsrFunc3Args)
|
|
|
|
|
bw!
|
2024-11-03 01:54:25 -07:00
|
|
|
|
|
|
|
|
|
new | only
|
|
|
|
|
set thesaurusfunc=
|
|
|
|
|
setlocal thesaurusfunc=NoSuchFunc
|
|
|
|
|
setglobal thesaurusfunc=s:TsrFunc3
|
|
|
|
|
call assert_equal('NoSuchFunc', &thesaurusfunc)
|
|
|
|
|
call assert_equal('NoSuchFunc', &l:thesaurusfunc)
|
|
|
|
|
call assert_equal('s:TsrFunc3', &g:thesaurusfunc)
|
|
|
|
|
new | only
|
|
|
|
|
call assert_equal('s:TsrFunc3', &thesaurusfunc)
|
|
|
|
|
call assert_equal('s:TsrFunc3', &g:thesaurusfunc)
|
|
|
|
|
call assert_equal('', &l:thesaurusfunc)
|
|
|
|
|
call setline(1, 'script1')
|
|
|
|
|
let g:TsrFunc3Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
new | only
|
|
|
|
|
set thesaurusfunc=
|
|
|
|
|
setlocal thesaurusfunc=NoSuchFunc
|
|
|
|
|
set thesaurusfunc=s:TsrFunc3
|
|
|
|
|
call assert_equal('s:TsrFunc3', &thesaurusfunc)
|
|
|
|
|
call assert_equal('s:TsrFunc3', &g:thesaurusfunc)
|
|
|
|
|
call assert_equal('', &l:thesaurusfunc)
|
|
|
|
|
call setline(1, 'script1')
|
|
|
|
|
let g:TsrFunc3Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args)
|
|
|
|
|
setlocal bufhidden=wipe
|
|
|
|
|
new | only!
|
|
|
|
|
call assert_equal('s:TsrFunc3', &thesaurusfunc)
|
|
|
|
|
call assert_equal('s:TsrFunc3', &g:thesaurusfunc)
|
|
|
|
|
call assert_equal('', &l:thesaurusfunc)
|
|
|
|
|
call setline(1, 'script1')
|
|
|
|
|
let g:TsrFunc3Args = []
|
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
2022-12-02 05:47:52 -07:00
|
|
|
|
delfunc s:TsrFunc3
|
|
|
|
|
|
|
|
|
|
" invalid return value
|
2022-11-06 19:26:54 -07:00
|
|
|
|
let &thesaurusfunc = {a -> 'abc'}
|
2022-08-19 17:45:15 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
|
2022-11-06 20:20:42 -07:00
|
|
|
|
" Using Vim9 lambda expression in legacy context should fail
|
2024-11-02 19:06:41 -07:00
|
|
|
|
set thesaurusfunc=(a,\ b)\ =>\ TsrFunc1(21,\ a,\ b)
|
2022-11-06 20:20:42 -07:00
|
|
|
|
new | only
|
2022-11-06 23:08:29 -07:00
|
|
|
|
let g:TsrFunc1Args = []
|
2024-11-02 19:06:41 -07:00
|
|
|
|
call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:')
|
2022-11-06 23:08:29 -07:00
|
|
|
|
call assert_equal([], g:TsrFunc1Args)
|
2022-11-06 20:20:42 -07:00
|
|
|
|
bw!
|
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
" set 'thesaurusfunc' to a partial with dict. This used to cause a crash.
|
|
|
|
|
func SetTsrFunc()
|
|
|
|
|
let params = {'thesaurus': function('g:DictTsrFunc')}
|
|
|
|
|
let &thesaurusfunc = params.thesaurus
|
|
|
|
|
endfunc
|
|
|
|
|
func g:DictTsrFunc(_) dict
|
|
|
|
|
endfunc
|
|
|
|
|
call SetTsrFunc()
|
2022-11-06 20:20:42 -07:00
|
|
|
|
new
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call SetTsrFunc()
|
|
|
|
|
bw
|
|
|
|
|
call test_garbagecollect_now()
|
|
|
|
|
new
|
|
|
|
|
set thesaurusfunc=
|
2022-11-06 20:20:42 -07:00
|
|
|
|
wincmd w
|
|
|
|
|
%bw!
|
2022-11-06 22:37:22 -07:00
|
|
|
|
delfunc SetTsrFunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
|
2022-11-06 22:37:22 -07:00
|
|
|
|
" set buffer-local 'thesaurusfunc' to a partial with dict. This used to
|
|
|
|
|
" cause a crash.
|
|
|
|
|
func SetLocalTsrFunc()
|
|
|
|
|
let params = {'thesaurus': function('g:DictTsrFunc')}
|
|
|
|
|
let &l:thesaurusfunc = params.thesaurus
|
2022-11-06 20:20:42 -07:00
|
|
|
|
endfunc
|
2022-11-06 22:37:22 -07:00
|
|
|
|
call SetLocalTsrFunc()
|
|
|
|
|
call test_garbagecollect_now()
|
|
|
|
|
call SetLocalTsrFunc()
|
|
|
|
|
set thesaurusfunc=
|
2022-11-06 20:20:42 -07:00
|
|
|
|
bw!
|
2022-11-06 22:37:22 -07:00
|
|
|
|
delfunc g:DictTsrFunc
|
|
|
|
|
delfunc SetLocalTsrFunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
|
2022-08-19 17:45:15 -07:00
|
|
|
|
" Vim9 tests
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
vim9script
|
|
|
|
|
|
2022-12-02 05:47:52 -07:00
|
|
|
|
def Vim9tsrFunc(callnr: number, findstart: number, base: string): any
|
|
|
|
|
add(g:Vim9tsrFunc_Args, [callnr, findstart, base])
|
2022-08-19 17:45:15 -07:00
|
|
|
|
return findstart ? 0 : []
|
|
|
|
|
enddef
|
2022-12-02 05:47:52 -07:00
|
|
|
|
|
|
|
|
|
# Test for using a def function with thesaurusfunc
|
2022-11-06 20:20:42 -07:00
|
|
|
|
set thesaurusfunc=function('Vim9tsrFunc',\ [60])
|
2022-08-19 17:45:15 -07:00
|
|
|
|
new | only
|
|
|
|
|
setline(1, 'one')
|
2022-11-06 20:20:42 -07:00
|
|
|
|
g:Vim9tsrFunc_Args = []
|
2022-08-19 17:45:15 -07:00
|
|
|
|
feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
2022-11-06 20:20:42 -07:00
|
|
|
|
assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9tsrFunc_Args)
|
2022-08-19 17:45:15 -07:00
|
|
|
|
bw!
|
2022-12-02 05:47:52 -07:00
|
|
|
|
|
|
|
|
|
# Test for using a global function name
|
|
|
|
|
&thesaurusfunc = g:TsrFunc2
|
|
|
|
|
new | only
|
|
|
|
|
setline(1, 'two')
|
|
|
|
|
g:TsrFunc2Args = []
|
|
|
|
|
feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
assert_equal([[1, ''], [0, 'two']], g:TsrFunc2Args)
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
# Test for using a script-local function name
|
2023-04-15 02:12:59 -07:00
|
|
|
|
def LocalTsrFunc(findstart: number, base: string): any
|
2022-12-02 05:47:52 -07:00
|
|
|
|
add(g:LocalTsrFuncArgs, [findstart, base])
|
|
|
|
|
return findstart ? 0 : []
|
|
|
|
|
enddef
|
2023-04-15 02:12:59 -07:00
|
|
|
|
&thesaurusfunc = LocalTsrFunc
|
2022-12-02 05:47:52 -07:00
|
|
|
|
new | only
|
|
|
|
|
setline(1, 'three')
|
|
|
|
|
g:LocalTsrFuncArgs = []
|
|
|
|
|
feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
|
|
|
|
assert_equal([[1, ''], [0, 'three']], g:LocalTsrFuncArgs)
|
|
|
|
|
bw!
|
2022-08-19 17:45:15 -07:00
|
|
|
|
END
|
2022-12-03 05:27:09 -07:00
|
|
|
|
call CheckScriptSuccess(lines)
|
2022-08-19 17:45:15 -07:00
|
|
|
|
|
|
|
|
|
" cleanup
|
|
|
|
|
set thesaurusfunc&
|
2022-11-06 23:08:29 -07:00
|
|
|
|
delfunc TsrFunc1
|
|
|
|
|
delfunc TsrFunc2
|
|
|
|
|
unlet g:TsrFunc1Args g:TsrFunc2Args
|
2022-08-19 17:45:15 -07:00
|
|
|
|
%bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-04-07 16:12:47 -07:00
|
|
|
|
func FooBarComplete(findstart, base)
|
|
|
|
|
if a:findstart
|
|
|
|
|
return col('.') - 1
|
|
|
|
|
else
|
|
|
|
|
return ["Foo", "Bar", "}"]
|
|
|
|
|
endif
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_complete_smartindent()
|
|
|
|
|
new
|
|
|
|
|
setlocal smartindent completefunc=FooBarComplete
|
|
|
|
|
|
|
|
|
|
exe "norm! o{\<cr>\<c-x>\<c-u>\<c-p>}\<cr>\<esc>"
|
|
|
|
|
let result = getline(1,'$')
|
|
|
|
|
call assert_equal(['', '{','}',''], result)
|
|
|
|
|
bw!
|
|
|
|
|
delfunction! FooBarComplete
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 01:59:03 -07:00
|
|
|
|
func Test_complete_overrun()
|
|
|
|
|
" this was going past the end of the copied text
|
|
|
|
|
new
|
|
|
|
|
sil norm si0s0
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 06:08:17 -07:00
|
|
|
|
func Test_infercase_very_long_line()
|
|
|
|
|
" this was truncating the line when inferring case
|
|
|
|
|
new
|
|
|
|
|
let longLine = "blah "->repeat(300)
|
|
|
|
|
let verylongLine = "blah "->repeat(400)
|
|
|
|
|
call setline(1, verylongLine)
|
|
|
|
|
call setline(2, longLine)
|
|
|
|
|
set ic infercase
|
|
|
|
|
exe "normal 2Go\<C-X>\<C-L>\<Esc>"
|
|
|
|
|
call assert_equal(longLine, getline(3))
|
|
|
|
|
|
2022-08-24 06:44:37 -07:00
|
|
|
|
" check that the too long text is NUL terminated
|
|
|
|
|
%del
|
|
|
|
|
norm o
|
|
|
|
|
norm 1987ax
|
|
|
|
|
exec "norm ox\<C-X>\<C-L>"
|
|
|
|
|
call assert_equal(repeat('x', 1987), getline(3))
|
|
|
|
|
|
2022-08-24 06:08:17 -07:00
|
|
|
|
bwipe!
|
|
|
|
|
set noic noinfercase
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 06:40:14 -07:00
|
|
|
|
func Test_ins_complete_add()
|
|
|
|
|
" this was reading past the end of allocated memory
|
|
|
|
|
new
|
|
|
|
|
norm o
|
|
|
|
|
norm 7o
|
|
|
|
|
sil! norm o
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-24 06:46:06 -07:00
|
|
|
|
func Test_ins_complete_end_of_line()
|
|
|
|
|
" this was reading past the end of the line
|
2024-07-16 19:19:31 -07:00
|
|
|
|
new
|
2022-08-24 06:46:06 -07:00
|
|
|
|
norm 8oý
|
|
|
|
|
sil! norm o
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
2022-08-24 01:59:03 -07:00
|
|
|
|
|
2023-08-22 07:48:55 -07:00
|
|
|
|
func s:Tagfunc(t,f,o)
|
|
|
|
|
bwipe!
|
|
|
|
|
return []
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" This was using freed memory, since 'complete' was in a wiped out buffer.
|
|
|
|
|
" Also using a window that was closed.
|
|
|
|
|
func Test_tagfunc_wipes_out_buffer()
|
|
|
|
|
new
|
|
|
|
|
set complete=.,t,w,b,u,i
|
|
|
|
|
se tagfunc=s:Tagfunc
|
|
|
|
|
sil norm i
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2023-10-11 17:21:01 -07:00
|
|
|
|
func Test_ins_complete_popup_position()
|
|
|
|
|
CheckScreendump
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
vim9script
|
|
|
|
|
set nowrap
|
|
|
|
|
setline(1, ['one', 'two', 'this is line ', 'four'])
|
|
|
|
|
prop_type_add('test', {highlight: 'Error'})
|
|
|
|
|
prop_add(3, 0, {
|
|
|
|
|
text_align: 'above',
|
|
|
|
|
text: 'The quick brown fox jumps over the lazy dog',
|
|
|
|
|
type: 'test'
|
|
|
|
|
})
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'XinsPopup', 'D')
|
|
|
|
|
let buf = RunVimInTerminal('-S XinsPopup', #{rows: 10})
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "3GA\<C-N>")
|
|
|
|
|
call VerifyScreenDump(buf, 'Test_ins_complete_popup_position_1', {})
|
|
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func GetCompleteInfo()
|
|
|
|
|
let g:compl_info = complete_info()
|
|
|
|
|
return ''
|
|
|
|
|
endfunc
|
|
|
|
|
|
2023-10-17 02:49:22 -07:00
|
|
|
|
func Test_completion_restart()
|
|
|
|
|
new
|
|
|
|
|
set complete=. completeopt=menuone backspace=2
|
|
|
|
|
call setline(1, 'workhorse workhorse')
|
|
|
|
|
exe "normal $a\<C-N>\<BS>\<BS>\<C-R>=GetCompleteInfo()\<CR>"
|
|
|
|
|
call assert_equal(1, len(g:compl_info['items']))
|
|
|
|
|
call assert_equal('workhorse', g:compl_info['items'][0]['word'])
|
|
|
|
|
set complete& completeopt& backspace&
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2023-10-11 17:21:01 -07:00
|
|
|
|
func Test_complete_info_index()
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ["aaa", "bbb", "ccc", "ddd", "eee", "fff"])
|
|
|
|
|
inoremap <buffer><F5> <C-R>=GetCompleteInfo()<CR>
|
|
|
|
|
|
|
|
|
|
" Ensure 'index' in complete_info() is coherent with the 'items' array.
|
|
|
|
|
|
|
|
|
|
set completeopt=menu,preview
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
" Search forward
|
2023-10-11 17:21:01 -07:00
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
2023-10-11 17:21:01 -07:00
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("bbb", g:compl_info['items'][g:compl_info['selected']]['word'])
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("ccc", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("ddd", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("eee", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
" Search forward: unselected item
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call assert_equal(-1 , g:compl_info['selected'])
|
2023-10-11 17:21:01 -07:00
|
|
|
|
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
" Search backward
|
2023-10-11 17:21:01 -07:00
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
2023-10-11 17:21:01 -07:00
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("eee", g:compl_info['items'][g:compl_info['selected']]['word'])
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("ddd", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("ccc", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("bbb", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
" search backwards: unselected item
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call assert_equal(-1 , g:compl_info['selected'])
|
|
|
|
|
|
|
|
|
|
" switch direction: forwards, then backwards
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
" switch direction: forwards, then backwards, then forwards again
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-P>\<C-P>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
|
|
|
|
|
" switch direction: backwards, then forwards
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
" switch direction: backwards, then forwards, then backwards again
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-N>\<C-N>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
2023-10-11 17:21:01 -07:00
|
|
|
|
|
|
|
|
|
" Add 'noselect', check that 'selected' is -1 when nothing is selected.
|
|
|
|
|
set completeopt+=noselect
|
|
|
|
|
" Search forward.
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal(-1, g:compl_info['selected'])
|
|
|
|
|
|
|
|
|
|
" Search backward.
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal(-1, g:compl_info['selected'])
|
|
|
|
|
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-P>\<F5>\<Esc>_dd", 'tx')
|
2024-03-20 16:50:12 -07:00
|
|
|
|
call assert_equal(5, g:compl_info['selected'])
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
|
|
|
|
call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
|
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
2023-10-27 15:17:02 -07:00
|
|
|
|
call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
2023-11-04 06:59:03 -07:00
|
|
|
|
call feedkeys("Go\<C-X>\<C-N>\<F5>\<Esc>_dd", 'tx')
|
|
|
|
|
call assert_equal(-1, g:compl_info['selected'])
|
|
|
|
|
call assert_equal(6 , len(g:compl_info['items']))
|
vim-patch:9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408
https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-10-27 15:13:57 -07:00
|
|
|
|
|
2023-10-11 17:21:01 -07:00
|
|
|
|
set completeopt&
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
2023-08-22 07:48:55 -07:00
|
|
|
|
|
2024-01-29 16:34:37 -07:00
|
|
|
|
func Test_complete_changed_complete_info()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
" this used to crash vim, see #13929
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set completeopt=menuone
|
|
|
|
|
autocmd CompleteChanged * call complete_info(['items'])
|
|
|
|
|
call feedkeys("iii\<cr>\<c-p>")
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'Xsegfault', 'D')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xsegfault', #{rows: 5})
|
|
|
|
|
call WaitForAssert({-> assert_match('^ii', term_getline(buf, 1))}, 1000)
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
endfunc
|
|
|
|
|
|
2024-04-02 14:53:08 -07:00
|
|
|
|
func Test_completefunc_first_call_complete_add()
|
|
|
|
|
new
|
|
|
|
|
|
|
|
|
|
func Complete(findstart, base) abort
|
|
|
|
|
if a:findstart
|
|
|
|
|
let col = col('.')
|
|
|
|
|
call complete_add('#')
|
|
|
|
|
return col - 1
|
|
|
|
|
else
|
|
|
|
|
return []
|
|
|
|
|
endif
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
set completeopt=longest completefunc=Complete
|
|
|
|
|
" This used to cause heap-buffer-overflow
|
|
|
|
|
call assert_fails('call feedkeys("ifoo#\<C-X>\<C-U>", "xt")', 'E840:')
|
|
|
|
|
|
|
|
|
|
delfunc Complete
|
|
|
|
|
set completeopt& completefunc&
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2024-06-04 23:44:31 -07:00
|
|
|
|
func Test_complete_fuzzy_match()
|
|
|
|
|
func OnPumChange()
|
|
|
|
|
let g:item = get(v:event, 'completed_item', {})
|
|
|
|
|
let g:word = get(g:item, 'word', v:null)
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
augroup AAAAA_Group
|
|
|
|
|
au!
|
|
|
|
|
autocmd CompleteChanged * :call OnPumChange()
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
func Omni_test(findstart, base)
|
|
|
|
|
if a:findstart
|
|
|
|
|
return col(".")
|
|
|
|
|
endif
|
|
|
|
|
return [#{word: "foo"}, #{word: "foobar"}, #{word: "fooBaz"}, #{word: "foobala"}]
|
|
|
|
|
endfunc
|
2024-06-05 14:49:04 -07:00
|
|
|
|
|
2024-06-04 23:44:31 -07:00
|
|
|
|
new
|
|
|
|
|
set omnifunc=Omni_test
|
|
|
|
|
set completeopt+=noinsert,fuzzy
|
|
|
|
|
call feedkeys("Gi\<C-x>\<C-o>", 'tx')
|
|
|
|
|
call assert_equal('foo', g:word)
|
|
|
|
|
call feedkeys("S\<C-x>\<C-o>fb", 'tx')
|
|
|
|
|
call assert_equal('fooBaz', g:word)
|
|
|
|
|
call feedkeys("S\<C-x>\<C-o>fa", 'tx')
|
|
|
|
|
call assert_equal('foobar', g:word)
|
|
|
|
|
" select next
|
|
|
|
|
call feedkeys("S\<C-x>\<C-o>fb\<C-n>", 'tx')
|
|
|
|
|
call assert_equal('foobar', g:word)
|
2024-06-05 14:49:04 -07:00
|
|
|
|
" can cyclically select next
|
2024-06-04 23:44:31 -07:00
|
|
|
|
call feedkeys("S\<C-x>\<C-o>fb\<C-n>\<C-n>\<C-n>", 'tx')
|
|
|
|
|
call assert_equal(v:null, g:word)
|
|
|
|
|
" select prev
|
|
|
|
|
call feedkeys("S\<C-x>\<C-o>fb\<C-p>", 'tx')
|
|
|
|
|
call assert_equal(v:null, g:word)
|
2024-06-05 14:49:04 -07:00
|
|
|
|
" can cyclically select prev
|
2024-06-04 23:44:31 -07:00
|
|
|
|
call feedkeys("S\<C-x>\<C-o>fb\<C-p>\<C-p>\<C-p>\<C-p>", 'tx')
|
|
|
|
|
call assert_equal('fooBaz', g:word)
|
|
|
|
|
|
2024-06-14 16:20:38 -07:00
|
|
|
|
func Comp()
|
|
|
|
|
call complete(col('.'), ["fooBaz", "foobar", "foobala"])
|
|
|
|
|
return ''
|
|
|
|
|
endfunc
|
|
|
|
|
call feedkeys("i\<C-R>=Comp()\<CR>", 'tx')
|
|
|
|
|
call assert_equal('fooBaz', g:word)
|
|
|
|
|
|
2024-06-04 23:44:31 -07:00
|
|
|
|
" respect noselect
|
|
|
|
|
set completeopt+=noselect
|
|
|
|
|
call feedkeys("S\<C-x>\<C-o>fb", 'tx')
|
|
|
|
|
call assert_equal(v:null, g:word)
|
|
|
|
|
call feedkeys("S\<C-x>\<C-o>fb\<C-n>", 'tx')
|
|
|
|
|
call assert_equal('fooBaz', g:word)
|
|
|
|
|
|
2024-06-16 02:30:15 -07:00
|
|
|
|
" avoid breaking default completion behavior
|
2024-06-15 16:07:06 -07:00
|
|
|
|
set completeopt=fuzzy,menu
|
|
|
|
|
call setline(1, ['hello help hero h'])
|
2024-06-16 02:30:15 -07:00
|
|
|
|
" Use "!" flag of feedkeys() so that ex_normal_busy is not set and
|
|
|
|
|
" ins_compl_check_keys() is not skipped.
|
|
|
|
|
" Add a "0" after the <Esc> to avoid waiting for an escape sequence.
|
|
|
|
|
call feedkeys("A\<C-X>\<C-N>\<Esc>0", 'tx!')
|
2024-06-15 16:07:06 -07:00
|
|
|
|
call assert_equal('hello help hero hello', getline('.'))
|
|
|
|
|
set completeopt+=noinsert
|
|
|
|
|
call setline(1, ['hello help hero h'])
|
2024-06-16 02:30:15 -07:00
|
|
|
|
call feedkeys("A\<C-X>\<C-N>\<Esc>0", 'tx!')
|
2024-06-15 16:07:06 -07:00
|
|
|
|
call assert_equal('hello help hero h', getline('.'))
|
|
|
|
|
|
2024-08-31 02:10:05 -07:00
|
|
|
|
" issue #15526
|
|
|
|
|
set completeopt=fuzzy,menuone,menu,noselect
|
|
|
|
|
call setline(1, ['Text', 'ToText', ''])
|
|
|
|
|
call cursor(2, 1)
|
|
|
|
|
call feedkeys("STe\<C-X>\<C-N>x\<CR>\<Esc>0", 'tx!')
|
|
|
|
|
call assert_equal('Tex', getline('.'))
|
|
|
|
|
|
2024-06-04 23:44:31 -07:00
|
|
|
|
" clean up
|
|
|
|
|
set omnifunc=
|
|
|
|
|
bw!
|
|
|
|
|
set complete& completeopt&
|
|
|
|
|
autocmd! AAAAA_Group
|
|
|
|
|
augroup! AAAAA_Group
|
|
|
|
|
delfunc OnPumChange
|
|
|
|
|
delfunc Omni_test
|
2024-06-14 16:20:38 -07:00
|
|
|
|
delfunc Comp
|
2024-06-05 14:49:04 -07:00
|
|
|
|
unlet g:item
|
|
|
|
|
unlet g:word
|
2024-06-04 23:44:31 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2024-06-14 13:33:19 -07:00
|
|
|
|
" Check that tie breaking is stable for completeopt+=fuzzy (which should
|
|
|
|
|
" behave the same on different platforms).
|
|
|
|
|
func Test_complete_fuzzy_match_tie()
|
|
|
|
|
new
|
|
|
|
|
set completeopt+=fuzzy,noselect
|
|
|
|
|
call setline(1, ['aaabbccc', 'aaabbCCC', 'aaabbcccc', 'aaabbCCCC', ''])
|
|
|
|
|
|
|
|
|
|
call feedkeys("Gcc\<C-X>\<C-N>ab\<C-N>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('aaabbccc', getline('.'))
|
|
|
|
|
call feedkeys("Gcc\<C-X>\<C-N>ab\<C-N>\<C-N>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('aaabbCCC', getline('.'))
|
|
|
|
|
call feedkeys("Gcc\<C-X>\<C-N>ab\<C-N>\<C-N>\<C-N>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('aaabbcccc', getline('.'))
|
|
|
|
|
call feedkeys("Gcc\<C-X>\<C-N>ab\<C-N>\<C-N>\<C-N>\<C-N>\<C-Y>", 'tx')
|
|
|
|
|
call assert_equal('aaabbCCCC', getline('.'))
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
set completeopt&
|
|
|
|
|
endfunc
|
|
|
|
|
|
2024-01-29 16:34:37 -07:00
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab nofoldenable
|