comparison src/testdir/test_popup.vim @ 14055:ac5265f7d1c7 v8.1.0045

patch 8.1.0045: popup test isn't run completely commit https://github.com/vim/vim/commit/ae0f30b761eb62e1b6bfc83fb4a6d1a47bf48320 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jun 12 15:22:43 2018 +0200 patch 8.1.0045: popup test isn't run completely Problem: Popup test isn't run completely. Solution: Remove "finish". Clean up function definitions.
author Christian Brabandt <cb@256bit.org>
date Tue, 12 Jun 2018 15:30:05 +0200
parents 8ba288f12675
children 6a74cde86252
comparison
equal deleted inserted replaced
14054:b1e910a646dc 14055:ac5265f7d1c7
4 source screendump.vim 4 source screendump.vim
5 5
6 let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] 6 let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
7 let g:setting = '' 7 let g:setting = ''
8 8
9 func! ListMonths() 9 func ListMonths()
10 if g:setting != '' 10 if g:setting != ''
11 exe ":set" g:setting 11 exe ":set" g:setting
12 endif 12 endif
13 let mth = copy(g:months) 13 let mth = copy(g:months)
14 let entered = strcharpart(getline('.'),0,col('.')) 14 let entered = strcharpart(getline('.'),0,col('.'))
17 endif 17 endif
18 call complete(1, mth) 18 call complete(1, mth)
19 return '' 19 return ''
20 endfunc 20 endfunc
21 21
22 func! Test_popup_complete2() 22 func Test_popup_complete2()
23 " Although the popupmenu is not visible, this does not mean completion mode 23 " Although the popupmenu is not visible, this does not mean completion mode
24 " has ended. After pressing <f5> to complete the currently typed char, Vim 24 " has ended. After pressing <f5> to complete the currently typed char, Vim
25 " still stays in the first state of the completion (:h ins-completion-menu), 25 " still stays in the first state of the completion (:h ins-completion-menu),
26 " although the popupmenu wasn't shown <c-e> will remove the inserted 26 " although the popupmenu wasn't shown <c-e> will remove the inserted
27 " completed text (:h complete_CTRL-E), while the following <c-e> will behave 27 " completed text (:h complete_CTRL-E), while the following <c-e> will behave
32 :1 32 :1
33 call feedkeys("aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>", 'tx') 33 call feedkeys("aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>", 'tx')
34 call assert_equal(["Dece", "", "December2015"], getline(1,3)) 34 call assert_equal(["Dece", "", "December2015"], getline(1,3))
35 %d 35 %d
36 bw! 36 bw!
37 endfu 37 endfunc
38 38
39 func! Test_popup_complete() 39 func Test_popup_complete()
40 new 40 new
41 inoremap <f5> <c-r>=ListMonths()<cr> 41 inoremap <f5> <c-r>=ListMonths()<cr>
42 42
43 " <C-E> - select original typed text before the completion started 43 " <C-E> - select original typed text before the completion started
44 call feedkeys("aJu\<f5>\<down>\<c-e>\<esc>", 'tx') 44 call feedkeys("aJu\<f5>\<down>\<c-e>\<esc>", 'tx')
213 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') 213 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx')
214 set completeopt-=noselect completeopt+=noinsert 214 set completeopt-=noselect completeopt+=noinsert
215 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') 215 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx')
216 call assert_equal(["March", "M", "March"], getline(1,4)) 216 call assert_equal(["March", "M", "March"], getline(1,4))
217 %d 217 %d
218 endfu 218 endfunc
219 219
220 220
221 func! Test_popup_completion_insertmode() 221 func Test_popup_completion_insertmode()
222 new 222 new
223 inoremap <F5> <C-R>=ListMonths()<CR> 223 inoremap <F5> <C-R>=ListMonths()<CR>
224 224
225 call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx') 225 call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx')
226 call assert_equal('February', getline(1)) 226 call assert_equal('February', getline(1))
245 call assert_equal('December', getline(1)) 245 call assert_equal('December', getline(1))
246 246
247 iunmap <F5> 247 iunmap <F5>
248 endfunc 248 endfunc
249 249
250 " TODO: Fix what breaks after this line.
251 " - Do not use "q!", it may exit Vim if there is an error
252 finish
253
254 func Test_noinsert_complete() 250 func Test_noinsert_complete()
255 function! s:complTest1() abort 251 func! s:complTest1() abort
256 call complete(1, ['source', 'soundfold']) 252 call complete(1, ['source', 'soundfold'])
257 return '' 253 return ''
258 endfunction 254 endfunc
259 255
260 function! s:complTest2() abort 256 func! s:complTest2() abort
261 call complete(1, ['source', 'soundfold']) 257 call complete(1, ['source', 'soundfold'])
262 return '' 258 return ''
263 endfunction 259 endfunc
264 260
265 new 261 new
266 set completeopt+=noinsert 262 set completeopt+=noinsert
267 inoremap <F5> <C-R>=s:complTest1()<CR> 263 inoremap <F5> <C-R>=s:complTest1()<CR>
268 call feedkeys("i\<F5>soun\<CR>\<CR>\<ESC>.", 'tx') 264 call feedkeys("i\<F5>soun\<CR>\<CR>\<ESC>.", 'tx')
279 set completeopt-=noinsert 275 set completeopt-=noinsert
280 iunmap <F5> 276 iunmap <F5>
281 endfunc 277 endfunc
282 278
283 func Test_compl_vim_cmds_after_register_expr() 279 func Test_compl_vim_cmds_after_register_expr()
284 function! s:test_func() 280 func! s:test_func()
285 return 'autocmd ' 281 return 'autocmd '
286 endfunction 282 endfunc
287 augroup AAAAA_Group 283 augroup AAAAA_Group
288 au! 284 au!
289 augroup END 285 augroup END
290 286
291 new 287 new
328 wincmd n 324 wincmd n
329 return 0 325 return 0
330 else 326 else
331 return ['twodef', 'twoDEF'] 327 return ['twodef', 'twoDEF']
332 endif 328 endif
333 endfunction 329 endfunc
334 330
335 " Test that nothing happens if the 'completefunc' opens 331 " Test that nothing happens if the 'completefunc' opens
336 " a new window (no completion, no crash) 332 " a new window (no completion, no crash)
337 func Test_completefunc_opens_new_window_two() 333 func Test_completefunc_opens_new_window_two()
338 new 334 new
405 call assert_equal('four5', getline(1)) 401 call assert_equal('four5', getline(1))
406 402
407 q! 403 q!
408 endfunc 404 endfunc
409 405
410 function UndoComplete() 406 func UndoComplete()
411 call complete(1, ['January', 'February', 'March', 407 call complete(1, ['January', 'February', 'March',
412 \ 'April', 'May', 'June', 'July', 'August', 'September', 408 \ 'April', 'May', 'June', 'July', 'August', 'September',
413 \ 'October', 'November', 'December']) 409 \ 'October', 'November', 'December'])
414 return '' 410 return ''
415 endfunc 411 endfunc
442 iunmap <Right> 438 iunmap <Right>
443 set completeopt& 439 set completeopt&
444 q! 440 q!
445 endfunc 441 endfunc
446 442
447 function! DummyCompleteFive(findstart, base) 443 func DummyCompleteFive(findstart, base)
448 if a:findstart 444 if a:findstart
449 return 0 445 return 0
450 else 446 else
451 return [ 447 return [
452 \ { 'word': 'January', 'info': "info1-1\n1-2\n1-3" }, 448 \ { 'word': 'January', 'info': "info1-1\n1-2\n1-3" },
487 483
488 let &tw = tw_save 484 let &tw = tw_save
489 q! 485 q!
490 endfunc 486 endfunc
491 487
492 function! DummyCompleteSix() 488 func DummyCompleteSix()
493 call complete(1, ['Hello', 'World']) 489 call complete(1, ['Hello', 'World'])
494 return '' 490 return ''
495 endfunction 491 endfunction
496 492
497 " complete() correctly clears the list of autocomplete candidates 493 " complete() correctly clears the list of autocomplete candidates
575 endtry 571 endtry
576 call assert_equal(['', '/*', ' *', ' */'], getline(1,4)) 572 call assert_equal(['', '/*', ' *', ' */'], getline(1,4))
577 bwipe! 573 bwipe!
578 endfunc 574 endfunc
579 575
580 fun MessCompleteMonths() 576 func MessCompleteMonths()
581 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep") 577 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep")
582 call complete_add(m) 578 call complete_add(m)
583 if complete_check() 579 if complete_check()
584 break 580 break
585 endif 581 endif
586 endfor 582 endfor
587 return [] 583 return []
588 endfun 584 endfunc
589 585
590 fun MessCompleteMore() 586 func MessCompleteMore()
591 call complete(1, split("Oct Nov Dec")) 587 call complete(1, split("Oct Nov Dec"))
592 return [] 588 return []
593 endfun 589 endfunc
594 590
595 fun MessComplete(findstart, base) 591 func MessComplete(findstart, base)
596 if a:findstart 592 if a:findstart
597 let line = getline('.') 593 let line = getline('.')
598 let start = col('.') - 1 594 let start = col('.') - 1
599 while start > 0 && line[start - 1] =~ '\a' 595 while start > 0 && line[start - 1] =~ '\a'
600 let start -= 1 596 let start -= 1
603 else 599 else
604 call MessCompleteMonths() 600 call MessCompleteMonths()
605 call MessCompleteMore() 601 call MessCompleteMore()
606 return [] 602 return []
607 endif 603 endif
608 endf 604 endfunc
609 605
610 func Test_complete_func_mess() 606 func Test_complete_func_mess()
611 " Calling complete() after complete_add() in 'completefunc' is wrong, but it 607 " Calling complete() after complete_add() in 'completefunc' is wrong, but it
612 " should not crash. 608 " should not crash.
613 set completefunc=MessComplete 609 set completefunc=MessComplete
833 call feedkeys("A\<C-P>\<C-N>rt\<cr>", 'tx') 829 call feedkeys("A\<C-P>\<C-N>rt\<cr>", 'tx')
834 call assert_equal(expected, getline(1,'$')) 830 call assert_equal(expected, getline(1,'$'))
835 bwipe! 831 bwipe!
836 endfunc 832 endfunc
837 833
838 fun! Test_complete_o_tab() 834 func Test_complete_o_tab()
839 let s:o_char_pressed = 0 835 let s:o_char_pressed = 0
840 836
841 fun! s:act_on_text_changed() 837 fun! s:act_on_text_changed()
842 if s:o_char_pressed 838 if s:o_char_pressed
843 let s:o_char_pressed = 0 839 let s:o_char_pressed = 0
844 call feedkeys("\<c-x>\<c-n>", 'i') 840 call feedkeys("\<c-x>\<c-n>", 'i')
845 endif 841 endif
846 endf 842 endfunc
847 843
848 set completeopt=menu,noselect 844 set completeopt=menu,noselect
849 new 845 new
850 imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X" 846 imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X"
851 autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o') 847 autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o')
860 856
861 call test_override("char_avail", 0) 857 call test_override("char_avail", 0)
862 bwipe! 858 bwipe!
863 set completeopt& 859 set completeopt&
864 delfunc s:act_on_text_changed 860 delfunc s:act_on_text_changed
865 endf 861 endfunc
866 862
867 863
868 " vim: shiftwidth=2 sts=2 expandtab 864 " vim: shiftwidth=2 sts=2 expandtab