" Test for completion menu
source shared.vim
source screendump.vim
source check.vim
let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
let g:setting = ''
func ListMonths()
if g:setting != ''
exe ":set" g:setting
endif
let mth = copy(g:months)
let entered = strcharpart(getline('.'),0,col('.'))
if !empty(entered)
let mth = filter(mth, 'v:val=~"^".entered')
endif
call complete(1, mth)
return ''
endfunc
func Test_popup_complete2()
" Although the popupmenu is not visible, this does not mean completion mode
" has ended. After pressing <f5> to complete the currently typed char, Vim
" still stays in the first state of the completion (:h ins-completion-menu),
" although the popupmenu wasn't shown <c-e> will remove the inserted
" completed text (:h complete_CTRL-E), while the following <c-e> will behave
" like expected (:h i_CTRL-E)
new
inoremap <f5> <c-r>=ListMonths()<cr>
call append(1, ["December2015"])
:1
call feedkeys("aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>", 'tx')
call assert_equal(["Dece", "", "December2015"], getline(1,3))
%d
bw!
endfunc
func Test_popup_complete()
new
inoremap <f5> <c-r>=ListMonths()<cr>
" <C-E> - select original typed text before the completion started
call feedkeys("aJu\<f5>\<down>\<c-e>\<esc>", 'tx')
call assert_equal(["Ju"], getline(1,2))
%d
" <C-Y> - accept current match
call feedkeys("a\<f5>". repeat("\<down>",7). "\<c-y>\<esc>", 'tx')
call assert_equal(["August"], getline(1,2))
%d
" <BS> - Delete one character from the inserted text (state: 1)
" TODO: This should not end the completion, but it does.
" This should according to the documentation:
" January
" but instead, this does
" Januar
" (idea is, C-L inserts the match from the popup menu
" but if the menu is closed, it will insert the character <c-l>
call feedkeys("aJ\<f5>\<bs>\<c-l>\<esc>", 'tx')
call assert_equal(["Januar"], getline(1,2))
%d
" any-non special character: Stop completion without changing the match
" and insert the typed character
call feedkeys("a\<f5>20", 'tx')
call assert_equal(["January20"], getline(1,2))
%d
" any-non printable, non-white character: Add this character and
" reduce number of matches
call feedkeys("aJu\<f5>\<c-p>l\<c-y>", 'tx')
call assert_equal(["Jul"], getline(1,2))
%d
" any-non printable, non-white character: Add this character and
" reduce number of matches
call feedkeys("aJu\<f5>\<c-p>l\<c-n>\<c-y>", 'tx')
call assert_equal(["July"], getline(1,2))
%d
" any-non printable, non-white character: Add this character and
" reduce number of matches
call feedkeys("aJu\<f5>\<c-p>l\<c-e>", 'tx')
call assert_equal(["Jul"], getline(1,2))
%d
" <BS> - Delete one character from the inserted text (state: 2)
call feedkeys("a\<f5>\<c-n>\<bs>", 'tx')
call assert_equal(["Februar"], getline(1,2))
%d
" <c-l> - Insert one character from the current match
call feedkeys("aJ\<f5>".repeat("\<c-n>",3)."\<c-l>\<esc>", 'tx')
call assert_equal(["J"], getline(1,2))
%d
" <c-l> - Insert one character from the current match
call feedkeys("aJ\<f5>".repeat("\<c-n>",4)."\<c-l>\<esc>", 'tx')
call assert_equal(["January"], getline(1,2))
%d
" <c-y> - Accept current selected match
call feedkeys("aJ\<f5>\<c-y>\<esc>", 'tx')
call assert_equal(["January"], getline(1,2))
%d
" <c-e> - End completion, go back to what was there before selecting a match
call feedkeys("aJu\<f5>\<c-e>\<esc>", 'tx')
call assert_equal(["Ju"], getline(1,2))
%d
" <PageUp> - Select a match several entries back
call feedkeys("a\<f5>\<PageUp>\<c-y>\<esc>", 'tx')
call assert_equal([""], getline(1,2))
%d
" <PageUp><PageUp> - Select a match several entries back
call feedkeys("a\<f5>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx')
call assert_equal(["December"], getline(1,2))
%d
" <PageUp><PageUp><PageUp> - Select a match several entries back
call feedkeys("a\<f5>\<PageUp>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx')
call assert_equal(["February"], getline(1,2))
%d
" <PageDown> - Select a match several entries further
call feedkeys("a\<f5>\<PageDown>\<c-y>\<esc>", 'tx')
call assert_equal(["November"], getline(1,2))
%d
" <PageDown><PageDown> - Select a match several entries further
call feedkeys("a\<f5>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx')
call assert_equal(["December"], getline(1,2))
%d
" <PageDown><PageDown><PageDown> - Select a match several entries further
call feedkeys("a\<f5>\<PageDown>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx')
call assert_equal([""], getline(1,2))
%d
" <PageDown><PageDown><PageDown><PageDown> - Select a match several entries further
call feedkeys("a\<f5>".repeat("\<PageDown>",4)."\<c-y>\<esc>", 'tx')
call assert_equal(["October"], getline(1,2))
%d