blob: 795a1befaf4016d88545ba156d48f065d9b1acc5 [file] [log] [blame]
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001" Tests for popup windows
2
3if !has('textprop')
4 finish
5endif
6
7source screendump.vim
8
9func Test_simple_popup()
10 if !CanRunVimInTerminal()
11 return
12 endif
13 call writefile([
14 \ "call setline(1, range(1, 100))",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020015 \ "hi PopupColor1 ctermbg=lightblue",
16 \ "hi PopupColor2 ctermbg=lightcyan",
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020017 \ "hi Comment ctermfg=red",
18 \ "call prop_type_add('comment', {'highlight': 'Comment'})",
Bram Moolenaar60cdb302019-05-27 21:54:10 +020019 \ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})",
20 \ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25, 'minwidth': 20})",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020021 \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
Bram Moolenaar4d784b22019-05-25 19:51:39 +020022 \], 'XtestPopup')
23 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
24 call VerifyScreenDump(buf, 'Test_popupwin_01', {})
25
Bram Moolenaarec583842019-05-26 14:11:23 +020026 " Add a tabpage
27 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020028 call term_sendkeys(buf, ":let popupwin = popup_create(["
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020029 \ .. "{'text': 'other tab'},"
30 \ .. "{'text': 'a comment line', 'props': [{"
Bram Moolenaar60cdb302019-05-27 21:54:10 +020031 \ .. "'col': 3, 'length': 7, 'minwidth': 20, 'type': 'comment'"
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020032 \ .. "}]},"
Bram Moolenaar60cdb302019-05-27 21:54:10 +020033 \ .. "], {'line': 4, 'col': 9, 'minwidth': 20})\<CR>")
Bram Moolenaarec583842019-05-26 14:11:23 +020034 call VerifyScreenDump(buf, 'Test_popupwin_02', {})
35
36 " switch back to first tabpage
37 call term_sendkeys(buf, "gt")
38 call VerifyScreenDump(buf, 'Test_popupwin_03', {})
39
40 " close that tabpage
41 call term_sendkeys(buf, ":quit!\<CR>")
42 call VerifyScreenDump(buf, 'Test_popupwin_04', {})
43
Bram Moolenaar17146962019-05-30 00:12:11 +020044 " resize popup, show empty line at bottom
Bram Moolenaar60cdb302019-05-27 21:54:10 +020045 call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>")
46 call term_sendkeys(buf, ":redraw\<CR>")
47 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
48
Bram Moolenaar17146962019-05-30 00:12:11 +020049 " show not fitting line at bottom
50 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
51 call term_sendkeys(buf, ":redraw\<CR>")
52 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
53
Bram Moolenaar4d784b22019-05-25 19:51:39 +020054 " clean up
55 call StopVimInTerminal(buf)
56 call delete('XtestPopup')
57endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020058
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020059func Test_popup_with_border_and_padding()
60 if !CanRunVimInTerminal()
61 return
62 endif
63 call writefile([
64 \ "call setline(1, range(1, 100))",
65 \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
66 \ "call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})",
67 \ "call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})",
68 \ "call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})",
69 \ "call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})",
70 \], 'XtestPopupBorder')
71 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15})
72 call VerifyScreenDump(buf, 'Test_popupwin_20', {})
73
74 " clean up
75 call StopVimInTerminal(buf)
76 call delete('XtestPopupBorder')
77
78 let with_border_or_padding = {
79 \ 'line': 2,
80 \ 'core_line': 3,
81 \ 'col': 3,
82 \ 'core_col': 4,
83 \ 'width': 14,
84 \ 'core_width': 12,
85 \ 'height': 3,
86 \ 'core_height': 1,
87 \ 'visible': 1}
88 let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
89 call assert_equal(with_border_or_padding, popup_getpos(winid))
90
91 let winid = popup_create('hello paddng', {'line': 2, 'col': 3, 'padding': []})
92 call assert_equal(with_border_or_padding, popup_getpos(winid))
93
94 let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []})
95 call assert_equal({
96 \ 'line': 3,
97 \ 'core_line': 5,
98 \ 'col': 8,
99 \ 'core_col': 10,
100 \ 'width': 14,
101 \ 'core_width': 10,
102 \ 'height': 5,
103 \ 'core_height': 1,
104 \ 'visible': 1}, popup_getpos(winid))
105endfunc
106
Bram Moolenaarb4230122019-05-30 18:40:53 +0200107func Test_popup_with_syntax_win_execute()
108 if !CanRunVimInTerminal()
109 return
110 endif
111 call writefile([
112 \ "call setline(1, range(1, 100))",
113 \ "hi PopupColor ctermbg=lightblue",
114 \ "let winid = popup_create([",
115 \ "\\ '#include <stdio.h>',",
116 \ "\\ 'int main(void)',",
117 \ "\\ '{',",
118 \ "\\ ' printf(123);',",
119 \ "\\ '}',",
120 \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})",
121 \ "call win_execute(winid, 'set syntax=cpp')",
122 \], 'XtestPopup')
123 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
124 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
125
126 " clean up
127 call StopVimInTerminal(buf)
128 call delete('XtestPopup')
129endfunc
130
131func Test_popup_with_syntax_setbufvar()
132 if !CanRunVimInTerminal()
133 return
134 endif
Bram Moolenaar402502d2019-05-30 22:07:36 +0200135 let lines =<< trim END
136 call setline(1, range(1, 100))
137 hi PopupColor ctermbg=lightgrey
138 let winid = popup_create([
139 \ '#include <stdio.h>',
140 \ 'int main(void)',
141 \ '{',
142 \ ' printf(567);',
143 \ '}',
144 \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})
145 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
146 END
147 call writefile(lines, 'XtestPopup')
Bram Moolenaarb4230122019-05-30 18:40:53 +0200148 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
149 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
150
151 " clean up
152 call StopVimInTerminal(buf)
153 call delete('XtestPopup')
154endfunc
155
Bram Moolenaareea16992019-05-31 17:34:48 +0200156func Test_win_execute_closing_curwin()
157 split
158 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200159 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
160 popupclear
161endfunc
162
163func Test_win_execute_not_allowed()
164 let winid = popup_create('some text', {})
165 call assert_fails('call win_execute(winid, "split")', 'E994:')
166 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
167 call assert_fails('call win_execute(winid, "close")', 'E994:')
168 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200169 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200170 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
171 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
172 call assert_fails('call win_execute(winid, "next")', 'E994:')
173 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
174 call assert_fails('call win_execute(winid, "buf")', 'E994:')
175 call assert_fails('call win_execute(winid, "edit")', 'E994:')
176 call assert_fails('call win_execute(winid, "enew")', 'E994:')
177 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
178 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
179 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
180 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaareea16992019-05-31 17:34:48 +0200181 popupclear
182endfunc
183
Bram Moolenaar402502d2019-05-30 22:07:36 +0200184func Test_popup_with_wrap()
185 if !CanRunVimInTerminal()
186 return
187 endif
188 let lines =<< trim END
189 call setline(1, range(1, 100))
190 let winid = popup_create(
191 \ 'a long line that wont fit',
192 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
193 END
194 call writefile(lines, 'XtestPopup')
195 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
196 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
197
198 " clean up
199 call StopVimInTerminal(buf)
200 call delete('XtestPopup')
201endfunc
202
203func Test_popup_without_wrap()
204 if !CanRunVimInTerminal()
205 return
206 endif
207 let lines =<< trim END
208 call setline(1, range(1, 100))
209 let winid = popup_create(
210 \ 'a long line that wont fit',
211 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
212 END
213 call writefile(lines, 'XtestPopup')
214 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
215 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
216
217 " clean up
218 call StopVimInTerminal(buf)
219 call delete('XtestPopup')
220endfunc
221
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200222func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200223 if !has('timers')
224 return
225 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200226 topleft vnew
227 call setline(1, 'hello')
228
229 call popup_create('world', {
230 \ 'line': 1,
231 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200232 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200233 \ 'time': 500,
234 \})
235 redraw
236 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
237 call assert_equal('world', line)
238
239 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200240 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200241 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
242 call assert_equal('hello', line)
243
244 call popup_create('on the command line', {
245 \ 'line': &lines,
246 \ 'col': 10,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200247 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200248 \ 'time': 500,
249 \})
250 redraw
251 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
252 call assert_match('.*on the command line.*', line)
253
254 sleep 700m
255 redraw
256 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
257 call assert_notmatch('.*on the command line.*', line)
258
259 bwipe!
260endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200261
262func Test_popup_hide()
263 topleft vnew
264 call setline(1, 'hello')
265
266 let winid = popup_create('world', {
267 \ 'line': 1,
268 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200269 \ 'minwidth': 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200270 \})
271 redraw
272 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
273 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200274 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200275 " buffer is still listed and active
276 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200277
278 call popup_hide(winid)
279 redraw
280 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
281 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200282 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200283 " buffer is still listed but hidden
284 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200285
286 call popup_show(winid)
287 redraw
288 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
289 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200290 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200291
292
293 call popup_close(winid)
294 redraw
295 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
296 call assert_equal('hello', line)
297
298 " error is given for existing non-popup window
299 call assert_fails('call popup_hide(win_getid())', 'E993:')
300
301 " no error non-existing window
302 call popup_hide(1234234)
303 call popup_show(41234234)
304
305 bwipe!
306endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200307
308func Test_popup_move()
309 topleft vnew
310 call setline(1, 'hello')
311
312 let winid = popup_create('world', {
313 \ 'line': 1,
314 \ 'col': 1,
315 \ 'minwidth': 20,
316 \})
317 redraw
318 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
319 call assert_equal('world ', line)
320
321 call popup_move(winid, {'line': 2, 'col': 2})
322 redraw
323 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
324 call assert_equal('hello ', line)
325 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
326 call assert_equal('~world', line)
327
328 call popup_move(winid, {'line': 1})
329 redraw
330 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
331 call assert_equal('hworld', line)
332
333 call popup_close(winid)
334
335 bwipe!
336endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200337
Bram Moolenaar402502d2019-05-30 22:07:36 +0200338func Test_popup_getpos()
Bram Moolenaarbc133542019-05-29 20:26:46 +0200339 let winid = popup_create('hello', {
340 \ 'line': 2,
341 \ 'col': 3,
342 \ 'minwidth': 10,
343 \ 'minheight': 11,
344 \})
345 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200346 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200347 call assert_equal(2, res.line)
348 call assert_equal(3, res.col)
349 call assert_equal(10, res.width)
350 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200351 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200352
353 call popup_close(winid)
354endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200355
356func Test_popup_width_longest()
357 let tests = [
358 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
359 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
360 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
361 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
362 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
363 \ ]
364
365 for test in tests
366 let winid = popup_create(test[0], {'line': 2, 'col': 3})
367 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200368 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200369 call assert_equal(test[1], position.width)
370 call popup_close(winid)
371 endfor
372endfunc
373
374func Test_popup_wraps()
375 let tests = [
376 \ ['nowrap', 6, 1],
377 \ ['a line that wraps once', 12, 2],
378 \ ['a line that wraps two times', 12, 3],
379 \ ]
380 for test in tests
381 let winid = popup_create(test[0],
382 \ {'line': 2, 'col': 3, 'maxwidth': 12})
383 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200384 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200385 call assert_equal(test[1], position.width)
386 call assert_equal(test[2], position.height)
387
388 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200389 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200390 endfor
391endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200392
393func Test_popup_getoptions()
394 let winid = popup_create('hello', {
395 \ 'line': 2,
396 \ 'col': 3,
397 \ 'minwidth': 10,
398 \ 'minheight': 11,
399 \ 'maxwidth': 20,
400 \ 'maxheight': 21,
401 \ 'zindex': 100,
402 \ 'time': 5000,
403 \})
404 redraw
405 let res = popup_getoptions(winid)
406 call assert_equal(2, res.line)
407 call assert_equal(3, res.col)
408 call assert_equal(10, res.minwidth)
409 call assert_equal(11, res.minheight)
410 call assert_equal(20, res.maxwidth)
411 call assert_equal(21, res.maxheight)
412 call assert_equal(100, res.zindex)
413 if has('timers')
414 call assert_equal(5000, res.time)
415 endif
416 call popup_close(winid)
417
418 let winid = popup_create('hello', {})
419 redraw
420 let res = popup_getoptions(winid)
421 call assert_equal(0, res.line)
422 call assert_equal(0, res.col)
423 call assert_equal(0, res.minwidth)
424 call assert_equal(0, res.minheight)
425 call assert_equal(0, res.maxwidth)
426 call assert_equal(0, res.maxheight)
427 call assert_equal(50, res.zindex)
428 if has('timers')
429 call assert_equal(0, res.time)
430 endif
431 call popup_close(winid)
432 call assert_equal({}, popup_getoptions(winid))
433endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200434
435func Test_popup_option_values()
436 new
437 " window-local
438 setlocal number
439 setlocal nowrap
440 " buffer-local
441 setlocal omnifunc=Something
442 " global/buffer-local
443 setlocal path=/there
444 " global/window-local
445 setlocal scrolloff=9
446
447 let winid = popup_create('hello', {})
448 call assert_equal(0, getwinvar(winid, '&number'))
449 call assert_equal(1, getwinvar(winid, '&wrap'))
450 call assert_equal('', getwinvar(winid, '&omnifunc'))
451 call assert_equal(&g:path, getwinvar(winid, '&path'))
452 call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
453
454 call popup_close(winid)
455 bwipe
456endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200457
458func Test_popup_atcursor()
459 topleft vnew
460 call setline(1, [
461 \ 'xxxxxxxxxxxxxxxxx',
462 \ 'xxxxxxxxxxxxxxxxx',
463 \ 'xxxxxxxxxxxxxxxxx',
464 \])
465
466 call cursor(2, 2)
467 redraw
468 let winid = popup_atcursor('vim', {})
469 redraw
470 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
471 call assert_equal('xvimxxxxxxxxxxxxx', line)
472 call popup_close(winid)
473
474 call cursor(3, 4)
475 redraw
476 let winid = popup_atcursor('vim', {})
477 redraw
478 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
479 call assert_equal('xxxvimxxxxxxxxxxx', line)
480 call popup_close(winid)
481
482 call cursor(1, 1)
483 redraw
484 let winid = popup_create('vim', {
485 \ 'line': 'cursor+2',
486 \ 'col': 'cursor+1',
487 \})
488 redraw
489 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
490 call assert_equal('xvimxxxxxxxxxxxxx', line)
491 call popup_close(winid)
492
493 call cursor(3, 3)
494 redraw
495 let winid = popup_create('vim', {
496 \ 'line': 'cursor-2',
497 \ 'col': 'cursor-1',
498 \})
499 redraw
500 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
501 call assert_equal('xvimxxxxxxxxxxxxx', line)
502 call popup_close(winid)
503
Bram Moolenaar402502d2019-05-30 22:07:36 +0200504 " just enough room above
505 call cursor(3, 3)
506 redraw
507 let winid = popup_atcursor(['vim', 'is great'], {})
508 redraw
509 let pos = popup_getpos(winid)
510 call assert_equal(1, pos.line)
511 call popup_close(winid)
512
513 " not enough room above, popup goes below the cursor
514 call cursor(3, 3)
515 redraw
516 let winid = popup_atcursor(['vim', 'is', 'great'], {})
517 redraw
518 let pos = popup_getpos(winid)
519 call assert_equal(4, pos.line)
520 call popup_close(winid)
521
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200522 bwipe!
523endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200524
525func Test_popup_filter()
526 new
527 call setline(1, 'some text')
528
529 func MyPopupFilter(winid, c)
530 if a:c == 'e'
531 let g:eaten = 'e'
532 return 1
533 endif
534 if a:c == '0'
535 let g:ignored = '0'
536 return 0
537 endif
538 if a:c == 'x'
539 call popup_close(a:winid)
540 return 1
541 endif
542 return 0
543 endfunc
544
545 let winid = popup_create('something', {'filter': 'MyPopupFilter'})
546 redraw
547
548 " e is consumed by the filter
549 call feedkeys('e', 'xt')
550 call assert_equal('e', g:eaten)
551
552 " 0 is ignored by the filter
553 normal $
554 call assert_equal(9, getcurpos()[2])
555 call feedkeys('0', 'xt')
556 call assert_equal('0', g:ignored)
557 call assert_equal(1, getcurpos()[2])
558
559 " x closes the popup
560 call feedkeys('x', 'xt')
561 call assert_equal('e', g:eaten)
562 call assert_equal(-1, winbufnr(winid))
563
564 delfunc MyPopupFilter
565 popupclear
566endfunc