blob: ef5ac72ae9fbba1f495175fae20386ad3788cd6e [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 Moolenaar1e115362019-01-09 23:01:02 +0100178func s:CompleteDone_CheckCompletedItemDict()
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 Moolenaar17e04782020-01-17 18:58:59 +0100186 call assert_equal('function', complete_info().mode)
187
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100188 let s:called_completedone = 1
Bram Moolenaar1e115362019-01-09 23:01:02 +0100189endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100190
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100191func Test_CompleteDoneNone()
192 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone()
Bram Moolenaar9845f362019-04-08 18:59:54 +0200193 let oldline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100194
195 set completefunc=<SID>CompleteDone_CompleteFuncNone
196 execute "normal a\<C-X>\<C-U>\<C-Y>"
197 set completefunc&
Bram Moolenaar9845f362019-04-08 18:59:54 +0200198 let newline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100199
200 call assert_true(s:called_completedone)
Bram Moolenaar9845f362019-04-08 18:59:54 +0200201 call assert_equal(oldline, newline)
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100202
203 let s:called_completedone = 0
204 au! CompleteDone
205endfunc
206
207func Test_CompleteDoneDict()
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100208 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict()
209
210 set completefunc=<SID>CompleteDone_CompleteFuncDict
211 execute "normal a\<C-X>\<C-U>\<C-Y>"
212 set completefunc&
213
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100214 call assert_equal('test', v:completed_item[ 'user_data' ])
215 call assert_true(s:called_completedone)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100216
217 let s:called_completedone = 0
218 au! CompleteDone
219endfunc
220
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100221func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100222 if a:findstart
223 return 0
224 endif
225
226 return {
Bram Moolenaar08928322020-01-04 14:32:48 +0100227 \ 'words': [
228 \ {
229 \ 'word': 'aword',
230 \ 'abbr': 'wrd',
231 \ 'menu': 'extra text',
232 \ 'info': 'words are cool',
233 \ 'kind': 'W',
234 \ 'user_data': ['one', 'two'],
235 \ }
236 \ ]
237 \ }
Bram Moolenaar1e115362019-01-09 23:01:02 +0100238endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100239
Bram Moolenaar1e115362019-01-09 23:01:02 +0100240func s:CompleteDone_CheckCompletedItemDictNoUserData()
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100241 call assert_equal( 'aword', v:completed_item[ 'word' ] )
242 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] )
243 call assert_equal( 'extra text', v:completed_item[ 'menu' ] )
244 call assert_equal( 'words are cool', v:completed_item[ 'info' ] )
245 call assert_equal( 'W', v:completed_item[ 'kind' ] )
Bram Moolenaar08928322020-01-04 14:32:48 +0100246 call assert_equal( ['one', 'two'], v:completed_item[ 'user_data' ] )
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100247
248 let s:called_completedone = 1
Bram Moolenaar1e115362019-01-09 23:01:02 +0100249endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100250
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100251func Test_CompleteDoneDictNoUserData()
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100252 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData()
253
254 set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData
255 execute "normal a\<C-X>\<C-U>\<C-Y>"
256 set completefunc&
257
Bram Moolenaar08928322020-01-04 14:32:48 +0100258 call assert_equal(['one', 'two'], v:completed_item[ 'user_data' ])
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100259 call assert_true(s:called_completedone)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100260
261 let s:called_completedone = 0
262 au! CompleteDone
263endfunc
264
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100265func s:CompleteDone_CompleteFuncList(findstart, base)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100266 if a:findstart
267 return 0
268 endif
269
270 return [ 'aword' ]
Bram Moolenaar1e115362019-01-09 23:01:02 +0100271endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100272
Bram Moolenaar1e115362019-01-09 23:01:02 +0100273func s:CompleteDone_CheckCompletedItemList()
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100274 call assert_equal( 'aword', v:completed_item[ 'word' ] )
275 call assert_equal( '', v:completed_item[ 'abbr' ] )
276 call assert_equal( '', v:completed_item[ 'menu' ] )
277 call assert_equal( '', v:completed_item[ 'info' ] )
278 call assert_equal( '', v:completed_item[ 'kind' ] )
279 call assert_equal( '', v:completed_item[ 'user_data' ] )
280
281 let s:called_completedone = 1
Bram Moolenaar1e115362019-01-09 23:01:02 +0100282endfunc
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100283
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100284func Test_CompleteDoneList()
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100285 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList()
286
287 set completefunc=<SID>CompleteDone_CompleteFuncList
288 execute "normal a\<C-X>\<C-U>\<C-Y>"
289 set completefunc&
290
Bram Moolenaarcee9bc22019-01-11 13:02:23 +0100291 call assert_equal('', v:completed_item[ 'user_data' ])
292 call assert_true(s:called_completedone)
Bram Moolenaar9b56a572018-02-10 16:19:32 +0100293
294 let s:called_completedone = 0
295 au! CompleteDone
296endfunc
297
Bram Moolenaaraf559d22018-08-08 22:55:41 +0200298func Test_CompleteDone_undo()
299 au CompleteDone * call append(0, "prepend1")
300 new
301 call setline(1, ["line1", "line2"])
302 call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx")
303 call assert_equal(["prepend1", "line1", "line2", "line1", ""],
304 \ getline(1, '$'))
305 undo
306 call assert_equal(["line1", "line2"], getline(1, '$'))
307 bwipe!
308 au! CompleteDone
309endfunc
310
Bram Moolenaar02ae9b42018-02-09 15:06:02 +0100311" Check that when using feedkeys() typeahead does not interrupt searching for
312" completions.
313func Test_compl_feedkeys()
314 new
315 set completeopt=menuone,noselect
316 call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx")
317 call assert_equal("jump jump", getline(1))
318 bwipe!
319 set completeopt&
320endfunc
Bram Moolenaarf03e3282019-07-22 21:55:18 +0200321
322func Test_compl_in_cmdwin()
323 set wildmenu wildchar=<Tab>
324 com! -nargs=1 -complete=command GetInput let input = <q-args>
325 com! -buffer TestCommand echo 'TestCommand'
326
327 let input = ''
328 call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!')
329 call assert_equal('TestCommand', input)
330
331 let input = ''
332 call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!')
333 call assert_equal('T', input)
334
335 delcom TestCommand
336 delcom GetInput
337 set wildmenu& wildchar&
338endfunc
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200339
340" Test for insert path completion with completeslash option
341func Test_ins_completeslash()
Bram Moolenaar50f91d22019-08-02 19:52:15 +0200342 CheckMSWindows
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200343
344 call mkdir('Xdir')
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200345 let orig_shellslash = &shellslash
346 set cpt&
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200347 new
348
349 set noshellslash
350
351 set completeslash=
352 exe "normal oXd\<C-X>\<C-F>"
353 call assert_equal('Xdir\', getline('.'))
354
355 set completeslash=backslash
356 exe "normal oXd\<C-X>\<C-F>"
357 call assert_equal('Xdir\', getline('.'))
358
359 set completeslash=slash
360 exe "normal oXd\<C-X>\<C-F>"
361 call assert_equal('Xdir/', getline('.'))
362
363 set shellslash
364
365 set completeslash=
366 exe "normal oXd\<C-X>\<C-F>"
367 call assert_equal('Xdir/', getline('.'))
368
369 set completeslash=backslash
370 exe "normal oXd\<C-X>\<C-F>"
371 call assert_equal('Xdir\', getline('.'))
372
373 set completeslash=slash
374 exe "normal oXd\<C-X>\<C-F>"
375 call assert_equal('Xdir/', getline('.'))
376 %bw!
377 call delete('Xdir', 'rf')
378
Bram Moolenaar50f91d22019-08-02 19:52:15 +0200379 set noshellslash
380 set completeslash=slash
381 call assert_true(stridx(globpath(&rtp, 'syntax/*.vim', 1, 1)[0], '\') != -1)
382
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200383 let &shellslash = orig_shellslash
Bram Moolenaar50f91d22019-08-02 19:52:15 +0200384 set completeslash=
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200385endfunc
386
Bram Moolenaar09dd2bb2019-12-14 18:42:15 +0100387func Test_pum_with_folds_two_tabs()
388 CheckScreendump
389
390 let lines =<< trim END
391 set fdm=marker
392 call setline(1, ['" x {{{1', '" a some text'])
393 call setline(3, range(&lines)->map({_, val -> '" a' .. val}))
394 norm! zm
395 tab sp
396 call feedkeys('2Gzv', 'xt')
397 call feedkeys("0fa", 'xt')
398 END
399
400 call writefile(lines, 'Xpumscript')
401 let buf = RunVimInTerminal('-S Xpumscript', #{rows: 10})
402 call term_wait(buf, 100)
403 call term_sendkeys(buf, "a\<C-N>")
404 call VerifyScreenDump(buf, 'Test_pum_with_folds_two_tabs', {})
405
406 call term_sendkeys(buf, "\<Esc>")
407 call StopVimInTerminal(buf)
408 call delete('Xpumscript')
409endfunc
Bram Moolenaar5e5a98d2019-12-15 14:55:33 +0100410
411func Test_pum_with_preview_win()
412 CheckScreendump
413
414 let lines =<< trim END
415 funct Omni_test(findstart, base)
416 if a:findstart
417 return col(".") - 1
418 endif
419 return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}]
420 endfunc
421 set omnifunc=Omni_test
422 set completeopt+=longest
423 END
424
425 call writefile(lines, 'Xpreviewscript')
426 let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12})
427 call term_wait(buf, 100)
428 call term_sendkeys(buf, "Gi\<C-X>\<C-O>")
429 call term_wait(buf, 100)
430 call term_sendkeys(buf, "\<C-N>")
431 call VerifyScreenDump(buf, 'Test_pum_with_preview_win', {})
432
433 call term_sendkeys(buf, "\<Esc>")
434 call StopVimInTerminal(buf)
435 call delete('Xpreviewscript')
436endfunc
Bram Moolenaar830c1af2020-01-05 20:35:44 +0100437
438" Test for inserting the tag search pattern in insert mode
439func Test_ins_compl_tag_sft()
440 call writefile([
441 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
442 \ "first\tXfoo\t/^int first() {}$/",
443 \ "second\tXfoo\t/^int second() {}$/",
444 \ "third\tXfoo\t/^int third() {}$/"],
445 \ 'Xtags')
446 set tags=Xtags
447 let code =<< trim [CODE]
448 int first() {}
449 int second() {}
450 int third() {}
451 [CODE]
452 call writefile(code, 'Xfoo')
453
454 enew
455 set showfulltag
456 exe "normal isec\<C-X>\<C-]>\<C-N>\<CR>"
457 call assert_equal('int second() {}', getline(1))
458 set noshowfulltag
459
460 call delete('Xtags')
461 call delete('Xfoo')
462 set tags&
463 %bwipe!
464endfunc