blob: dbea9013f82fb84873aa5f8ba9915640e37fa2de [file] [log] [blame]
Bram Moolenaar09dd2bb2019-12-14 18:42:15 +01001source screendump.vim
Bram Moolenaar50f91d22019-08-02 19:52:15 +02002source check.vim
Bram Moolenaar15993ce2017-10-26 20:21:44 +02003
4" Test for insert expansion
5func Test_ins_complete()
Bram Moolenaarcf1ba352017-10-27 00:55:04 +02006 edit test_ins_complete.vim
Bram Moolenaarfb094e12017-11-05 20:59:28 +01007 " The files in the current directory interferes with the files
8 " used by this test. So use a separate directory for the test.
9 call mkdir('Xdir')
10 cd Xdir
11
Bram Moolenaar15993ce2017-10-26 20:21:44 +020012 set ff=unix
13 call writefile(["test11\t36Gepeto\t/Tag/",
14 \ "asd\ttest11file\t36G",
15 \ "Makefile\tto\trun"], 'Xtestfile')
16 call writefile(['', 'start of testfile',
17 \ 'ru',
18 \ 'run1',
19 \ 'run2',
20 \ 'STARTTEST',
21 \ 'ENDTEST',
22 \ 'end of testfile'], 'Xtestdata')
23 set ff&
24
25 enew!
26 edit Xtestdata
27 new
28 call append(0, ['#include "Xtestfile"', ''])
29 call cursor(2, 1)
30
31 set cot=
32 set cpt=.,w
33 " add-expands (word from next line) from other window
34 exe "normal iru\<C-N>\<C-N>\<C-X>\<C-N>\<Esc>\<C-A>"
35 call assert_equal('run1 run3', getline('.'))
36 " add-expands (current buffer first)
37 exe "normal o\<C-P>\<C-X>\<C-N>"
38 call assert_equal('run3 run3', getline('.'))
39 " Local expansion, ends in an empty line (unless it becomes a global
40 " expansion)
41 exe "normal o\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>"
42 call assert_equal('', getline('.'))
43 " starts Local and switches to global add-expansion
44 exe "normal o\<C-X>\<C-P>\<C-P>\<C-X>\<C-X>\<C-N>\<C-X>\<C-N>\<C-N>"
45 call assert_equal('run1 run2', getline('.'))
46
47 set cpt=.,w,i
48 " i-add-expands and switches to local
49 exe "normal OM\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-X>\<C-X>\<C-P>"
50 call assert_equal("Makefile\tto\trun3", getline('.'))
51 " add-expands lines (it would end in an empty line if it didn't ignored
52 " itself)
53 exe "normal o\<C-X>\<C-L>\<C-X>\<C-L>\<C-P>\<C-P>"
54 call assert_equal("Makefile\tto\trun3", getline('.'))
55 call assert_equal("Makefile\tto\trun3", getline(line('.') - 1))
56
57 set cpt=kXtestfile
58 " checks k-expansion, and file expansion (use Xtest11 instead of test11,
59 " because TEST11.OUT may match first on DOS)
60 write Xtest11.one
61 write Xtest11.two
62 exe "normal o\<C-N>\<Esc>IX\<Esc>A\<C-X>\<C-F>\<C-N>"
63 call assert_equal('Xtest11.two', getline('.'))
64
65 " use CTRL-X CTRL-F to complete Xtest11.one, remove it and then use CTRL-X
66 " CTRL-F again to verify this doesn't cause trouble.
67 exe "normal oXt\<C-X>\<C-F>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<C-X>\<C-F>"
68 call assert_equal('Xtest11.one', getline('.'))
69 normal ddk
70
71 set cpt=w
72 " checks make_cyclic in other window
73 exe "normal oST\<C-N>\<C-P>\<C-P>\<C-P>\<C-P>"
74 call assert_equal('STARTTEST', getline('.'))
75
76 set cpt=u nohid
77 " checks unloaded buffer expansion
78 only
79 exe "normal oEN\<C-N>"
80 call assert_equal('ENDTEST', getline('.'))
81 " checks adding mode abortion
82 exe "normal ounl\<C-N>\<C-X>\<C-X>\<C-P>"
83 call assert_equal('unless', getline('.'))
84
85 set cpt=t,d def=^\\k* tags=Xtestfile notagbsearch
86 " tag expansion, define add-expansion interrupted
87 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>"
88 call assert_equal('test11file 36Gepeto /Tag/ asd', getline('.'))
89 " t-expansion
90 exe "normal oa\<C-N>\<Esc>"
91 call assert_equal('asd', getline('.'))
92
93 %bw!
94 call delete('Xtestfile')
95 call delete('Xtest11.one')
96 call delete('Xtest11.two')
97 call delete('Xtestdata')
98 set cpt& cot& def& tags& tagbsearch& hidden&
Bram Moolenaarfb094e12017-11-05 20:59:28 +010099 cd ..
100 call delete('Xdir', 'rf')
Bram Moolenaar15993ce2017-10-26 20:21:44 +0200101endfunc
Bram Moolenaarffd99f72017-11-02 15:44:14 +0100102
103func Test_omni_dash()
104 func Omni(findstart, base)
105 if a:findstart
106 return 5
107 else
108 echom a:base
109 return ['-help', '-v']
110 endif
111 endfunc
112 set omnifunc=Omni
113 new
114 exe "normal Gofind -\<C-x>\<C-o>"
115 call assert_equal("\n-\nmatch 1 of 2", execute(':2mess'))
116
117 bwipe!
118 delfunc Omni
119 set omnifunc=
120endfunc
Bram Moolenaar02ae9b42018-02-09 15:06:02 +0100121
Bram Moolenaarffa96842018-06-12 22:05:14 +0200122func Test_completefunc_args()
123 let s:args = []
124 func! CompleteFunc(findstart, base)
125 let s:args += [[a:findstart, empty(a:base)]]
126 endfunc
127 new
128
129 set completefunc=CompleteFunc
130 call feedkeys("i\<C-X>\<C-U>\<Esc>", 'x')
Bram Moolenaar52d3aae2018-06-13 21:27:24 +0200131 call assert_equal([1, 1], s:args[0])
132 call assert_equal(0, s:args[1][0])
Bram Moolenaarffa96842018-06-12 22:05:14 +0200133 set completefunc=
134
135 let s:args = []
136 set omnifunc=CompleteFunc
137 call feedkeys("i\<C-X>\<C-O>\<Esc>", 'x')
Bram Moolenaar52d3aae2018-06-13 21:27:24 +0200138 call assert_equal([1, 1], s:args[0])
139 call assert_equal(0, s:args[1][0])
Bram Moolenaarffa96842018-06-12 22:05:14 +0200140 set omnifunc=
141
142 bwipe!
143 unlet s:args
144 delfunc CompleteFunc
145endfunc
146
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100147func s:CompleteDone_CompleteFuncNone( findstart, base )
148 if a:findstart
149 return 0
150 endif
151
152 return v:none
153endfunc
154
Bram Moolenaar1e115362019-01-09 23:01:02 +0100155func s:CompleteDone_CompleteFuncDict( findstart, base )
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100156 if a:findstart
157 return 0
158 endif
159
160 return {
Bram Moolenaar08928322020-01-04 14:32:48 +0100161 \ 'words': [
162 \ {
163 \ 'word': 'aword',
164 \ 'abbr': 'wrd',
165 \ 'menu': 'extra text',
166 \ 'info': 'words are cool',
167 \ 'kind': 'W',
168 \ 'user_data': 'test'
169 \ }
170 \ ]
171 \ }
Bram Moolenaar1e115362019-01-09 23:01:02 +0100172endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100173
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100174func s:CompleteDone_CheckCompletedItemNone()
175 let s:called_completedone = 1
176endfunc
177
Bram Moolenaar3f169ce2020-01-26 22:43:31 +0100178func s:CompleteDone_CheckCompletedItemDict(pre)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100179 call assert_equal( 'aword', v:completed_item[ 'word' ] )
180 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] )
181 call assert_equal( 'extra text', v:completed_item[ 'menu' ] )
182 call assert_equal( 'words are cool', v:completed_item[ 'info' ] )
183 call assert_equal( 'W', v:completed_item[ 'kind' ] )
184 call assert_equal( 'test', v:completed_item[ 'user_data' ] )
185
Bram Moolenaar3f169ce2020-01-26 22:43:31 +0100186 if a:pre
187 call assert_equal('function', complete_info().mode)
188 endif
Bram Moolenaar17e04782020-01-17 18:58:59 +0100189
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100190 let s:called_completedone = 1
Bram Moolenaar1e115362019-01-09 23:01:02 +0100191endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100192
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100193func Test_CompleteDoneNone()
194 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone()
Bram Moolenaar9845f362019-04-08 18:59:54 +0200195 let oldline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100196
197 set completefunc=<SID>CompleteDone_CompleteFuncNone
198 execute "normal a\<C-X>\<C-U>\<C-Y>"
199 set completefunc&
Bram Moolenaar9845f362019-04-08 18:59:54 +0200200 let newline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100201
202 call assert_true(s:called_completedone)
Bram Moolenaar9845f362019-04-08 18:59:54 +0200203 call assert_equal(oldline, newline)
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100204
205 let s:called_completedone = 0
206 au! CompleteDone
207endfunc
208
209func Test_CompleteDoneDict()
Bram Moolenaar3f169ce2020-01-26 22:43:31 +0100210 au CompleteDonePre * :call <SID>CompleteDone_CheckCompletedItemDict(1)
211 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict(0)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100212
213 set completefunc=<SID>CompleteDone_CompleteFuncDict
214 execute "normal a\<C-X>\<C-U>\<C-Y>"
215 set completefunc&
216
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100217 call assert_equal('test', v:completed_item[ 'user_data' ])
218 call assert_true(s:called_completedone)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100219
220 let s:called_completedone = 0
221 au! CompleteDone
222endfunc
223
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100224func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100225 if a:findstart
226 return 0
227 endif
228
229 return {
Bram Moolenaar08928322020-01-04 14:32:48 +0100230 \ 'words': [
231 \ {
232 \ 'word': 'aword',
233 \ 'abbr': 'wrd',
234 \ 'menu': 'extra text',
235 \ 'info': 'words are cool',
236 \ 'kind': 'W',
237 \ 'user_data': ['one', 'two'],
238 \ }
239 \ ]
240 \ }
Bram Moolenaar1e115362019-01-09 23:01:02 +0100241endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100242
Bram Moolenaar1e115362019-01-09 23:01:02 +0100243func s:CompleteDone_CheckCompletedItemDictNoUserData()
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100244 call assert_equal( 'aword', v:completed_item[ 'word' ] )
245 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] )
246 call assert_equal( 'extra text', v:completed_item[ 'menu' ] )
247 call assert_equal( 'words are cool', v:completed_item[ 'info' ] )
248 call assert_equal( 'W', v:completed_item[ 'kind' ] )
Bram Moolenaar08928322020-01-04 14:32:48 +0100249 call assert_equal( ['one', 'two'], v:completed_item[ 'user_data' ] )
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100250
251 let s:called_completedone = 1
Bram Moolenaar1e115362019-01-09 23:01:02 +0100252endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100253
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100254func Test_CompleteDoneDictNoUserData()
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100255 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData()
256
257 set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData
258 execute "normal a\<C-X>\<C-U>\<C-Y>"
259 set completefunc&
260
Bram Moolenaar08928322020-01-04 14:32:48 +0100261 call assert_equal(['one', 'two'], v:completed_item[ 'user_data' ])
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100262 call assert_true(s:called_completedone)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100263
264 let s:called_completedone = 0
265 au! CompleteDone
266endfunc
267
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100268func s:CompleteDone_CompleteFuncList(findstart, base)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100269 if a:findstart
270 return 0
271 endif
272
273 return [ 'aword' ]
Bram Moolenaar1e115362019-01-09 23:01:02 +0100274endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100275
Bram Moolenaar1e115362019-01-09 23:01:02 +0100276func s:CompleteDone_CheckCompletedItemList()
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100277 call assert_equal( 'aword', v:completed_item[ 'word' ] )
278 call assert_equal( '', v:completed_item[ 'abbr' ] )
279 call assert_equal( '', v:completed_item[ 'menu' ] )
280 call assert_equal( '', v:completed_item[ 'info' ] )
281 call assert_equal( '', v:completed_item[ 'kind' ] )
282 call assert_equal( '', v:completed_item[ 'user_data' ] )
283
284 let s:called_completedone = 1
Bram Moolenaar1e115362019-01-09 23:01:02 +0100285endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100286
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100287func Test_CompleteDoneList()
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100288 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList()
289
290 set completefunc=<SID>CompleteDone_CompleteFuncList
291 execute "normal a\<C-X>\<C-U>\<C-Y>"
292 set completefunc&
293
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100294 call assert_equal('', v:completed_item[ 'user_data' ])
295 call assert_true(s:called_completedone)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100296
297 let s:called_completedone = 0
298 au! CompleteDone
299endfunc
300
Bram Moolenaaraf559d22018-08-08 22:55:41 +0200301func Test_CompleteDone_undo()
302 au CompleteDone * call append(0, "prepend1")
303 new
304 call setline(1, ["line1", "line2"])
305 call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx")
306 call assert_equal(["prepend1", "line1", "line2", "line1", ""],
307 \ getline(1, '$'))
308 undo
309 call assert_equal(["line1", "line2"], getline(1, '$'))
310 bwipe!
311 au! CompleteDone
312endfunc
313
Bram Moolenaar02ae9b42018-02-09 15:06:02 +0100314" Check that when using feedkeys() typeahead does not interrupt searching for
315" completions.
316func Test_compl_feedkeys()
317 new
318 set completeopt=menuone,noselect
319 call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx")
320 call assert_equal("jump jump", getline(1))
321 bwipe!
322 set completeopt&
323endfunc
Bram Moolenaarf03e3282019-07-22 21:55:18 +0200324
325func Test_compl_in_cmdwin()
326 set wildmenu wildchar=<Tab>
327 com! -nargs=1 -complete=command GetInput let input = <q-args>
328 com! -buffer TestCommand echo 'TestCommand'
329
330 let input = ''
331 call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!')
332 call assert_equal('TestCommand', input)
333
334 let input = ''
335 call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!')
336 call assert_equal('T', input)
337
338 delcom TestCommand
339 delcom GetInput
340 set wildmenu& wildchar&
341endfunc
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200342
343" Test for insert path completion with completeslash option
344func Test_ins_completeslash()
Bram Moolenaar50f91d22019-08-02 19:52:15 +0200345 CheckMSWindows
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200346
347 call mkdir('Xdir')
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200348 let orig_shellslash = &shellslash
349 set cpt&
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200350 new
351
352 set noshellslash
353
354 set completeslash=
355 exe "normal oXd\<C-X>\<C-F>"
356 call assert_equal('Xdir\', getline('.'))
357
358 set completeslash=backslash
359 exe "normal oXd\<C-X>\<C-F>"
360 call assert_equal('Xdir\', getline('.'))
361
362 set completeslash=slash
363 exe "normal oXd\<C-X>\<C-F>"
364 call assert_equal('Xdir/', getline('.'))
365
366 set shellslash
367
368 set completeslash=
369 exe "normal oXd\<C-X>\<C-F>"
370 call assert_equal('Xdir/', getline('.'))
371
372 set completeslash=backslash
373 exe "normal oXd\<C-X>\<C-F>"
374 call assert_equal('Xdir\', getline('.'))
375
376 set completeslash=slash
377 exe "normal oXd\<C-X>\<C-F>"
378 call assert_equal('Xdir/', getline('.'))
379 %bw!
380 call delete('Xdir', 'rf')
381
Bram Moolenaar50f91d22019-08-02 19:52:15 +0200382 set noshellslash
383 set completeslash=slash
384 call assert_true(stridx(globpath(&rtp, 'syntax/*.vim', 1, 1)[0], '\') != -1)
385
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200386 let &shellslash = orig_shellslash
Bram Moolenaar50f91d22019-08-02 19:52:15 +0200387 set completeslash=
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200388endfunc
389
Bram Moolenaar09dd2bb2019-12-14 18:42:15 +0100390func Test_pum_with_folds_two_tabs()
391 CheckScreendump
392
393 let lines =<< trim END
394 set fdm=marker
395 call setline(1, ['" x {{{1', '" a some text'])
396 call setline(3, range(&lines)->map({_, val -> '" a' .. val}))
397 norm! zm
398 tab sp
399 call feedkeys('2Gzv', 'xt')
400 call feedkeys("0fa", 'xt')
401 END
402
403 call writefile(lines, 'Xpumscript')
404 let buf = RunVimInTerminal('-S Xpumscript', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200405 call TermWait(buf, 50)
Bram Moolenaar09dd2bb2019-12-14 18:42:15 +0100406 call term_sendkeys(buf, "a\<C-N>")
407 call VerifyScreenDump(buf, 'Test_pum_with_folds_two_tabs', {})
408
409 call term_sendkeys(buf, "\<Esc>")
410 call StopVimInTerminal(buf)
411 call delete('Xpumscript')
412endfunc
Bram Moolenaar5e5a98d2019-12-15 14:55:33 +0100413
414func Test_pum_with_preview_win()
415 CheckScreendump
416
417 let lines =<< trim END
418 funct Omni_test(findstart, base)
419 if a:findstart
420 return col(".") - 1
421 endif
422 return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}]
423 endfunc
424 set omnifunc=Omni_test
425 set completeopt+=longest
426 END
427
428 call writefile(lines, 'Xpreviewscript')
429 let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200430 call TermWait(buf, 50)
Bram Moolenaar5e5a98d2019-12-15 14:55:33 +0100431 call term_sendkeys(buf, "Gi\<C-X>\<C-O>")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200432 call TermWait(buf, 100)
Bram Moolenaar5e5a98d2019-12-15 14:55:33 +0100433 call term_sendkeys(buf, "\<C-N>")
434 call VerifyScreenDump(buf, 'Test_pum_with_preview_win', {})
435
436 call term_sendkeys(buf, "\<Esc>")
437 call StopVimInTerminal(buf)
438 call delete('Xpreviewscript')
439endfunc
Bram Moolenaar830c1af2020-01-05 20:35:44 +0100440
441" Test for inserting the tag search pattern in insert mode
442func Test_ins_compl_tag_sft()
443 call writefile([
444 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
445 \ "first\tXfoo\t/^int first() {}$/",
446 \ "second\tXfoo\t/^int second() {}$/",
447 \ "third\tXfoo\t/^int third() {}$/"],
448 \ 'Xtags')
449 set tags=Xtags
450 let code =<< trim [CODE]
451 int first() {}
452 int second() {}
453 int third() {}
454 [CODE]
455 call writefile(code, 'Xfoo')
456
457 enew
458 set showfulltag
459 exe "normal isec\<C-X>\<C-]>\<C-N>\<CR>"
460 call assert_equal('int second() {}', getline(1))
461 set noshowfulltag
462
463 call delete('Xtags')
464 call delete('Xfoo')
465 set tags&
466 %bwipe!
467endfunc
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200468
469" Test for 'completefunc' deleting text
470func Test_completefunc_error()
471 new
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200472 " delete text when called for the first time
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200473 func CompleteFunc(findstart, base)
474 if a:findstart == 1
475 normal dd
476 return col('.') - 1
477 endif
478 return ['a', 'b']
479 endfunc
480 set completefunc=CompleteFunc
481 call setline(1, ['', 'abcd', ''])
482 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E840:')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200483
484 " delete text when called for the second time
485 func CompleteFunc2(findstart, base)
486 if a:findstart == 1
487 return col('.') - 1
488 endif
489 normal dd
490 return ['a', 'b']
491 endfunc
492 set completefunc=CompleteFunc2
493 call setline(1, ['', 'abcd', ''])
Bram Moolenaar6adb9ea2020-04-30 22:31:18 +0200494 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200495
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200496 set completefunc&
497 delfunc CompleteFunc
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200498 delfunc CompleteFunc2
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200499 close!
500endfunc
501
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200502" Test for errors in using complete() function
503func Test_complete_func_error()
504 call assert_fails('call complete(1, ["a"])', 'E785:')
505 func ListColors()
506 call complete(col('.'), "blue")
507 endfunc
508 call assert_fails('exe "normal i\<C-R>=ListColors()\<CR>"', 'E474:')
509 func ListMonths()
510 call complete(col('.'), test_null_list())
511 endfunc
512 call assert_fails('exe "normal i\<C-R>=ListMonths()\<CR>"', 'E474:')
513 delfunc ListColors
514 delfunc ListMonths
515 call assert_fails('call complete_info({})', 'E714:')
516endfunc
517
Bram Moolenaar224a5f12020-04-28 20:29:07 +0200518" Test for completing words following a completed word in a line
519func Test_complete_wrapscan()
520 " complete words from another buffer
521 new
522 call setline(1, ['one two', 'three four'])
523 new
524 setlocal complete=w
525 call feedkeys("itw\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt')
526 call assert_equal('two three four', getline(1))
527 close!
528 " complete words from the current buffer
529 setlocal complete=.
530 %d
531 call setline(1, ['one two', ''])
532 call cursor(2, 1)
533 call feedkeys("ion\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt')
534 call assert_equal('one two one two', getline(2))
535 close!
536endfunc
537
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200538" vim: shiftwidth=2 sts=2 expandtab