1source screendump.vim
2source check.vim
3
4" Test for insert expansion
5func Test_ins_complete()
6  edit test_ins_complete.vim
7  " 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
12  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&
99  cd ..
100  call delete('Xdir', 'rf')
101endfunc
102
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
121
122func 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')
131  call assert_equal([1, 1], s:args[0])
132  call assert_equal(0, s:args[1][0])
133  set completefunc=
134
135  let s:args = []
136  set omnifunc=CompleteFunc
137  call feedkeys("i\<C-X>\<C-O>\<Esc>", 'x')
138  call assert_equal([1, 1], s:args[0])
139  call assert_equal(0, s:args[1][0])
140  set omnifunc=
141
142  bwipe!
143  unlet s:args
144  delfunc CompleteFunc
145endfunc
146
147func s:CompleteDone_CompleteFuncNone( findstart, base )
148  if a:findstart
149    return 0
150  endif
151
152  return v:none
153endfunc
154
155func s:CompleteDone_CompleteFuncDict( findstart, base )
156  if a:findstart
157    return 0
158  endif
159
160  return {
161          \ '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        \ }
172endfunc
173
174func s:CompleteDone_CheckCompletedItemNone()
175  let s:called_completedone = 1
176endfunc
177
178func s:CompleteDone_CheckCompletedItemDict()
179  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
186  let s:called_completedone = 1
187endfunc
188
189func Test_CompleteDoneNone()
190  au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone()
191  let oldline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
192
193  set completefunc=<SID>CompleteDone_CompleteFuncNone
194  execute "normal a\<C-X>\<C-U>\<C-Y>"
195  set completefunc&
196  let newline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
197
198  call assert_true(s:called_completedone)
199  call assert_equal(oldline, newline)
200
201  let s:called_completedone = 0
202  au! CompleteDone
203endfunc
204
205func Test_CompleteDoneDict()
206  au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict()
207
208  set completefunc=<SID>CompleteDone_CompleteFuncDict
209  execute "normal a\<C-X>\<C-U>\<C-Y>"
210  set completefunc&
211
212  call assert_equal('test', v:completed_item[ 'user_data' ])
213  call assert_true(s:called_completedone)
214
215  let s:called_completedone = 0
216  au! CompleteDone
217endfunc
218
219func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base)
220  if a:findstart
221    return 0
222  endif
223
224  return {
225          \ 'words': [
226            \ {
227              \ 'word': 'aword',
228              \ 'abbr': 'wrd',
229              \ 'menu': 'extra text',
230              \ 'info': 'words are cool',
231              \ 'kind': 'W'
232            \ }
233          \ ]
234        \ }
235endfunc
236
237func s:CompleteDone_CheckCompletedItemDictNoUserData()
238  call assert_equal( 'aword',          v:completed_item[ 'word' ] )
239  call assert_equal( 'wrd',            v:completed_item[ 'abbr' ] )
240  call assert_equal( 'extra text',     v:completed_item[ 'menu' ] )
241  call assert_equal( 'words are cool', v:completed_item[ 'info' ] )
242  call assert_equal( 'W',              v:completed_item[ 'kind' ] )
243  call assert_equal( '',               v:completed_item[ 'user_data' ] )
244
245  let s:called_completedone = 1
246endfunc
247
248func Test_CompleteDoneDictNoUserData()
249  au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData()
250
251  set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData
252  execute "normal a\<C-X>\<C-U>\<C-Y>"
253  set completefunc&
254
255  call assert_equal('', v:completed_item[ 'user_data' ])
256  call assert_true(s:called_completedone)
257
258  let s:called_completedone = 0
259  au! CompleteDone
260endfunc
261
262func s:CompleteDone_CompleteFuncList(findstart, base)
263  if a:findstart
264    return 0
265  endif
266
267  return [ 'aword' ]
268endfunc
269
270func s:CompleteDone_CheckCompletedItemList()
271  call assert_equal( 'aword', v:completed_item[ 'word' ] )
272  call assert_equal( '',      v:completed_item[ 'abbr' ] )
273  call assert_equal( '',      v:completed_item[ 'menu' ] )
274  call assert_equal( '',      v:completed_item[ 'info' ] )
275  call assert_equal( '',      v:completed_item[ 'kind' ] )
276  call assert_equal( '',      v:completed_item[ 'user_data' ] )
277
278  let s:called_completedone = 1
279endfunc
280
281func Test_CompleteDoneList()
282  au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList()
283
284  set completefunc=<SID>CompleteDone_CompleteFuncList
285  execute "normal a\<C-X>\<C-U>\<C-Y>"
286  set completefunc&
287
288  call assert_equal('', v:completed_item[ 'user_data' ])
289  call assert_true(s:called_completedone)
290
291  let s:called_completedone = 0
292  au! CompleteDone
293endfunc
294
295func Test_CompleteDone_undo()
296  au CompleteDone * call append(0, "prepend1")
297  new
298  call setline(1, ["line1", "line2"])
299  call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx")
300  call assert_equal(["prepend1", "line1", "line2", "line1", ""],
301              \     getline(1, '$'))
302  undo
303  call assert_equal(["line1", "line2"], getline(1, '$'))
304  bwipe!
305  au! CompleteDone
306endfunc
307
308" Check that when using feedkeys() typeahead does not interrupt searching for
309" completions.
310func Test_compl_feedkeys()
311  new
312  set completeopt=menuone,noselect
313  call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx")
314  call assert_equal("jump jump", getline(1))
315  bwipe!
316  set completeopt&
317endfunc
318
319func Test_compl_in_cmdwin()
320  set wildmenu wildchar=<Tab>
321  com! -nargs=1 -complete=command GetInput let input = <q-args>
322  com! -buffer TestCommand echo 'TestCommand'
323
324  let input = ''
325  call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!')
326  call assert_equal('TestCommand', input)
327
328  let input = ''
329  call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!')
330  call assert_equal('T', input)
331
332  delcom TestCommand
333  delcom GetInput
334  set wildmenu& wildchar&
335endfunc
336
337" Test for insert path completion with completeslash option
338func Test_ins_completeslash()
339  CheckMSWindows
340
341  call mkdir('Xdir')
342  let orig_shellslash = &shellslash
343  set cpt&
344  new
345
346  set noshellslash
347
348  set completeslash=
349  exe "normal oXd\<C-X>\<C-F>"
350  call assert_equal('Xdir\', getline('.'))
351
352  set completeslash=backslash
353  exe "normal oXd\<C-X>\<C-F>"
354  call assert_equal('Xdir\', getline('.'))
355
356  set completeslash=slash
357  exe "normal oXd\<C-X>\<C-F>"
358  call assert_equal('Xdir/', getline('.'))
359
360  set shellslash
361
362  set completeslash=
363  exe "normal oXd\<C-X>\<C-F>"
364  call assert_equal('Xdir/', getline('.'))
365
366  set completeslash=backslash
367  exe "normal oXd\<C-X>\<C-F>"
368  call assert_equal('Xdir\', getline('.'))
369
370  set completeslash=slash
371  exe "normal oXd\<C-X>\<C-F>"
372  call assert_equal('Xdir/', getline('.'))
373  %bw!
374  call delete('Xdir', 'rf')
375
376  set noshellslash
377  set completeslash=slash
378  call assert_true(stridx(globpath(&rtp, 'syntax/*.vim', 1, 1)[0], '\') != -1)
379
380  let &shellslash = orig_shellslash
381  set completeslash=
382endfunc
383
384func Test_pum_with_folds_two_tabs()
385  CheckScreendump
386
387  let lines =<< trim END
388    set fdm=marker
389    call setline(1, ['" x {{{1', '" a some text'])
390    call setline(3, range(&lines)->map({_, val -> '" a' .. val}))
391    norm! zm
392    tab sp
393    call feedkeys('2Gzv', 'xt')
394    call feedkeys("0fa", 'xt')
395  END
396
397  call writefile(lines, 'Xpumscript')
398  let buf = RunVimInTerminal('-S Xpumscript', #{rows: 10})
399  call term_wait(buf, 100)
400  call term_sendkeys(buf, "a\<C-N>")
401  call VerifyScreenDump(buf, 'Test_pum_with_folds_two_tabs', {})
402
403  call term_sendkeys(buf, "\<Esc>")
404  call StopVimInTerminal(buf)
405  call delete('Xpumscript')
406endfunc
407
408func Test_pum_with_preview_win()
409  CheckScreendump
410
411  let lines =<< trim END
412      funct Omni_test(findstart, base)
413	if a:findstart
414	  return col(".") - 1
415	endif
416	return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}]
417      endfunc
418      set omnifunc=Omni_test
419      set completeopt+=longest
420  END
421
422  call writefile(lines, 'Xpreviewscript')
423  let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12})
424  call term_wait(buf, 100)
425  call term_sendkeys(buf, "Gi\<C-X>\<C-O>")
426  call term_wait(buf, 100)
427  call term_sendkeys(buf, "\<C-N>")
428  call VerifyScreenDump(buf, 'Test_pum_with_preview_win', {})
429
430  call term_sendkeys(buf, "\<Esc>")
431  call StopVimInTerminal(buf)
432  call delete('Xpreviewscript')
433endfunc
434