1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
" Test for completion menu
function! ComplTest() abort
call complete(1, ['source', 'soundfold'])
return ''
endfunction
function! Test() abort
call complete(1, ['source', 'soundfold'])
return ''
endfunction
func Test_noinsert_complete()
new
set completeopt+=noinsert
inoremap <F5> <C-R>=ComplTest()<CR>
call feedkeys("i\<F5>soun\<CR>\<CR>\<ESC>.", 'tx')
call assert_equal('soundfold', getline(1))
call assert_equal('soundfold', getline(2))
bwipe!
new
inoremap <F5> <C-R>=Test()<CR>
call feedkeys("i\<F5>\<CR>\<ESC>", 'tx')
call assert_equal('source', getline(1))
bwipe!
set completeopt-=noinsert
iunmap <F5>
endfunc
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
call complete(col('.'), g:months)
return ''
endfunc
func! Test_popup_completion_insertmode()
inoremap <F5> <C-R>=ListMonths()<CR>
new
call feedkeys("a\<F5>\<down>\<enter>\<esc>", 'tx')
call assert_equal('February', getline(1))
%d
let g:setting = 'noinsertmode'
call feedkeys("a\<F5>\<down>\<enter>\<esc>", 'tx')
call assert_equal('February', getline(1))
call assert_false(pumvisible())
%d
let g:setting = ''
call feedkeys("a\<F5>". repeat("\<c-n>",12)."\<enter>\<esc>", 'tx')
call assert_equal('', getline(1))
%d
call feedkeys("a\<F5>\<c-p>\<enter>\<esc>", 'tx')
call assert_equal('', getline(1))
%d
call feedkeys("a\<F5>\<c-p>\<c-p>\<enter>\<esc>", 'tx')
call assert_equal('December', getline(1))
bwipe!
iunmap <F5>
endfunc
func DummyCompleteOne(findstart, base)
if a:findstart
return 0
else
wincmd n
return ['onedef', 'oneDEF']
endif
endfunc
" Test that nothing happens if the 'completefunc' opens
" a new window (no completion, no crash)
func Test_completefunc_opens_new_window_one()
new
let winid = win_getid()
setlocal completefunc=DummyCompleteOne
call setline(1, 'one')
/^one
call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E839:')
call assert_notequal(winid, win_getid())
q!
call assert_equal(winid, win_getid())
call assert_equal('', getline(1))
q!
endfunc
" Test that nothing happens if the 'completefunc' opens
" a new window (no completion, no crash)
func DummyCompleteTwo(findstart, base)
if a:findstart
wincmd n
return 0
else
return ['twodef', 'twoDEF']
endif
endfunction
" Test that nothing happens if the 'completefunc' opens
" a new window (no completion, no crash)
func Test_completefunc_opens_new_window_two()
new
let winid = win_getid()
setlocal completefunc=DummyCompleteTwo
call setline(1, 'two')
/^two
call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E764:')
call assert_notequal(winid, win_getid())
q!
call assert_equal(winid, win_getid())
call assert_equal('two', getline(1))
q!
endfunc
func DummyCompleteThree(findstart, base)
if a:findstart
return 0
else
return ['threedef', 'threeDEF']
endif
endfunc
:"Test that 'completefunc' works when it's OK.
func Test_completefunc_works()
new
let winid = win_getid()
setlocal completefunc=DummyCompleteThree
call setline(1, 'three')
/^three
call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")
call assert_equal(winid, win_getid())
call assert_equal('threeDEF', getline(1))
q!
endfunc
func DummyCompleteFour(findstart, base)
if a:findstart
return 0
else
call complete_add('four1')
call complete_add('four2')
call complete_check()
call complete_add('four3')
call complete_add('four4')
call complete_check()
call complete_add('four5')
call complete_add('four6')
return []
endif
endfunc
:"Test that 'completefunc' works when it's OK.
func Test_omnifunc_with_check()
new
setlocal omnifunc=DummyCompleteFour
call setline(1, 'four')
/^four
call feedkeys("A\<C-X>\<C-O>\<C-N>\<Esc>", "x")
call assert_equal('four2', getline(1))
call setline(1, 'four')
/^four
call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<Esc>", "x")
call assert_equal('four3', getline(1))
call setline(1, 'four')
/^four
call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<C-N>\<Esc>", "x")
call assert_equal('four5', getline(1))
q!
endfunc
" vim: shiftwidth=2 sts=2 expandtab
|