blob: f16a46f2618fb188a13c2267fd372bf570c5cf50 [file] [log] [blame]
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001" Tests for popup windows
2
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003source check.vim
4CheckFeature textprop
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005
6source screendump.vim
7
8func Test_simple_popup()
9 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +020010 throw 'Skipped: cannot make screendumps'
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011 endif
12 call writefile([
13 \ "call setline(1, range(1, 100))",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020014 \ "hi PopupColor1 ctermbg=lightblue",
15 \ "hi PopupColor2 ctermbg=lightcyan",
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020016 \ "hi Comment ctermfg=red",
17 \ "call prop_type_add('comment', {'highlight': 'Comment'})",
Bram Moolenaar60cdb302019-05-27 21:54:10 +020018 \ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})",
19 \ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25, 'minwidth': 20})",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020020 \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
Bram Moolenaar4d784b22019-05-25 19:51:39 +020021 \], 'XtestPopup')
22 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
23 call VerifyScreenDump(buf, 'Test_popupwin_01', {})
24
Bram Moolenaarec583842019-05-26 14:11:23 +020025 " Add a tabpage
26 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020027 call term_sendkeys(buf, ":let popupwin = popup_create(["
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020028 \ .. "{'text': 'other tab'},"
29 \ .. "{'text': 'a comment line', 'props': [{"
Bram Moolenaar60cdb302019-05-27 21:54:10 +020030 \ .. "'col': 3, 'length': 7, 'minwidth': 20, 'type': 'comment'"
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020031 \ .. "}]},"
Bram Moolenaar60cdb302019-05-27 21:54:10 +020032 \ .. "], {'line': 4, 'col': 9, 'minwidth': 20})\<CR>")
Bram Moolenaarec583842019-05-26 14:11:23 +020033 call VerifyScreenDump(buf, 'Test_popupwin_02', {})
34
35 " switch back to first tabpage
36 call term_sendkeys(buf, "gt")
37 call VerifyScreenDump(buf, 'Test_popupwin_03', {})
38
39 " close that tabpage
40 call term_sendkeys(buf, ":quit!\<CR>")
41 call VerifyScreenDump(buf, 'Test_popupwin_04', {})
42
Bram Moolenaar202d9822019-06-11 21:56:30 +020043 " set 'columns' to a small value, size must be recomputed
44 call term_sendkeys(buf, ":let cols = &columns\<CR>")
45 call term_sendkeys(buf, ":set columns=12\<CR>")
46 call VerifyScreenDump(buf, 'Test_popupwin_04a', {})
47 call term_sendkeys(buf, ":let &columns = cols\<CR>")
48
Bram Moolenaar17146962019-05-30 00:12:11 +020049 " resize popup, show empty line at bottom
Bram Moolenaar60cdb302019-05-27 21:54:10 +020050 call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>")
51 call term_sendkeys(buf, ":redraw\<CR>")
52 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
53
Bram Moolenaar17146962019-05-30 00:12:11 +020054 " show not fitting line at bottom
55 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
56 call term_sendkeys(buf, ":redraw\<CR>")
57 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
58
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020059 " move popup over ruler
60 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
61 call term_sendkeys(buf, ":call popup_move(popupwin, {'line': 7, 'col': 55})\<CR>")
62 call VerifyScreenDump(buf, 'Test_popupwin_07', {})
63
64 " clear all popups after moving the cursor a bit, so that ruler is updated
65 call term_sendkeys(buf, "axxx\<Esc>")
66 call term_wait(buf)
67 call term_sendkeys(buf, "0")
68 call term_wait(buf)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020069 call term_sendkeys(buf, ":call popup_clear()\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020070 call VerifyScreenDump(buf, 'Test_popupwin_08', {})
71
Bram Moolenaar4d784b22019-05-25 19:51:39 +020072 " clean up
73 call StopVimInTerminal(buf)
74 call delete('XtestPopup')
75endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020076
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020077func Test_popup_with_border_and_padding()
78 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +020079 throw 'Skipped: cannot make screendumps'
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020080 endif
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020081
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020082 for iter in range(0, 1)
83 call writefile([iter == 1 ? '' : 'set enc=latin1',
84 \ "call setline(1, range(1, 100))",
85 \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
86 \ "call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})",
87 \ "call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})",
88 \ "call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})",
89 \ "call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})",
Bram Moolenaar51c31312019-06-15 22:27:23 +020090 \ "call popup_create('wrapped longer text', {'line': 8, 'col': 55, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})",
91 \ "call popup_create('right aligned text', {'line': 11, 'col': 56, 'wrap': 0, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})",
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020092 \], 'XtestPopupBorder')
93 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15})
94 call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
95
96 call StopVimInTerminal(buf)
97 call delete('XtestPopupBorder')
98 endfor
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020099
Bram Moolenaar790498b2019-06-01 22:15:29 +0200100 call writefile([
101 \ "call setline(1, range(1, 100))",
102 \ "hi BlueColor ctermbg=lightblue",
103 \ "hi TopColor ctermbg=253",
104 \ "hi RightColor ctermbg=245",
105 \ "hi BottomColor ctermbg=240",
106 \ "hi LeftColor ctermbg=248",
107 \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor']})",
108 \ "call popup_create(['hello border', 'and more'], {'line': 2, 'col': 23, 'border': [], 'borderhighlight': ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})",
109 \ "call popup_create(['hello border', 'lines only'], {'line': 2, 'col': 43, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x']})",
110 \ "call popup_create(['hello border', 'with corners'], {'line': 2, 'col': 60, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x', '#']})",
111 \ "call popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})",
112 \ "call popup_create(['hello border', 'just blanks'], {'line': 7, 'col': 23, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': [' ']})",
113 \], 'XtestPopupBorder')
114 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 12})
115 call VerifyScreenDump(buf, 'Test_popupwin_22', {})
116
117 call StopVimInTerminal(buf)
118 call delete('XtestPopupBorder')
119
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200120 let with_border_or_padding = {
121 \ 'line': 2,
122 \ 'core_line': 3,
123 \ 'col': 3,
124 \ 'core_col': 4,
125 \ 'width': 14,
126 \ 'core_width': 12,
127 \ 'height': 3,
128 \ 'core_height': 1,
129 \ 'visible': 1}
130 let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
131 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200132 let options = popup_getoptions(winid)
133 call assert_equal([], options.border)
134 call assert_false(has_key(options, "padding"))
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200135
Bram Moolenaarae943152019-06-16 22:54:14 +0200136 let winid = popup_create('hello padding', {'line': 2, 'col': 3, 'padding': []})
137 let with_border_or_padding.width = 15
138 let with_border_or_padding.core_width = 13
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200139 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200140 let options = popup_getoptions(winid)
141 call assert_false(has_key(options, "border"))
142 call assert_equal([], options.padding)
143
144 call popup_setoptions(winid, {
145 \ 'padding': [1, 2, 3, 4],
146 \ 'border': [4, 0, 7, 8],
147 \ 'borderhighlight': ['Top', 'Right', 'Bottom', 'Left'],
148 \ 'borderchars': ['1', '^', '2', '>', '3', 'v', '4', '<'],
149 \ })
150 let options = popup_getoptions(winid)
151 call assert_equal([1, 0, 1, 1], options.border)
152 call assert_equal([1, 2, 3, 4], options.padding)
153 call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
154 call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200155
156 let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []})
157 call assert_equal({
158 \ 'line': 3,
159 \ 'core_line': 5,
160 \ 'col': 8,
161 \ 'core_col': 10,
162 \ 'width': 14,
163 \ 'core_width': 10,
164 \ 'height': 5,
165 \ 'core_height': 1,
166 \ 'visible': 1}, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200167
168 call popup_clear()
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200169endfunc
170
Bram Moolenaarb4230122019-05-30 18:40:53 +0200171func Test_popup_with_syntax_win_execute()
172 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200173 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200174 endif
175 call writefile([
176 \ "call setline(1, range(1, 100))",
177 \ "hi PopupColor ctermbg=lightblue",
178 \ "let winid = popup_create([",
179 \ "\\ '#include <stdio.h>',",
180 \ "\\ 'int main(void)',",
181 \ "\\ '{',",
182 \ "\\ ' printf(123);',",
183 \ "\\ '}',",
184 \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})",
185 \ "call win_execute(winid, 'set syntax=cpp')",
186 \], 'XtestPopup')
187 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
188 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
189
190 " clean up
191 call StopVimInTerminal(buf)
192 call delete('XtestPopup')
193endfunc
194
195func Test_popup_with_syntax_setbufvar()
196 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200197 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200198 endif
Bram Moolenaar402502d2019-05-30 22:07:36 +0200199 let lines =<< trim END
200 call setline(1, range(1, 100))
201 hi PopupColor ctermbg=lightgrey
202 let winid = popup_create([
203 \ '#include <stdio.h>',
204 \ 'int main(void)',
205 \ '{',
206 \ ' printf(567);',
207 \ '}',
208 \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})
209 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
210 END
211 call writefile(lines, 'XtestPopup')
Bram Moolenaarb4230122019-05-30 18:40:53 +0200212 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
213 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
214
215 " clean up
216 call StopVimInTerminal(buf)
217 call delete('XtestPopup')
218endfunc
219
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200220func Test_popup_with_matches()
221 if !CanRunVimInTerminal()
222 throw 'Skipped: cannot make screendumps'
223 endif
224 let lines =<< trim END
225 call setline(1, ['111 222 333', '444 555 666'])
226 let winid = popup_create([
227 \ '111 222 333',
228 \ '444 555 666',
229 \], {'line': 3, 'col': 10, 'border': []})
230 set hlsearch
231 /666
232 call matchadd('ErrorMsg', '111')
233 call matchadd('ErrorMsg', '444')
234 call win_execute(winid, "call matchadd('ErrorMsg', '111')")
235 call win_execute(winid, "call matchadd('ErrorMsg', '555')")
236 END
237 call writefile(lines, 'XtestPopupMatches')
238 let buf = RunVimInTerminal('-S XtestPopupMatches', {'rows': 10})
239 call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
240
241 " clean up
242 call StopVimInTerminal(buf)
243 call delete('XtestPopupMatches')
244endfunc
245
Bram Moolenaar399d8982019-06-02 15:34:29 +0200246func Test_popup_all_corners()
247 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200248 throw 'Skipped: cannot make screendumps'
Bram Moolenaar399d8982019-06-02 15:34:29 +0200249 endif
250 let lines =<< trim END
251 call setline(1, repeat([repeat('-', 60)], 15))
252 set so=0
253 normal 2G3|r#
254 let winid1 = popup_create(['first', 'second'], {
255 \ 'line': 'cursor+1',
256 \ 'col': 'cursor',
257 \ 'pos': 'topleft',
258 \ 'border': [],
259 \ 'padding': [],
260 \ })
261 normal 25|r@
262 let winid1 = popup_create(['First', 'SeconD'], {
263 \ 'line': 'cursor+1',
264 \ 'col': 'cursor',
265 \ 'pos': 'topright',
266 \ 'border': [],
267 \ 'padding': [],
268 \ })
269 normal 9G29|r%
270 let winid1 = popup_create(['fiRSt', 'seCOnd'], {
271 \ 'line': 'cursor-1',
272 \ 'col': 'cursor',
273 \ 'pos': 'botleft',
274 \ 'border': [],
275 \ 'padding': [],
276 \ })
277 normal 51|r&
278 let winid1 = popup_create(['FIrsT', 'SEcoND'], {
279 \ 'line': 'cursor-1',
280 \ 'col': 'cursor',
281 \ 'pos': 'botright',
282 \ 'border': [],
283 \ 'padding': [],
284 \ })
285 END
286 call writefile(lines, 'XtestPopupCorners')
287 let buf = RunVimInTerminal('-S XtestPopupCorners', {'rows': 12})
288 call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
289
290 " clean up
291 call StopVimInTerminal(buf)
292 call delete('XtestPopupCorners')
293endfunc
294
Bram Moolenaar8d241042019-06-12 23:40:01 +0200295func Test_popup_firstline()
296 if !CanRunVimInTerminal()
297 throw 'Skipped: cannot make screendumps'
298 endif
299 let lines =<< trim END
300 call setline(1, range(1, 20))
301 call popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], {
302 \ 'maxheight': 4,
303 \ 'firstline': 3,
304 \ })
305 END
306 call writefile(lines, 'XtestPopupFirstline')
307 let buf = RunVimInTerminal('-S XtestPopupFirstline', {'rows': 10})
308 call VerifyScreenDump(buf, 'Test_popupwin_firstline', {})
309
310 " clean up
311 call StopVimInTerminal(buf)
312 call delete('XtestPopupFirstline')
Bram Moolenaarae943152019-06-16 22:54:14 +0200313
314 let winid = popup_create(['1111', '222222', '33333', '44444'], {
315 \ 'maxheight': 2,
316 \ 'firstline': 3,
317 \ })
318 call assert_equal(3, popup_getoptions(winid).firstline)
319 call popup_setoptions(winid, {'firstline': 1})
320 call assert_equal(1, popup_getoptions(winid).firstline)
321
322 call popup_close(winid)
Bram Moolenaar8d241042019-06-12 23:40:01 +0200323endfunc
324
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200325func Test_popup_drag()
326 if !CanRunVimInTerminal()
327 throw 'Skipped: cannot make screendumps'
328 endif
329 " create a popup that covers the command line
330 let lines =<< trim END
331 call setline(1, range(1, 20))
332 let winid = popup_create(['1111', '222222', '33333'], {
333 \ 'drag': 1,
334 \ 'border': [],
335 \ 'line': &lines - 4,
336 \ })
337 func Dragit()
338 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
339 endfunc
340 map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR>
341 map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2)<CR>
342 END
343 call writefile(lines, 'XtestPopupDrag')
344 let buf = RunVimInTerminal('-S XtestPopupDrag', {'rows': 10})
345 call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {})
346
347 call term_sendkeys(buf, ":call Dragit()\<CR>")
348 call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {})
349
350 " clean up
351 call StopVimInTerminal(buf)
352 call delete('XtestPopupDrag')
353endfunc
354
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200355func Test_popup_select()
356 if !CanRunVimInTerminal()
357 throw 'Skipped: cannot make screendumps'
358 endif
Bram Moolenaar650a6372019-06-15 00:29:33 +0200359 if !has('clipboard')
360 throw 'Skipped: clipboard feature missing'
361 endif
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200362 " create a popup with some text to be selected
363 let lines =<< trim END
Bram Moolenaar1755ec42019-06-15 13:13:54 +0200364 set clipboard=autoselect
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200365 call setline(1, range(1, 20))
366 let winid = popup_create(['the word', 'some more', 'several words here'], {
367 \ 'drag': 1,
368 \ 'border': [],
369 \ 'line': 3,
370 \ 'col': 10,
371 \ })
372 func Select1()
373 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
374 endfunc
375 map <silent> <F3> :call test_setmouse(4, 15)<CR>
376 map <silent> <F4> :call test_setmouse(6, 23)<CR>
377 END
378 call writefile(lines, 'XtestPopupSelect')
379 let buf = RunVimInTerminal('-S XtestPopupSelect', {'rows': 10})
380 call term_sendkeys(buf, ":call Select1()\<CR>")
381 call VerifyScreenDump(buf, 'Test_popupwin_select_01', {})
382
383 call term_sendkeys(buf, ":call popup_close(winid)\<CR>")
384 call term_sendkeys(buf, "\"*p")
385 call VerifyScreenDump(buf, 'Test_popupwin_select_02', {})
386
387 " clean up
388 call StopVimInTerminal(buf)
389 call delete('XtestPopupSelect')
390endfunc
391
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200392func Test_popup_in_tab()
393 " default popup is local to tab, not visible when in other tab
394 let winid = popup_create("text", {})
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200395 let bufnr = winbufnr(winid)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200396 call assert_equal(1, popup_getpos(winid).visible)
397 tabnew
398 call assert_equal(0, popup_getpos(winid).visible)
399 quit
400 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200401
402 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200403 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200404 " buffer is gone now
405 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200406
407 " global popup is visible in any tab
Bram Moolenaarfc06cbb2019-06-15 14:14:31 +0200408 let winid = popup_create("text", {'tabpage': -1})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200409 call assert_equal(1, popup_getpos(winid).visible)
410 tabnew
411 call assert_equal(1, popup_getpos(winid).visible)
412 quit
413 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200414 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200415endfunc
416
417func Test_popup_valid_arguments()
418 " Zero value is like the property wasn't there
419 let winid = popup_create("text", {"col": 0})
420 let pos = popup_getpos(winid)
421 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200422 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200423
424 " using cursor column has minimum value of 1
425 let winid = popup_create("text", {"col": 'cursor-100'})
426 let pos = popup_getpos(winid)
427 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200428 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200429
430 " center
431 let winid = popup_create("text", {"pos": 'center'})
432 let pos = popup_getpos(winid)
433 let around = (&columns - pos.width) / 2
434 call assert_inrange(around - 1, around + 1, pos.col)
435 let around = (&lines - pos.height) / 2
436 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200437 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200438endfunc
439
440func Test_popup_invalid_arguments()
441 call assert_fails('call popup_create(666, {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200442 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200443 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200444 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200445
446 call assert_fails('call popup_create("text", {"col": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200447 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200448 call assert_fails('call popup_create("text", {"col": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200449 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200450 call assert_fails('call popup_create("text", {"col": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200451 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200452 call assert_fails('call popup_create("text", {"col": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200453 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200454
455 call assert_fails('call popup_create("text", {"line": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200456 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200457 call assert_fails('call popup_create("text", {"line": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200458 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200459 call assert_fails('call popup_create("text", {"line": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200460 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200461 call assert_fails('call popup_create("text", {"line": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200462 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200463
464 call assert_fails('call popup_create("text", {"pos": "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200465 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200466 call assert_fails('call popup_create("text", {"padding": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200467 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200468 call assert_fails('call popup_create("text", {"border": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200469 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200470 call assert_fails('call popup_create("text", {"borderhighlight": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200471 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200472 call assert_fails('call popup_create("text", {"borderchars": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200473 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200474
475 call assert_fails('call popup_create([{"text": "text"}, 666], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200476 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200477 call assert_fails('call popup_create([{"text": "text", "props": "none"}], {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200478 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200479 call assert_fails('call popup_create([{"text": "text", "props": ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200480 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200481endfunc
482
Bram Moolenaareea16992019-05-31 17:34:48 +0200483func Test_win_execute_closing_curwin()
484 split
485 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200486 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200487 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200488endfunc
489
490func Test_win_execute_not_allowed()
491 let winid = popup_create('some text', {})
492 call assert_fails('call win_execute(winid, "split")', 'E994:')
493 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
494 call assert_fails('call win_execute(winid, "close")', 'E994:')
495 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200496 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200497 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
498 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
499 call assert_fails('call win_execute(winid, "next")', 'E994:')
500 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
501 call assert_fails('call win_execute(winid, "buf")', 'E994:')
502 call assert_fails('call win_execute(winid, "edit")', 'E994:')
503 call assert_fails('call win_execute(winid, "enew")', 'E994:')
504 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
505 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
506 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
507 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200508 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200509endfunc
510
Bram Moolenaar402502d2019-05-30 22:07:36 +0200511func Test_popup_with_wrap()
512 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200513 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200514 endif
515 let lines =<< trim END
516 call setline(1, range(1, 100))
517 let winid = popup_create(
518 \ 'a long line that wont fit',
519 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
520 END
521 call writefile(lines, 'XtestPopup')
522 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
523 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
524
525 " clean up
526 call StopVimInTerminal(buf)
527 call delete('XtestPopup')
528endfunc
529
530func Test_popup_without_wrap()
531 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200532 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200533 endif
534 let lines =<< trim END
535 call setline(1, range(1, 100))
536 let winid = popup_create(
537 \ 'a long line that wont fit',
538 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
539 END
540 call writefile(lines, 'XtestPopup')
541 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
542 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
543
544 " clean up
545 call StopVimInTerminal(buf)
546 call delete('XtestPopup')
547endfunc
548
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200549func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200550 if !has('timers')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +0200551 throw 'Skipped: timer feature not supported'
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200552 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200553 topleft vnew
554 call setline(1, 'hello')
555
556 call popup_create('world', {
557 \ 'line': 1,
558 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200559 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200560 \ 'time': 500,
561 \})
562 redraw
563 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
564 call assert_equal('world', line)
565
566 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200567 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200568 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
569 call assert_equal('hello', line)
570
571 call popup_create('on the command line', {
572 \ 'line': &lines,
573 \ 'col': 10,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200574 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200575 \ 'time': 500,
576 \})
577 redraw
578 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
579 call assert_match('.*on the command line.*', line)
580
581 sleep 700m
582 redraw
583 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
584 call assert_notmatch('.*on the command line.*', line)
585
586 bwipe!
587endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200588
589func Test_popup_hide()
590 topleft vnew
591 call setline(1, 'hello')
592
593 let winid = popup_create('world', {
594 \ 'line': 1,
595 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200596 \ 'minwidth': 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200597 \})
598 redraw
599 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
600 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200601 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200602 " buffer is still listed and active
603 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200604
605 call popup_hide(winid)
606 redraw
607 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
608 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200609 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200610 " buffer is still listed but hidden
611 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200612
613 call popup_show(winid)
614 redraw
615 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
616 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200617 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200618
619
620 call popup_close(winid)
621 redraw
622 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
623 call assert_equal('hello', line)
624
625 " error is given for existing non-popup window
626 call assert_fails('call popup_hide(win_getid())', 'E993:')
627
628 " no error non-existing window
629 call popup_hide(1234234)
630 call popup_show(41234234)
631
632 bwipe!
633endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200634
635func Test_popup_move()
636 topleft vnew
637 call setline(1, 'hello')
638
639 let winid = popup_create('world', {
640 \ 'line': 1,
641 \ 'col': 1,
642 \ 'minwidth': 20,
643 \})
644 redraw
645 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
646 call assert_equal('world ', line)
647
648 call popup_move(winid, {'line': 2, 'col': 2})
649 redraw
650 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
651 call assert_equal('hello ', line)
652 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
653 call assert_equal('~world', line)
654
655 call popup_move(winid, {'line': 1})
656 redraw
657 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
658 call assert_equal('hworld', line)
659
660 call popup_close(winid)
661
662 bwipe!
663endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200664
Bram Moolenaar402502d2019-05-30 22:07:36 +0200665func Test_popup_getpos()
Bram Moolenaarbc133542019-05-29 20:26:46 +0200666 let winid = popup_create('hello', {
667 \ 'line': 2,
668 \ 'col': 3,
669 \ 'minwidth': 10,
670 \ 'minheight': 11,
671 \})
672 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200673 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200674 call assert_equal(2, res.line)
675 call assert_equal(3, res.col)
676 call assert_equal(10, res.width)
677 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200678 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200679
680 call popup_close(winid)
681endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200682
683func Test_popup_width_longest()
684 let tests = [
685 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
686 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
687 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
688 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
689 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
690 \ ]
691
692 for test in tests
693 let winid = popup_create(test[0], {'line': 2, 'col': 3})
694 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200695 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200696 call assert_equal(test[1], position.width)
697 call popup_close(winid)
698 endfor
699endfunc
700
701func Test_popup_wraps()
702 let tests = [
703 \ ['nowrap', 6, 1],
704 \ ['a line that wraps once', 12, 2],
705 \ ['a line that wraps two times', 12, 3],
706 \ ]
707 for test in tests
708 let winid = popup_create(test[0],
709 \ {'line': 2, 'col': 3, 'maxwidth': 12})
710 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200711 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200712 call assert_equal(test[1], position.width)
713 call assert_equal(test[2], position.height)
714
715 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200716 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200717 endfor
718endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200719
720func Test_popup_getoptions()
721 let winid = popup_create('hello', {
722 \ 'line': 2,
723 \ 'col': 3,
724 \ 'minwidth': 10,
725 \ 'minheight': 11,
726 \ 'maxwidth': 20,
727 \ 'maxheight': 21,
728 \ 'zindex': 100,
729 \ 'time': 5000,
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200730 \ 'fixed': 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200731 \})
732 redraw
733 let res = popup_getoptions(winid)
734 call assert_equal(2, res.line)
735 call assert_equal(3, res.col)
736 call assert_equal(10, res.minwidth)
737 call assert_equal(11, res.minheight)
738 call assert_equal(20, res.maxwidth)
739 call assert_equal(21, res.maxheight)
740 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200741 call assert_equal(1, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200742 if has('timers')
743 call assert_equal(5000, res.time)
744 endif
745 call popup_close(winid)
746
747 let winid = popup_create('hello', {})
748 redraw
749 let res = popup_getoptions(winid)
750 call assert_equal(0, res.line)
751 call assert_equal(0, res.col)
752 call assert_equal(0, res.minwidth)
753 call assert_equal(0, res.minheight)
754 call assert_equal(0, res.maxwidth)
755 call assert_equal(0, res.maxheight)
756 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200757 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200758 if has('timers')
759 call assert_equal(0, res.time)
760 endif
761 call popup_close(winid)
762 call assert_equal({}, popup_getoptions(winid))
763endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200764
765func Test_popup_option_values()
766 new
767 " window-local
768 setlocal number
769 setlocal nowrap
770 " buffer-local
771 setlocal omnifunc=Something
772 " global/buffer-local
773 setlocal path=/there
774 " global/window-local
775 setlocal scrolloff=9
776
777 let winid = popup_create('hello', {})
778 call assert_equal(0, getwinvar(winid, '&number'))
779 call assert_equal(1, getwinvar(winid, '&wrap'))
780 call assert_equal('', getwinvar(winid, '&omnifunc'))
781 call assert_equal(&g:path, getwinvar(winid, '&path'))
782 call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
783
784 call popup_close(winid)
785 bwipe
786endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200787
788func Test_popup_atcursor()
789 topleft vnew
790 call setline(1, [
791 \ 'xxxxxxxxxxxxxxxxx',
792 \ 'xxxxxxxxxxxxxxxxx',
793 \ 'xxxxxxxxxxxxxxxxx',
794 \])
795
796 call cursor(2, 2)
797 redraw
798 let winid = popup_atcursor('vim', {})
799 redraw
800 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
801 call assert_equal('xvimxxxxxxxxxxxxx', line)
802 call popup_close(winid)
803
804 call cursor(3, 4)
805 redraw
806 let winid = popup_atcursor('vim', {})
807 redraw
808 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
809 call assert_equal('xxxvimxxxxxxxxxxx', line)
810 call popup_close(winid)
811
812 call cursor(1, 1)
813 redraw
814 let winid = popup_create('vim', {
815 \ 'line': 'cursor+2',
816 \ 'col': 'cursor+1',
817 \})
818 redraw
819 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
820 call assert_equal('xvimxxxxxxxxxxxxx', line)
821 call popup_close(winid)
822
823 call cursor(3, 3)
824 redraw
825 let winid = popup_create('vim', {
826 \ 'line': 'cursor-2',
827 \ 'col': 'cursor-1',
828 \})
829 redraw
830 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
831 call assert_equal('xvimxxxxxxxxxxxxx', line)
832 call popup_close(winid)
833
Bram Moolenaar402502d2019-05-30 22:07:36 +0200834 " just enough room above
835 call cursor(3, 3)
836 redraw
837 let winid = popup_atcursor(['vim', 'is great'], {})
838 redraw
839 let pos = popup_getpos(winid)
840 call assert_equal(1, pos.line)
841 call popup_close(winid)
842
843 " not enough room above, popup goes below the cursor
844 call cursor(3, 3)
845 redraw
846 let winid = popup_atcursor(['vim', 'is', 'great'], {})
847 redraw
848 let pos = popup_getpos(winid)
849 call assert_equal(4, pos.line)
850 call popup_close(winid)
851
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200852 " cursor in first line, popup in line 2
853 call cursor(1, 1)
854 redraw
855 let winid = popup_atcursor(['vim', 'is', 'great'], {})
856 redraw
857 let pos = popup_getpos(winid)
858 call assert_equal(2, pos.line)
859 call popup_close(winid)
860
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200861 bwipe!
862endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200863
864func Test_popup_filter()
865 new
866 call setline(1, 'some text')
867
868 func MyPopupFilter(winid, c)
869 if a:c == 'e'
870 let g:eaten = 'e'
871 return 1
872 endif
873 if a:c == '0'
874 let g:ignored = '0'
875 return 0
876 endif
877 if a:c == 'x'
878 call popup_close(a:winid)
879 return 1
880 endif
881 return 0
882 endfunc
883
884 let winid = popup_create('something', {'filter': 'MyPopupFilter'})
885 redraw
886
887 " e is consumed by the filter
888 call feedkeys('e', 'xt')
889 call assert_equal('e', g:eaten)
890
891 " 0 is ignored by the filter
892 normal $
893 call assert_equal(9, getcurpos()[2])
894 call feedkeys('0', 'xt')
895 call assert_equal('0', g:ignored)
896 call assert_equal(1, getcurpos()[2])
897
898 " x closes the popup
899 call feedkeys('x', 'xt')
900 call assert_equal('e', g:eaten)
901 call assert_equal(-1, winbufnr(winid))
902
903 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200904 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200905endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200906
Bram Moolenaara42d9452019-06-15 21:46:30 +0200907func ShowDialog(key, result)
908 let s:cb_res = 999
909 let winid = popup_dialog('do you want to quit (Yes/no)?', {
910 \ 'filter': 'popup_filter_yesno',
911 \ 'callback': 'QuitCallback',
912 \ })
913 redraw
914 call feedkeys(a:key, "xt")
915 call assert_equal(winid, s:cb_winid)
916 call assert_equal(a:result, s:cb_res)
917endfunc
918
919func Test_popup_dialog()
920 func QuitCallback(id, res)
921 let s:cb_winid = a:id
922 let s:cb_res = a:res
923 endfunc
924
925 let winid = ShowDialog("y", 1)
926 let winid = ShowDialog("Y", 1)
927 let winid = ShowDialog("n", 0)
928 let winid = ShowDialog("N", 0)
929 let winid = ShowDialog("x", 0)
930 let winid = ShowDialog("X", 0)
931 let winid = ShowDialog("\<Esc>", 0)
932 let winid = ShowDialog("\<C-C>", -1)
933
934 delfunc QuitCallback
935endfunc
936
Bram Moolenaara730e552019-06-16 19:05:31 +0200937func ShowMenu(key, result)
938 let s:cb_res = 999
939 let winid = popup_menu(['one', 'two', 'something else'], {
940 \ 'callback': 'QuitCallback',
941 \ })
942 redraw
943 call feedkeys(a:key, "xt")
944 call assert_equal(winid, s:cb_winid)
945 call assert_equal(a:result, s:cb_res)
946endfunc
947
948func Test_popup_menu()
949 func QuitCallback(id, res)
950 let s:cb_winid = a:id
951 let s:cb_res = a:res
952 endfunc
953
954 let winid = ShowMenu(" ", 1)
955 let winid = ShowMenu("j \<CR>", 2)
956 let winid = ShowMenu("JjK \<CR>", 2)
957 let winid = ShowMenu("jjjjjj ", 3)
958 let winid = ShowMenu("kkk ", 1)
959 let winid = ShowMenu("x", -1)
960 let winid = ShowMenu("X", -1)
961 let winid = ShowMenu("\<Esc>", -1)
962 let winid = ShowMenu("\<C-C>", -1)
963
964 delfunc QuitCallback
965endfunc
966
967func Test_popup_menu_screenshot()
968 if !CanRunVimInTerminal()
969 throw 'Skipped: cannot make screendumps'
970 endif
971
972 let lines =<< trim END
973 call setline(1, range(1, 20))
974 hi PopupSelected ctermbg=lightblue
Bram Moolenaareb2310d2019-06-16 20:09:10 +0200975 call popup_menu(['one', 'two', 'another'], {'callback': 'MenuDone', 'title': ' make a choice from the list '})
Bram Moolenaara730e552019-06-16 19:05:31 +0200976 func MenuDone(id, res)
977 echomsg "selected " .. a:res
978 endfunc
979 END
980 call writefile(lines, 'XtestPopupMenu')
981 let buf = RunVimInTerminal('-S XtestPopupMenu', {'rows': 10})
982 call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {})
983
984 call term_sendkeys(buf, "jj")
985 call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {})
986
987 call term_sendkeys(buf, " ")
988 call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {})
989
990 " clean up
991 call StopVimInTerminal(buf)
992 call delete('XtestPopupMenu')
993endfunc
994
Bram Moolenaareb2310d2019-06-16 20:09:10 +0200995func Test_popup_title()
996 if !CanRunVimInTerminal()
997 throw 'Skipped: cannot make screendumps'
998 endif
999
1000 " Create a popup without title or border, a line of padding will be added to
1001 " put the title on.
1002 let lines =<< trim END
1003 call setline(1, range(1, 20))
1004 call popup_create(['one', 'two', 'another'], {'title': 'Title String'})
1005 END
1006 call writefile(lines, 'XtestPopupTitle')
1007 let buf = RunVimInTerminal('-S XtestPopupTitle', {'rows': 10})
1008 call VerifyScreenDump(buf, 'Test_popupwin_title', {})
1009
1010 " clean up
1011 call StopVimInTerminal(buf)
1012 call delete('XtestPopupTitle')
Bram Moolenaarae943152019-06-16 22:54:14 +02001013
1014 let winid = popup_create('something', {'title': 'Some Title'})
1015 call assert_equal('Some Title', popup_getoptions(winid).title)
1016 call popup_setoptions(winid, {'title': 'Another Title'})
1017 call assert_equal('Another Title', popup_getoptions(winid).title)
1018
1019 call popup_clear()
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001020endfunc
1021
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001022func Test_popup_close_callback()
1023 func PopupDone(id, result)
1024 let g:result = a:result
1025 endfunc
1026 let winid = popup_create('something', {'callback': 'PopupDone'})
1027 redraw
1028 call popup_close(winid, 'done')
1029 call assert_equal('done', g:result)
1030endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001031
1032func Test_popup_empty()
1033 let winid = popup_create('', {'padding': [2,2,2,2]})
1034 redraw
1035 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001036 call assert_equal(5, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001037 call assert_equal(5, pos.height)
1038
1039 let winid = popup_create([], {'border': []})
1040 redraw
1041 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001042 call assert_equal(3, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001043 call assert_equal(3, pos.height)
1044endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +02001045
1046func Test_popup_never_behind()
1047 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +02001048 throw 'Skipped: cannot make screendumps'
Bram Moolenaar988c4332019-06-02 14:12:11 +02001049 endif
1050 " +-----------------------------+
1051 " | | |
1052 " | | |
1053 " | | |
1054 " | line1 |
1055 " |------------line2------------|
1056 " | line3 |
1057 " | line4 |
1058 " | |
1059 " | |
1060 " +-----------------------------+
1061 let lines =<< trim END
1062 only
1063 split
1064 vsplit
1065 let info_window1 = getwininfo()[0]
1066 let line = info_window1['height']
1067 let col = info_window1['width']
1068 call popup_create(['line1', 'line2', 'line3', 'line4'], {
1069 \ 'line' : line,
1070 \ 'col' : col,
1071 \ })
1072 END
1073 call writefile(lines, 'XtestPopupBehind')
1074 let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10})
1075 call term_sendkeys(buf, "\<C-W>w")
1076 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
1077
1078 " clean up
1079 call StopVimInTerminal(buf)
1080 call delete('XtestPopupBehind')
1081endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001082
1083func s:VerifyPosition( p, msg, line, col, width, height )
1084 call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' )
1085 call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' )
1086 call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' )
1087 call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' )
1088endfunc
1089
1090func Test_popup_position_adjust()
1091 " Anything placed past 2 cells from of the right of the screen is moved to the
1092 " left.
1093 "
1094 " When wrapping is disabled, we also shift to the left to display on the
1095 " screen, unless fixed is set.
1096
1097 " Entries for cases which don't vary based on wrapping.
1098 " Format is per tests described below
1099 let both_wrap_tests = [
1100 \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ],
1101 \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ],
1102 \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ],
1103 \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ],
1104 \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ],
1105 \
1106 \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ],
1107 \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ],
1108 \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ],
1109 \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ],
1110 \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ],
1111 \
1112 \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ],
1113 \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
1114 \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
1115 \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
1116 \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ],
1117 \ ]
1118
1119 " these test groups are dicts with:
1120 " - comment: something to identify the group of tests by
1121 " - options: dict of options to merge with the row/col in tests
1122 " - tests: list of cases. Each one is a list with elements:
1123 " - text
1124 " - row
1125 " - col
1126 " - expected row
1127 " - expected col
1128 " - expected width
1129 " - expected height
1130 let tests = [
1131 \ {
1132 \ 'comment': 'left-aligned with wrapping',
1133 \ 'options': {
1134 \ 'wrap': 1,
1135 \ 'pos': 'botleft',
1136 \ },
1137 \ 'tests': both_wrap_tests + [
1138 \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ],
1139 \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ],
1140 \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ],
1141 \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ],
1142 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1143 \ ],
1144 \ },
1145 \ {
1146 \ 'comment': 'left aligned without wrapping',
1147 \ 'options': {
1148 \ 'wrap': 0,
1149 \ 'pos': 'botleft',
1150 \ },
1151 \ 'tests': both_wrap_tests + [
1152 \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ],
1153 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ],
1154 \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ],
1155 \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ],
1156 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1157 \ ],
1158 \ },
1159 \ {
1160 \ 'comment': 'left aligned with fixed position',
1161 \ 'options': {
1162 \ 'wrap': 0,
1163 \ 'fixed': 1,
1164 \ 'pos': 'botleft',
1165 \ },
1166 \ 'tests': both_wrap_tests + [
1167 \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ],
1168 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
1169 \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
1170 \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
1171 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1172 \ ],
1173 \ },
1174 \ ]
1175
1176 for test_group in tests
1177 for test in test_group.tests
1178 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
1179 let options = {
1180 \ 'line': line,
1181 \ 'col': col,
1182 \ }
1183 call extend( options, test_group.options )
1184
1185 let p = popup_create( text, options )
1186
1187 let msg = string( extend( options, { 'text': text } ) )
1188 call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height )
1189 call popup_close( p )
1190 endfor
1191 endfor
1192
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001193 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001194 %bwipe!
1195endfunc
1196
Bram Moolenaar3397f742019-06-02 18:40:06 +02001197func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001198 " width of screen
1199 let X = join(map(range(&columns), {->'X'}), '')
1200
1201 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
1202 call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 )
1203
1204 redraw
1205 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1206 call assert_equal(X, line)
1207
1208 call popup_close( p )
1209 redraw
1210
1211 " Same if placed on the right hand side
1212 let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } )
1213 call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 )
1214
1215 redraw
1216 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1217 call assert_equal(X, line)
1218
1219 call popup_close( p )
1220 redraw
1221
1222 " Extend so > window width
1223 let X .= 'x'
1224
1225 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
1226 call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 )
1227
1228 redraw
1229 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1230 call assert_equal(X[ : -2 ], line)
1231
1232 call popup_close( p )
1233 redraw
1234
1235 " Shifted then truncated (the x is not visible)
1236 let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } )
1237 call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 )
1238
1239 redraw
1240 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1241 call assert_equal(X[ : -2 ], line)
1242
1243 call popup_close( p )
1244 redraw
1245
1246 " Not shifted, just truncated
1247 let p = popup_create( X,
1248 \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } )
1249 call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
1250
1251 redraw
1252 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1253 let e_line = ' ' . X[ 1 : -2 ]
1254 call assert_equal(e_line, line)
1255
1256 call popup_close( p )
1257 redraw
1258
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001259 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001260 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001261endfunc
1262
1263func Test_popup_moved()
1264 new
1265 call test_override('char_avail', 1)
1266 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1267
1268 exe "normal gg0/word\<CR>"
1269 let winid = popup_atcursor('text', {'moved': 'any'})
1270 redraw
1271 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001272 call assert_equal([4, 4], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001273 " trigger the check for last_cursormoved by going into insert mode
1274 call feedkeys("li\<Esc>", 'xt')
1275 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001276 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001277
1278 exe "normal gg0/word\<CR>"
1279 let winid = popup_atcursor('text', {'moved': 'word'})
1280 redraw
1281 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001282 call assert_equal([4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001283 call feedkeys("hi\<Esc>", 'xt')
1284 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001285 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001286
1287 exe "normal gg0/word\<CR>"
1288 let winid = popup_atcursor('text', {'moved': 'word'})
1289 redraw
1290 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001291 call assert_equal([4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001292 call feedkeys("li\<Esc>", 'xt')
1293 call assert_equal(1, popup_getpos(winid).visible)
1294 call feedkeys("ei\<Esc>", 'xt')
1295 call assert_equal(1, popup_getpos(winid).visible)
1296 call feedkeys("eli\<Esc>", 'xt')
1297 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001298 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001299
Bram Moolenaar17627312019-06-02 19:53:44 +02001300 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001301 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001302 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001303 redraw
1304 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001305 call assert_equal([2, 15], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001306 call feedkeys("eli\<Esc>", 'xt')
1307 call assert_equal(1, popup_getpos(winid).visible)
1308 call feedkeys("wi\<Esc>", 'xt')
1309 call assert_equal(1, popup_getpos(winid).visible)
1310 call feedkeys("Eli\<Esc>", 'xt')
1311 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001312 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001313
1314 exe "normal gg0/word\<CR>"
1315 let winid = popup_atcursor('text', {'moved': [5, 10]})
1316 redraw
1317 call assert_equal(1, popup_getpos(winid).visible)
1318 call feedkeys("eli\<Esc>", 'xt')
1319 call feedkeys("ei\<Esc>", 'xt')
1320 call assert_equal(1, popup_getpos(winid).visible)
1321 call feedkeys("eli\<Esc>", 'xt')
1322 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001323 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001324
1325 bwipe!
1326 call test_override('ALL', 0)
1327endfunc
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001328
1329func Test_notifications()
1330 if !has('timers')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02001331 throw 'Skipped: timer feature not supported'
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001332 endif
1333 if !CanRunVimInTerminal()
1334 throw 'Skipped: cannot make screendumps'
1335 endif
1336
1337 call writefile([
1338 \ "call setline(1, range(1, 20))",
1339 \ "hi Notification ctermbg=lightblue",
1340 \ "call popup_notification('first notification', {})",
1341 \], 'XtestNotifications')
1342 let buf = RunVimInTerminal('-S XtestNotifications', {'rows': 10})
1343 call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {})
1344
1345 " second one goes below the first one
Bram Moolenaardfa97f22019-06-15 14:31:55 +02001346 call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>")
1347 call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>")
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001348 call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {})
1349
1350
1351 " clean up
1352 call StopVimInTerminal(buf)
1353 call delete('XtestNotifications')
1354endfunc
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001355
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001356func Test_popup_settext()
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001357 if !CanRunVimInTerminal()
1358 throw 'Skipped: cannot make screendumps'
1359 endif
1360
1361 let lines =<< trim END
1362 let opts = {'wrap': 0}
1363 let p = popup_create('test', opts)
1364 call popup_settext(p, 'this is a text')
1365 END
1366
1367 call writefile( lines, 'XtestPopupSetText' )
1368 let buf = RunVimInTerminal('-S XtestPopupSetText', {'rows': 10})
1369 call VerifyScreenDump(buf, 'Test_popup_settext_01', {})
1370
1371 " Setting to empty string clears it
1372 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>")
1373 call VerifyScreenDump(buf, 'Test_popup_settext_02', {})
1374
1375 " Setting a list
1376 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1377 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1378
1379 " Shrinking with a list
1380 call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>")
1381 call VerifyScreenDump(buf, 'Test_popup_settext_04', {})
1382
1383 " Growing with a list
1384 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1385 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1386
1387 " Empty list clears
1388 call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>")
1389 call VerifyScreenDump(buf, 'Test_popup_settext_05', {})
1390
1391 " Dicts
1392 call term_sendkeys(buf, ":call popup_settext(p, [{'text': 'aaaa'}, {'text': 'bbbb'}, {'text': 'cccc'}])\<CR>")
1393 call VerifyScreenDump(buf, 'Test_popup_settext_06', {})
1394
1395 " clean up
1396 call StopVimInTerminal(buf)
1397 call delete('XtestPopupSetText')
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001398endfunc
1399
1400func Test_popup_hidden()
1401 new
1402
1403 let winid = popup_atcursor('text', {'hidden': 1})
1404 redraw
1405 call assert_equal(0, popup_getpos(winid).visible)
1406 call popup_close(winid)
1407
1408 let winid = popup_create('text', {'hidden': 1})
1409 redraw
1410 call assert_equal(0, popup_getpos(winid).visible)
1411 call popup_close(winid)
1412
1413 func QuitCallback(id, res)
1414 let s:cb_winid = a:id
1415 let s:cb_res = a:res
1416 endfunc
1417 let winid = popup_dialog('make a choice', {'hidden': 1,
1418 \ 'filter': 'popup_filter_yesno',
1419 \ 'callback': 'QuitCallback',
1420 \ })
1421 redraw
1422 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001423 call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter)
1424 call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback)
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001425 exe "normal anot used by filter\<Esc>"
1426 call assert_equal('not used by filter', getline(1))
1427
1428 call popup_show(winid)
1429 call feedkeys('y', "xt")
1430 call assert_equal(1, s:cb_res)
1431
1432 bwipe!
1433 delfunc QuitCallback
1434endfunc
Bram Moolenaarae943152019-06-16 22:54:14 +02001435
1436" Test options not checked elsewhere
1437func Test_set_get_options()
1438 let winid = popup_create('some text', {'highlight': 'Beautiful'})
1439 let options = popup_getoptions(winid)
1440 call assert_equal(1, options.wrap)
1441 call assert_equal(0, options.drag)
1442 call assert_equal('Beautiful', options.highlight)
1443
1444 call popup_setoptions(winid, {'wrap': 0, 'drag': 1, 'highlight': 'Another'})
1445 let options = popup_getoptions(winid)
1446 call assert_equal(0, options.wrap)
1447 call assert_equal(1, options.drag)
1448 call assert_equal('Another', options.highlight)
1449
1450 call popup_close(winid)
1451endfunc