blob: 456e0db1e6b0a4835502a0aebf143ed41a8774d9 [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
Bram Moolenaare7eb9272019-06-24 00:58:07 +020012 let lines =<< trim END
13 call setline(1, range(1, 100))
14 hi PopupColor1 ctermbg=lightblue
15 hi PopupColor2 ctermbg=lightcyan
16 hi Comment ctermfg=red
17 call prop_type_add('comment', {'highlight': 'Comment'})
18 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})
20 call setwinvar(winid2, '&wincolor', 'PopupColor2')
21 END
22 call writefile(lines, 'XtestPopup')
Bram Moolenaar4d784b22019-05-25 19:51:39 +020023 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 Moolenaar202d9822019-06-11 21:56:30 +020044 " set 'columns' to a small value, size must be recomputed
45 call term_sendkeys(buf, ":let cols = &columns\<CR>")
46 call term_sendkeys(buf, ":set columns=12\<CR>")
47 call VerifyScreenDump(buf, 'Test_popupwin_04a', {})
48 call term_sendkeys(buf, ":let &columns = cols\<CR>")
49
Bram Moolenaar17146962019-05-30 00:12:11 +020050 " resize popup, show empty line at bottom
Bram Moolenaar60cdb302019-05-27 21:54:10 +020051 call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>")
52 call term_sendkeys(buf, ":redraw\<CR>")
53 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
54
Bram Moolenaar17146962019-05-30 00:12:11 +020055 " show not fitting line at bottom
56 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
57 call term_sendkeys(buf, ":redraw\<CR>")
58 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
59
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020060 " move popup over ruler
61 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
62 call term_sendkeys(buf, ":call popup_move(popupwin, {'line': 7, 'col': 55})\<CR>")
63 call VerifyScreenDump(buf, 'Test_popupwin_07', {})
64
65 " clear all popups after moving the cursor a bit, so that ruler is updated
66 call term_sendkeys(buf, "axxx\<Esc>")
67 call term_wait(buf)
68 call term_sendkeys(buf, "0")
69 call term_wait(buf)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020070 call term_sendkeys(buf, ":call popup_clear()\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020071 call VerifyScreenDump(buf, 'Test_popupwin_08', {})
72
Bram Moolenaar4d784b22019-05-25 19:51:39 +020073 " clean up
74 call StopVimInTerminal(buf)
75 call delete('XtestPopup')
76endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020077
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020078func Test_popup_with_border_and_padding()
79 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +020080 throw 'Skipped: cannot make screendumps'
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020081 endif
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020082
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020083 for iter in range(0, 1)
Bram Moolenaare7eb9272019-06-24 00:58:07 +020084 let lines =<< trim END
85 call setline(1, range(1, 100))
86 call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})
87 call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})
88 call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})
89 call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})
90 call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})
91 call popup_create('wrapped longer text', {'line': 8, 'col': 55, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})
92 call popup_create('right aligned text', {'line': 11, 'col': 56, 'wrap': 0, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})
93 END
94 call insert(lines, iter == 1 ? '' : 'set enc=latin1')
95 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020096 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15})
97 call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
98
99 call StopVimInTerminal(buf)
100 call delete('XtestPopupBorder')
101 endfor
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200102
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200103 let lines =<< trim END
104 call setline(1, range(1, 100))
105 hi BlueColor ctermbg=lightblue
106 hi TopColor ctermbg=253
107 hi RightColor ctermbg=245
108 hi BottomColor ctermbg=240
109 hi LeftColor ctermbg=248
110 call popup_create('hello border', {'line': 2, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor']})
111 call popup_create(['hello border', 'and more'], {'line': 2, 'col': 23, 'border': [], 'borderhighlight': ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})
112 call popup_create(['hello border', 'lines only'], {'line': 2, 'col': 43, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x']})
113 call popup_create(['hello border', 'with corners'], {'line': 2, 'col': 60, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x', '#']})
114 let winid = popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})
115 call popup_create(['hello border', 'just blanks'], {'line': 7, 'col': 23, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': [' ']})
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200116 func MultiByte()
117 call popup_create(['hello'], {'line': 8, 'col': 43, 'border': [], 'borderchars': ['─', '│', '─', '│', '┌', '┐', '┘', '└']})
118 endfunc
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200119 END
120 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar790498b2019-06-01 22:15:29 +0200121 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 12})
122 call VerifyScreenDump(buf, 'Test_popupwin_22', {})
123
Bram Moolenaarad24a712019-06-17 20:05:45 +0200124 " check that changing borderchars triggers a redraw
125 call term_sendkeys(buf, ":call popup_setoptions(winid, {'borderchars': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']})\<CR>")
126 call VerifyScreenDump(buf, 'Test_popupwin_23', {})
127
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200128 " check multi-byte border only with 'ambiwidth' single
129 if &ambiwidth == 'single'
130 call term_sendkeys(buf, ":call MultiByte()\<CR>")
131 call VerifyScreenDump(buf, 'Test_popupwin_24', {})
132 endif
133
Bram Moolenaar790498b2019-06-01 22:15:29 +0200134 call StopVimInTerminal(buf)
135 call delete('XtestPopupBorder')
136
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200137 let with_border_or_padding = {
138 \ 'line': 2,
139 \ 'core_line': 3,
140 \ 'col': 3,
141 \ 'core_col': 4,
142 \ 'width': 14,
143 \ 'core_width': 12,
144 \ 'height': 3,
145 \ 'core_height': 1,
Bram Moolenaar53a95d62019-06-26 03:54:08 +0200146 \ 'firstline': 1,
Bram Moolenaar6c6a6032019-06-25 05:33:36 +0200147 \ 'scrollbar': 0,
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200148 \ 'visible': 1}
149 let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
150 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200151 let options = popup_getoptions(winid)
152 call assert_equal([], options.border)
153 call assert_false(has_key(options, "padding"))
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200154
Bram Moolenaarae943152019-06-16 22:54:14 +0200155 let winid = popup_create('hello padding', {'line': 2, 'col': 3, 'padding': []})
156 let with_border_or_padding.width = 15
157 let with_border_or_padding.core_width = 13
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200158 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200159 let options = popup_getoptions(winid)
160 call assert_false(has_key(options, "border"))
161 call assert_equal([], options.padding)
162
163 call popup_setoptions(winid, {
164 \ 'padding': [1, 2, 3, 4],
165 \ 'border': [4, 0, 7, 8],
166 \ 'borderhighlight': ['Top', 'Right', 'Bottom', 'Left'],
167 \ 'borderchars': ['1', '^', '2', '>', '3', 'v', '4', '<'],
168 \ })
169 let options = popup_getoptions(winid)
170 call assert_equal([1, 0, 1, 1], options.border)
171 call assert_equal([1, 2, 3, 4], options.padding)
172 call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
173 call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200174
175 let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []})
176 call assert_equal({
177 \ 'line': 3,
178 \ 'core_line': 5,
179 \ 'col': 8,
180 \ 'core_col': 10,
181 \ 'width': 14,
182 \ 'core_width': 10,
183 \ 'height': 5,
Bram Moolenaar6c6a6032019-06-25 05:33:36 +0200184 \ 'scrollbar': 0,
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200185 \ 'core_height': 1,
Bram Moolenaar53a95d62019-06-26 03:54:08 +0200186 \ 'firstline': 1,
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200187 \ 'visible': 1}, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200188
189 call popup_clear()
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200190endfunc
191
Bram Moolenaarb4230122019-05-30 18:40:53 +0200192func Test_popup_with_syntax_win_execute()
193 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200194 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200195 endif
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200196 let lines =<< trim END
197 call setline(1, range(1, 100))
198 hi PopupColor ctermbg=lightblue
199 let winid = popup_create([
200 \ '#include <stdio.h>',
201 \ 'int main(void)',
202 \ '{',
203 \ ' printf(123);',
204 \ '}',
205 \], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})
206 call win_execute(winid, 'set syntax=cpp')
207 END
208 call writefile(lines, 'XtestPopup')
Bram Moolenaarb4230122019-05-30 18:40:53 +0200209 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
210 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
211
212 " clean up
213 call StopVimInTerminal(buf)
214 call delete('XtestPopup')
215endfunc
216
217func Test_popup_with_syntax_setbufvar()
218 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200219 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200220 endif
Bram Moolenaar402502d2019-05-30 22:07:36 +0200221 let lines =<< trim END
222 call setline(1, range(1, 100))
223 hi PopupColor ctermbg=lightgrey
224 let winid = popup_create([
225 \ '#include <stdio.h>',
226 \ 'int main(void)',
227 \ '{',
Bram Moolenaare089c3f2019-07-09 20:25:25 +0200228 \ "\tprintf(567);",
Bram Moolenaar402502d2019-05-30 22:07:36 +0200229 \ '}',
230 \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})
231 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
232 END
233 call writefile(lines, 'XtestPopup')
Bram Moolenaarb4230122019-05-30 18:40:53 +0200234 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
235 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
236
237 " clean up
238 call StopVimInTerminal(buf)
239 call delete('XtestPopup')
240endfunc
241
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200242func Test_popup_with_matches()
243 if !CanRunVimInTerminal()
244 throw 'Skipped: cannot make screendumps'
245 endif
246 let lines =<< trim END
247 call setline(1, ['111 222 333', '444 555 666'])
248 let winid = popup_create([
249 \ '111 222 333',
250 \ '444 555 666',
251 \], {'line': 3, 'col': 10, 'border': []})
252 set hlsearch
253 /666
254 call matchadd('ErrorMsg', '111')
255 call matchadd('ErrorMsg', '444')
256 call win_execute(winid, "call matchadd('ErrorMsg', '111')")
257 call win_execute(winid, "call matchadd('ErrorMsg', '555')")
258 END
259 call writefile(lines, 'XtestPopupMatches')
260 let buf = RunVimInTerminal('-S XtestPopupMatches', {'rows': 10})
261 call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
262
263 " clean up
264 call StopVimInTerminal(buf)
265 call delete('XtestPopupMatches')
266endfunc
267
Bram Moolenaar399d8982019-06-02 15:34:29 +0200268func Test_popup_all_corners()
269 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200270 throw 'Skipped: cannot make screendumps'
Bram Moolenaar399d8982019-06-02 15:34:29 +0200271 endif
272 let lines =<< trim END
273 call setline(1, repeat([repeat('-', 60)], 15))
274 set so=0
275 normal 2G3|r#
276 let winid1 = popup_create(['first', 'second'], {
277 \ 'line': 'cursor+1',
278 \ 'col': 'cursor',
279 \ 'pos': 'topleft',
280 \ 'border': [],
281 \ 'padding': [],
282 \ })
283 normal 25|r@
284 let winid1 = popup_create(['First', 'SeconD'], {
285 \ 'line': 'cursor+1',
286 \ 'col': 'cursor',
287 \ 'pos': 'topright',
288 \ 'border': [],
289 \ 'padding': [],
290 \ })
291 normal 9G29|r%
292 let winid1 = popup_create(['fiRSt', 'seCOnd'], {
293 \ 'line': 'cursor-1',
294 \ 'col': 'cursor',
295 \ 'pos': 'botleft',
296 \ 'border': [],
297 \ 'padding': [],
298 \ })
299 normal 51|r&
300 let winid1 = popup_create(['FIrsT', 'SEcoND'], {
301 \ 'line': 'cursor-1',
302 \ 'col': 'cursor',
303 \ 'pos': 'botright',
304 \ 'border': [],
305 \ 'padding': [],
306 \ })
307 END
308 call writefile(lines, 'XtestPopupCorners')
309 let buf = RunVimInTerminal('-S XtestPopupCorners', {'rows': 12})
310 call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
311
312 " clean up
313 call StopVimInTerminal(buf)
314 call delete('XtestPopupCorners')
315endfunc
316
Bram Moolenaar8d241042019-06-12 23:40:01 +0200317func Test_popup_firstline()
318 if !CanRunVimInTerminal()
319 throw 'Skipped: cannot make screendumps'
320 endif
321 let lines =<< trim END
322 call setline(1, range(1, 20))
323 call popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], {
324 \ 'maxheight': 4,
325 \ 'firstline': 3,
326 \ })
327 END
328 call writefile(lines, 'XtestPopupFirstline')
329 let buf = RunVimInTerminal('-S XtestPopupFirstline', {'rows': 10})
330 call VerifyScreenDump(buf, 'Test_popupwin_firstline', {})
331
332 " clean up
333 call StopVimInTerminal(buf)
334 call delete('XtestPopupFirstline')
Bram Moolenaarae943152019-06-16 22:54:14 +0200335
336 let winid = popup_create(['1111', '222222', '33333', '44444'], {
337 \ 'maxheight': 2,
338 \ 'firstline': 3,
339 \ })
340 call assert_equal(3, popup_getoptions(winid).firstline)
341 call popup_setoptions(winid, {'firstline': 1})
342 call assert_equal(1, popup_getoptions(winid).firstline)
343
344 call popup_close(winid)
Bram Moolenaar8d241042019-06-12 23:40:01 +0200345endfunc
346
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200347func Test_popup_drag()
348 if !CanRunVimInTerminal()
349 throw 'Skipped: cannot make screendumps'
350 endif
351 " create a popup that covers the command line
352 let lines =<< trim END
353 call setline(1, range(1, 20))
354 let winid = popup_create(['1111', '222222', '33333'], {
355 \ 'drag': 1,
356 \ 'border': [],
357 \ 'line': &lines - 4,
358 \ })
359 func Dragit()
360 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
361 endfunc
362 map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR>
363 map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2)<CR>
364 END
365 call writefile(lines, 'XtestPopupDrag')
366 let buf = RunVimInTerminal('-S XtestPopupDrag', {'rows': 10})
367 call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {})
368
369 call term_sendkeys(buf, ":call Dragit()\<CR>")
370 call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {})
371
372 " clean up
373 call StopVimInTerminal(buf)
374 call delete('XtestPopupDrag')
375endfunc
376
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200377func Test_popup_close_with_mouse()
378 if !CanRunVimInTerminal()
379 throw 'Skipped: cannot make screendumps'
380 endif
381 let lines =<< trim END
382 call setline(1, range(1, 20))
383 " With border, can click on X
384 let winid = popup_create('foobar', {
385 \ 'close': 'button',
386 \ 'border': [],
387 \ 'line': 1,
388 \ 'col': 1,
389 \ })
390 func CloseMsg(id, result)
391 echomsg 'Popup closed with ' .. a:result
392 endfunc
393 let winid = popup_create('notification', {
394 \ 'close': 'click',
395 \ 'line': 3,
396 \ 'col': 15,
397 \ 'callback': 'CloseMsg',
398 \ })
399 let winid = popup_create('no border here', {
400 \ 'close': 'button',
401 \ 'line': 5,
402 \ 'col': 3,
403 \ })
404 let winid = popup_create('only padding', {
405 \ 'close': 'button',
406 \ 'padding': [],
407 \ 'line': 5,
408 \ 'col': 23,
409 \ })
410 func CloseWithX()
411 call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
412 endfunc
413 map <silent> <F3> :call test_setmouse(1, len('foobar') + 2)<CR>
414 func CloseWithClick()
415 call feedkeys("\<F4>\<LeftMouse>\<LeftRelease>", "xt")
416 endfunc
417 map <silent> <F4> :call test_setmouse(3, 17)<CR>
418 END
419 call writefile(lines, 'XtestPopupClose')
420 let buf = RunVimInTerminal('-S XtestPopupClose', {'rows': 10})
421 call VerifyScreenDump(buf, 'Test_popupwin_close_01', {})
422
423 call term_sendkeys(buf, ":call CloseWithX()\<CR>")
424 call VerifyScreenDump(buf, 'Test_popupwin_close_02', {})
425
426 call term_sendkeys(buf, ":call CloseWithClick()\<CR>")
427 call VerifyScreenDump(buf, 'Test_popupwin_close_03', {})
428
429 " clean up
430 call StopVimInTerminal(buf)
431 call delete('XtestPopupClose')
432endfunction
433
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200434func Test_popup_with_mask()
435 if !CanRunVimInTerminal()
436 throw 'Skipped: cannot make screendumps'
437 endif
438 let lines =<< trim END
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200439 call setline(1, repeat([join(range(1, 42), '')], 13))
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200440 hi PopupColor ctermbg=lightgrey
441 let winid = popup_create([
442 \ 'some text',
443 \ 'another line',
444 \], {
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200445 \ 'line': 1,
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200446 \ 'col': 10,
Bram Moolenaard529ba52019-07-02 23:13:53 +0200447 \ 'wrap': 0,
448 \ 'fixed': 1,
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200449 \ 'zindex': 90,
450 \ 'padding': [],
451 \ 'highlight': 'PopupColor',
452 \ 'mask': [[1,1,1,1], [-5,-1,4,4], [7,9,2,3], [2,4,3,3]]})
453 call popup_create([
454 \ 'xxxxxxxxx',
455 \ 'yyyyyyyyy',
456 \], {
457 \ 'line': 3,
458 \ 'col': 18,
459 \ 'zindex': 20})
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200460 let winidb = popup_create([
461 \ 'just one line',
462 \], {
463 \ 'line': 7,
464 \ 'col': 10,
465 \ 'wrap': 0,
466 \ 'fixed': 1,
467 \ 'close': 'button',
468 \ 'zindex': 90,
469 \ 'padding': [],
470 \ 'border': [],
471 \ 'mask': [[1,2,1,1], [-5,-1,4,4], [7,9,2,3], [3,5,5,5],[-7,-4,5,5]]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200472 END
473 call writefile(lines, 'XtestPopupMask')
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200474 let buf = RunVimInTerminal('-S XtestPopupMask', {'rows': 13})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200475 call VerifyScreenDump(buf, 'Test_popupwin_mask_1', {})
476
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200477 call term_sendkeys(buf, ":call popup_move(winid, {'col': 11, 'line': 2})\<CR>")
478 call term_sendkeys(buf, ":call popup_move(winidb, {'col': 12})\<CR>")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200479 call VerifyScreenDump(buf, 'Test_popupwin_mask_2', {})
480
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200481 call term_sendkeys(buf, ":call popup_move(winid, {'col': 65, 'line': 2})\<CR>")
482 call term_sendkeys(buf, ":call popup_move(winidb, {'col': 63})\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200483 call VerifyScreenDump(buf, 'Test_popupwin_mask_3', {})
484
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200485 call term_sendkeys(buf, ":call popup_move(winid, {'pos': 'topright', 'col': 12, 'line': 2})\<CR>")
486 call term_sendkeys(buf, ":call popup_move(winidb, {'pos': 'topright', 'col': 12})\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200487 call VerifyScreenDump(buf, 'Test_popupwin_mask_4', {})
488
Bram Moolenaarb4207472019-07-12 16:05:45 +0200489 call term_sendkeys(buf, ":call popup_move(winid, {'pos': 'topright', 'col': 12, 'line': 11})\<CR>")
490 call term_sendkeys(buf, ":call popup_move(winidb, {'pos': 'topleft', 'col': 42, 'line': 11})\<CR>")
491 call VerifyScreenDump(buf, 'Test_popupwin_mask_5', {})
492
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200493 " clean up
494 call StopVimInTerminal(buf)
495 call delete('XtestPopupMask')
496endfunc
497
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200498func Test_popup_select()
499 if !CanRunVimInTerminal()
500 throw 'Skipped: cannot make screendumps'
501 endif
Bram Moolenaar650a6372019-06-15 00:29:33 +0200502 if !has('clipboard')
503 throw 'Skipped: clipboard feature missing'
504 endif
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200505 " create a popup with some text to be selected
506 let lines =<< trim END
Bram Moolenaar1755ec42019-06-15 13:13:54 +0200507 set clipboard=autoselect
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200508 call setline(1, range(1, 20))
509 let winid = popup_create(['the word', 'some more', 'several words here'], {
510 \ 'drag': 1,
511 \ 'border': [],
512 \ 'line': 3,
513 \ 'col': 10,
514 \ })
515 func Select1()
516 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
517 endfunc
518 map <silent> <F3> :call test_setmouse(4, 15)<CR>
519 map <silent> <F4> :call test_setmouse(6, 23)<CR>
520 END
521 call writefile(lines, 'XtestPopupSelect')
522 let buf = RunVimInTerminal('-S XtestPopupSelect', {'rows': 10})
523 call term_sendkeys(buf, ":call Select1()\<CR>")
524 call VerifyScreenDump(buf, 'Test_popupwin_select_01', {})
525
526 call term_sendkeys(buf, ":call popup_close(winid)\<CR>")
527 call term_sendkeys(buf, "\"*p")
Bram Moolenaar8ccabf62019-07-12 18:12:51 +0200528 " clean the command line, sometimes it still shows a command
529 call term_sendkeys(buf, ":\<esc>")
530
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200531 call VerifyScreenDump(buf, 'Test_popupwin_select_02', {})
532
533 " clean up
534 call StopVimInTerminal(buf)
535 call delete('XtestPopupSelect')
536endfunc
537
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200538func Test_popup_in_tab()
539 " default popup is local to tab, not visible when in other tab
540 let winid = popup_create("text", {})
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200541 let bufnr = winbufnr(winid)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200542 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200543 call assert_equal(0, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200544 tabnew
545 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200546 call assert_equal(1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200547 quit
548 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200549
550 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200551 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200552 " buffer is gone now
553 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200554
555 " global popup is visible in any tab
Bram Moolenaarfc06cbb2019-06-15 14:14:31 +0200556 let winid = popup_create("text", {'tabpage': -1})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200557 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200558 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200559 tabnew
560 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200561 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200562 quit
563 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200564 call popup_clear()
Bram Moolenaara3fce622019-06-20 02:31:49 +0200565
566 " create popup in other tab
567 tabnew
568 let winid = popup_create("text", {'tabpage': 1})
569 call assert_equal(0, popup_getpos(winid).visible)
570 call assert_equal(1, popup_getoptions(winid).tabpage)
571 quit
572 call assert_equal(1, popup_getpos(winid).visible)
573 call assert_equal(0, popup_getoptions(winid).tabpage)
574 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200575endfunc
576
577func Test_popup_valid_arguments()
578 " Zero value is like the property wasn't there
579 let winid = popup_create("text", {"col": 0})
580 let pos = popup_getpos(winid)
581 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200582 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200583
584 " using cursor column has minimum value of 1
585 let winid = popup_create("text", {"col": 'cursor-100'})
586 let pos = popup_getpos(winid)
587 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200588 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200589
590 " center
591 let winid = popup_create("text", {"pos": 'center'})
592 let pos = popup_getpos(winid)
593 let around = (&columns - pos.width) / 2
594 call assert_inrange(around - 1, around + 1, pos.col)
595 let around = (&lines - pos.height) / 2
596 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200597 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200598endfunc
599
600func Test_popup_invalid_arguments()
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200601 call assert_fails('call popup_create(666, {})', 'E86:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200602 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200603 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200604 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200605
606 call assert_fails('call popup_create("text", {"col": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200607 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200608 call assert_fails('call popup_create("text", {"col": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200609 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200610 call assert_fails('call popup_create("text", {"col": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200611 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200612 call assert_fails('call popup_create("text", {"col": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200613 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200614
615 call assert_fails('call popup_create("text", {"line": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200616 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200617 call assert_fails('call popup_create("text", {"line": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200618 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200619 call assert_fails('call popup_create("text", {"line": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200620 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200621 call assert_fails('call popup_create("text", {"line": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200622 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200623
624 call assert_fails('call popup_create("text", {"pos": "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200625 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200626 call assert_fails('call popup_create("text", {"padding": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200627 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200628 call assert_fails('call popup_create("text", {"border": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200629 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200630 call assert_fails('call popup_create("text", {"borderhighlight": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200631 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200632 call assert_fails('call popup_create("text", {"borderchars": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200633 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200634
635 call assert_fails('call popup_create([{"text": "text"}, 666], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200636 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200637 call assert_fails('call popup_create([{"text": "text", "props": "none"}], {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200638 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200639 call assert_fails('call popup_create([{"text": "text", "props": ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200640 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200641endfunc
642
Bram Moolenaareea16992019-05-31 17:34:48 +0200643func Test_win_execute_closing_curwin()
644 split
645 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200646 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200647 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200648endfunc
649
650func Test_win_execute_not_allowed()
651 let winid = popup_create('some text', {})
652 call assert_fails('call win_execute(winid, "split")', 'E994:')
653 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
654 call assert_fails('call win_execute(winid, "close")', 'E994:')
655 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200656 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200657 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
658 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
659 call assert_fails('call win_execute(winid, "next")', 'E994:')
660 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
661 call assert_fails('call win_execute(winid, "buf")', 'E994:')
662 call assert_fails('call win_execute(winid, "edit")', 'E994:')
663 call assert_fails('call win_execute(winid, "enew")', 'E994:')
664 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
665 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
666 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
667 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200668 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200669endfunc
670
Bram Moolenaar402502d2019-05-30 22:07:36 +0200671func Test_popup_with_wrap()
672 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200673 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200674 endif
675 let lines =<< trim END
676 call setline(1, range(1, 100))
677 let winid = popup_create(
678 \ 'a long line that wont fit',
679 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
680 END
681 call writefile(lines, 'XtestPopup')
682 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
683 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
684
685 " clean up
686 call StopVimInTerminal(buf)
687 call delete('XtestPopup')
688endfunc
689
690func Test_popup_without_wrap()
691 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200692 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200693 endif
694 let lines =<< trim END
695 call setline(1, range(1, 100))
696 let winid = popup_create(
697 \ 'a long line that wont fit',
698 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
699 END
700 call writefile(lines, 'XtestPopup')
701 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
702 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
703
704 " clean up
705 call StopVimInTerminal(buf)
706 call delete('XtestPopup')
707endfunc
708
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200709func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200710 if !has('timers')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +0200711 throw 'Skipped: timer feature not supported'
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200712 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200713 topleft vnew
714 call setline(1, 'hello')
715
Bram Moolenaarb4f06282019-07-12 21:07:54 +0200716 let winid = popup_create('world', {
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200717 \ 'line': 1,
718 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200719 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200720 \ 'time': 500,
721 \})
722 redraw
723 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
724 call assert_equal('world', line)
725
Bram Moolenaarb4f06282019-07-12 21:07:54 +0200726 call assert_equal(winid, popup_locate(1, 1))
727 call assert_equal(winid, popup_locate(1, 20))
728 call assert_equal(0, popup_locate(1, 21))
729 call assert_equal(0, popup_locate(2, 1))
730
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200731 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200732 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200733 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
734 call assert_equal('hello', line)
735
736 call popup_create('on the command line', {
737 \ 'line': &lines,
738 \ 'col': 10,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200739 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200740 \ 'time': 500,
741 \})
742 redraw
743 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
744 call assert_match('.*on the command line.*', line)
745
746 sleep 700m
747 redraw
748 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
749 call assert_notmatch('.*on the command line.*', line)
750
751 bwipe!
752endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200753
754func Test_popup_hide()
755 topleft vnew
756 call setline(1, 'hello')
757
758 let winid = popup_create('world', {
759 \ 'line': 1,
760 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200761 \ 'minwidth': 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200762 \})
763 redraw
764 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
765 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200766 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200767 " buffer is still listed and active
768 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200769
770 call popup_hide(winid)
771 redraw
772 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
773 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200774 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200775 " buffer is still listed but hidden
776 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200777
778 call popup_show(winid)
779 redraw
780 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
781 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200782 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200783
784
785 call popup_close(winid)
786 redraw
787 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
788 call assert_equal('hello', line)
789
790 " error is given for existing non-popup window
791 call assert_fails('call popup_hide(win_getid())', 'E993:')
792
793 " no error non-existing window
794 call popup_hide(1234234)
795 call popup_show(41234234)
796
797 bwipe!
798endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200799
800func Test_popup_move()
801 topleft vnew
802 call setline(1, 'hello')
803
804 let winid = popup_create('world', {
805 \ 'line': 1,
806 \ 'col': 1,
807 \ 'minwidth': 20,
808 \})
809 redraw
810 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
811 call assert_equal('world ', line)
812
813 call popup_move(winid, {'line': 2, 'col': 2})
814 redraw
815 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
816 call assert_equal('hello ', line)
817 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
818 call assert_equal('~world', line)
819
820 call popup_move(winid, {'line': 1})
821 redraw
822 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
823 call assert_equal('hworld', line)
824
825 call popup_close(winid)
826
827 bwipe!
828endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200829
Bram Moolenaar402502d2019-05-30 22:07:36 +0200830func Test_popup_getpos()
Bram Moolenaarbc133542019-05-29 20:26:46 +0200831 let winid = popup_create('hello', {
832 \ 'line': 2,
833 \ 'col': 3,
834 \ 'minwidth': 10,
835 \ 'minheight': 11,
836 \})
837 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200838 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200839 call assert_equal(2, res.line)
840 call assert_equal(3, res.col)
841 call assert_equal(10, res.width)
842 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200843 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200844
845 call popup_close(winid)
846endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200847
848func Test_popup_width_longest()
849 let tests = [
850 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
851 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
852 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
853 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
854 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
855 \ ]
856
857 for test in tests
858 let winid = popup_create(test[0], {'line': 2, 'col': 3})
859 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200860 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200861 call assert_equal(test[1], position.width)
862 call popup_close(winid)
863 endfor
864endfunc
865
866func Test_popup_wraps()
867 let tests = [
868 \ ['nowrap', 6, 1],
869 \ ['a line that wraps once', 12, 2],
870 \ ['a line that wraps two times', 12, 3],
871 \ ]
872 for test in tests
873 let winid = popup_create(test[0],
874 \ {'line': 2, 'col': 3, 'maxwidth': 12})
875 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200876 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200877 call assert_equal(test[1], position.width)
878 call assert_equal(test[2], position.height)
879
880 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200881 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200882 endfor
883endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200884
885func Test_popup_getoptions()
886 let winid = popup_create('hello', {
887 \ 'line': 2,
888 \ 'col': 3,
889 \ 'minwidth': 10,
890 \ 'minheight': 11,
891 \ 'maxwidth': 20,
892 \ 'maxheight': 21,
893 \ 'zindex': 100,
894 \ 'time': 5000,
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200895 \ 'fixed': 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200896 \})
897 redraw
898 let res = popup_getoptions(winid)
899 call assert_equal(2, res.line)
900 call assert_equal(3, res.col)
901 call assert_equal(10, res.minwidth)
902 call assert_equal(11, res.minheight)
903 call assert_equal(20, res.maxwidth)
904 call assert_equal(21, res.maxheight)
905 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200906 call assert_equal(1, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200907 if has('timers')
908 call assert_equal(5000, res.time)
909 endif
910 call popup_close(winid)
911
912 let winid = popup_create('hello', {})
913 redraw
914 let res = popup_getoptions(winid)
915 call assert_equal(0, res.line)
916 call assert_equal(0, res.col)
917 call assert_equal(0, res.minwidth)
918 call assert_equal(0, res.minheight)
919 call assert_equal(0, res.maxwidth)
920 call assert_equal(0, res.maxheight)
921 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200922 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200923 if has('timers')
924 call assert_equal(0, res.time)
925 endif
926 call popup_close(winid)
927 call assert_equal({}, popup_getoptions(winid))
928endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200929
930func Test_popup_option_values()
931 new
932 " window-local
933 setlocal number
934 setlocal nowrap
935 " buffer-local
936 setlocal omnifunc=Something
937 " global/buffer-local
938 setlocal path=/there
939 " global/window-local
940 setlocal scrolloff=9
941
942 let winid = popup_create('hello', {})
943 call assert_equal(0, getwinvar(winid, '&number'))
944 call assert_equal(1, getwinvar(winid, '&wrap'))
945 call assert_equal('', getwinvar(winid, '&omnifunc'))
946 call assert_equal(&g:path, getwinvar(winid, '&path'))
947 call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
948
949 call popup_close(winid)
950 bwipe
951endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200952
953func Test_popup_atcursor()
954 topleft vnew
955 call setline(1, [
956 \ 'xxxxxxxxxxxxxxxxx',
957 \ 'xxxxxxxxxxxxxxxxx',
958 \ 'xxxxxxxxxxxxxxxxx',
959 \])
960
961 call cursor(2, 2)
962 redraw
963 let winid = popup_atcursor('vim', {})
964 redraw
965 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
966 call assert_equal('xvimxxxxxxxxxxxxx', line)
967 call popup_close(winid)
968
969 call cursor(3, 4)
970 redraw
971 let winid = popup_atcursor('vim', {})
972 redraw
973 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
974 call assert_equal('xxxvimxxxxxxxxxxx', line)
975 call popup_close(winid)
976
977 call cursor(1, 1)
978 redraw
979 let winid = popup_create('vim', {
980 \ 'line': 'cursor+2',
981 \ 'col': 'cursor+1',
982 \})
983 redraw
984 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
985 call assert_equal('xvimxxxxxxxxxxxxx', line)
986 call popup_close(winid)
987
988 call cursor(3, 3)
989 redraw
990 let winid = popup_create('vim', {
991 \ 'line': 'cursor-2',
992 \ 'col': 'cursor-1',
993 \})
994 redraw
995 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
996 call assert_equal('xvimxxxxxxxxxxxxx', line)
997 call popup_close(winid)
998
Bram Moolenaar402502d2019-05-30 22:07:36 +0200999 " just enough room above
1000 call cursor(3, 3)
1001 redraw
1002 let winid = popup_atcursor(['vim', 'is great'], {})
1003 redraw
1004 let pos = popup_getpos(winid)
1005 call assert_equal(1, pos.line)
1006 call popup_close(winid)
1007
1008 " not enough room above, popup goes below the cursor
1009 call cursor(3, 3)
1010 redraw
1011 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1012 redraw
1013 let pos = popup_getpos(winid)
1014 call assert_equal(4, pos.line)
1015 call popup_close(winid)
1016
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +02001017 " cursor in first line, popup in line 2
1018 call cursor(1, 1)
1019 redraw
1020 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1021 redraw
1022 let pos = popup_getpos(winid)
1023 call assert_equal(2, pos.line)
1024 call popup_close(winid)
1025
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001026 bwipe!
1027endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001028
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001029func Test_popup_beval()
1030 if !CanRunVimInTerminal()
1031 throw 'Skipped: cannot make screendumps'
1032 endif
1033
1034 let lines =<< trim END
1035 call setline(1, range(1, 20))
1036 call setline(5, 'here is some text to hover over')
1037 set balloonevalterm
1038 set balloonexpr=BalloonExpr()
1039 set balloondelay=100
1040 func BalloonExpr()
1041 let s:winid = popup_beval([v:beval_text], {})
1042 return ''
1043 endfunc
1044 func Hover()
1045 call test_setmouse(5, 15)
1046 call feedkeys("\<MouseMove>\<Ignore>", "xt")
1047 sleep 100m
1048 endfunc
1049 func MoveOntoPopup()
1050 call test_setmouse(4, 17)
1051 call feedkeys("\<F4>\<MouseMove>\<Ignore>", "xt")
1052 endfunc
1053 func MoveAway()
1054 call test_setmouse(5, 13)
1055 call feedkeys("\<F5>\<MouseMove>\<Ignore>", "xt")
1056 endfunc
1057 END
1058 call writefile(lines, 'XtestPopupBeval')
1059 let buf = RunVimInTerminal('-S XtestPopupBeval', {'rows': 10})
1060 call term_wait(buf, 100)
1061 call term_sendkeys(buf, 'j')
1062 call term_sendkeys(buf, ":call Hover()\<CR>")
1063 call VerifyScreenDump(buf, 'Test_popupwin_beval_1', {})
1064
1065 call term_sendkeys(buf, ":call MoveOntoPopup()\<CR>")
1066 call VerifyScreenDump(buf, 'Test_popupwin_beval_2', {})
1067
1068 call term_sendkeys(buf, ":call MoveAway()\<CR>")
1069 call VerifyScreenDump(buf, 'Test_popupwin_beval_3', {})
1070
1071 " clean up
1072 call StopVimInTerminal(buf)
1073 call delete('XtestPopupBeval')
1074endfunc
1075
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001076func Test_popup_filter()
1077 new
1078 call setline(1, 'some text')
1079
1080 func MyPopupFilter(winid, c)
1081 if a:c == 'e'
1082 let g:eaten = 'e'
1083 return 1
1084 endif
1085 if a:c == '0'
1086 let g:ignored = '0'
1087 return 0
1088 endif
1089 if a:c == 'x'
1090 call popup_close(a:winid)
1091 return 1
1092 endif
1093 return 0
1094 endfunc
1095
1096 let winid = popup_create('something', {'filter': 'MyPopupFilter'})
1097 redraw
1098
1099 " e is consumed by the filter
1100 call feedkeys('e', 'xt')
1101 call assert_equal('e', g:eaten)
1102
1103 " 0 is ignored by the filter
1104 normal $
1105 call assert_equal(9, getcurpos()[2])
1106 call feedkeys('0', 'xt')
1107 call assert_equal('0', g:ignored)
1108 call assert_equal(1, getcurpos()[2])
1109
1110 " x closes the popup
1111 call feedkeys('x', 'xt')
1112 call assert_equal('e', g:eaten)
1113 call assert_equal(-1, winbufnr(winid))
1114
1115 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001116 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001117endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001118
Bram Moolenaara42d9452019-06-15 21:46:30 +02001119func ShowDialog(key, result)
1120 let s:cb_res = 999
1121 let winid = popup_dialog('do you want to quit (Yes/no)?', {
1122 \ 'filter': 'popup_filter_yesno',
1123 \ 'callback': 'QuitCallback',
1124 \ })
1125 redraw
1126 call feedkeys(a:key, "xt")
1127 call assert_equal(winid, s:cb_winid)
1128 call assert_equal(a:result, s:cb_res)
1129endfunc
1130
1131func Test_popup_dialog()
1132 func QuitCallback(id, res)
1133 let s:cb_winid = a:id
1134 let s:cb_res = a:res
1135 endfunc
1136
1137 let winid = ShowDialog("y", 1)
1138 let winid = ShowDialog("Y", 1)
1139 let winid = ShowDialog("n", 0)
1140 let winid = ShowDialog("N", 0)
1141 let winid = ShowDialog("x", 0)
1142 let winid = ShowDialog("X", 0)
1143 let winid = ShowDialog("\<Esc>", 0)
1144 let winid = ShowDialog("\<C-C>", -1)
1145
1146 delfunc QuitCallback
1147endfunc
1148
Bram Moolenaara730e552019-06-16 19:05:31 +02001149func ShowMenu(key, result)
1150 let s:cb_res = 999
1151 let winid = popup_menu(['one', 'two', 'something else'], {
1152 \ 'callback': 'QuitCallback',
1153 \ })
1154 redraw
1155 call feedkeys(a:key, "xt")
1156 call assert_equal(winid, s:cb_winid)
1157 call assert_equal(a:result, s:cb_res)
1158endfunc
1159
1160func Test_popup_menu()
1161 func QuitCallback(id, res)
1162 let s:cb_winid = a:id
1163 let s:cb_res = a:res
1164 endfunc
1165
1166 let winid = ShowMenu(" ", 1)
1167 let winid = ShowMenu("j \<CR>", 2)
1168 let winid = ShowMenu("JjK \<CR>", 2)
1169 let winid = ShowMenu("jjjjjj ", 3)
1170 let winid = ShowMenu("kkk ", 1)
1171 let winid = ShowMenu("x", -1)
1172 let winid = ShowMenu("X", -1)
1173 let winid = ShowMenu("\<Esc>", -1)
1174 let winid = ShowMenu("\<C-C>", -1)
1175
1176 delfunc QuitCallback
1177endfunc
1178
1179func Test_popup_menu_screenshot()
1180 if !CanRunVimInTerminal()
1181 throw 'Skipped: cannot make screendumps'
1182 endif
1183
1184 let lines =<< trim END
1185 call setline(1, range(1, 20))
1186 hi PopupSelected ctermbg=lightblue
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001187 call popup_menu(['one', 'two', 'another'], {'callback': 'MenuDone', 'title': ' make a choice from the list '})
Bram Moolenaara730e552019-06-16 19:05:31 +02001188 func MenuDone(id, res)
1189 echomsg "selected " .. a:res
1190 endfunc
1191 END
1192 call writefile(lines, 'XtestPopupMenu')
1193 let buf = RunVimInTerminal('-S XtestPopupMenu', {'rows': 10})
1194 call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {})
1195
1196 call term_sendkeys(buf, "jj")
1197 call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {})
1198
1199 call term_sendkeys(buf, " ")
1200 call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {})
1201
1202 " clean up
1203 call StopVimInTerminal(buf)
1204 call delete('XtestPopupMenu')
1205endfunc
1206
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001207func Test_popup_title()
1208 if !CanRunVimInTerminal()
1209 throw 'Skipped: cannot make screendumps'
1210 endif
1211
1212 " Create a popup without title or border, a line of padding will be added to
1213 " put the title on.
1214 let lines =<< trim END
1215 call setline(1, range(1, 20))
1216 call popup_create(['one', 'two', 'another'], {'title': 'Title String'})
1217 END
1218 call writefile(lines, 'XtestPopupTitle')
1219 let buf = RunVimInTerminal('-S XtestPopupTitle', {'rows': 10})
1220 call VerifyScreenDump(buf, 'Test_popupwin_title', {})
1221
1222 " clean up
1223 call StopVimInTerminal(buf)
1224 call delete('XtestPopupTitle')
Bram Moolenaarae943152019-06-16 22:54:14 +02001225
1226 let winid = popup_create('something', {'title': 'Some Title'})
1227 call assert_equal('Some Title', popup_getoptions(winid).title)
1228 call popup_setoptions(winid, {'title': 'Another Title'})
1229 call assert_equal('Another Title', popup_getoptions(winid).title)
1230
1231 call popup_clear()
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001232endfunc
1233
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001234func Test_popup_close_callback()
1235 func PopupDone(id, result)
1236 let g:result = a:result
1237 endfunc
1238 let winid = popup_create('something', {'callback': 'PopupDone'})
1239 redraw
1240 call popup_close(winid, 'done')
1241 call assert_equal('done', g:result)
1242endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001243
1244func Test_popup_empty()
1245 let winid = popup_create('', {'padding': [2,2,2,2]})
1246 redraw
1247 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001248 call assert_equal(5, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001249 call assert_equal(5, pos.height)
1250
1251 let winid = popup_create([], {'border': []})
1252 redraw
1253 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001254 call assert_equal(3, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001255 call assert_equal(3, pos.height)
1256endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +02001257
1258func Test_popup_never_behind()
1259 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +02001260 throw 'Skipped: cannot make screendumps'
Bram Moolenaar988c4332019-06-02 14:12:11 +02001261 endif
1262 " +-----------------------------+
1263 " | | |
1264 " | | |
1265 " | | |
1266 " | line1 |
1267 " |------------line2------------|
1268 " | line3 |
1269 " | line4 |
1270 " | |
1271 " | |
1272 " +-----------------------------+
1273 let lines =<< trim END
1274 only
1275 split
1276 vsplit
1277 let info_window1 = getwininfo()[0]
1278 let line = info_window1['height']
1279 let col = info_window1['width']
1280 call popup_create(['line1', 'line2', 'line3', 'line4'], {
1281 \ 'line' : line,
1282 \ 'col' : col,
1283 \ })
1284 END
1285 call writefile(lines, 'XtestPopupBehind')
1286 let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10})
1287 call term_sendkeys(buf, "\<C-W>w")
1288 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
1289
1290 " clean up
1291 call StopVimInTerminal(buf)
1292 call delete('XtestPopupBehind')
1293endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001294
1295func s:VerifyPosition( p, msg, line, col, width, height )
1296 call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' )
1297 call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' )
1298 call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' )
1299 call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' )
1300endfunc
1301
1302func Test_popup_position_adjust()
1303 " Anything placed past 2 cells from of the right of the screen is moved to the
1304 " left.
1305 "
1306 " When wrapping is disabled, we also shift to the left to display on the
1307 " screen, unless fixed is set.
1308
1309 " Entries for cases which don't vary based on wrapping.
1310 " Format is per tests described below
1311 let both_wrap_tests = [
1312 \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ],
1313 \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ],
1314 \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ],
1315 \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ],
1316 \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ],
1317 \
1318 \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ],
1319 \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ],
1320 \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ],
1321 \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ],
1322 \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ],
1323 \
1324 \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ],
1325 \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
1326 \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
1327 \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
1328 \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ],
1329 \ ]
1330
1331 " these test groups are dicts with:
1332 " - comment: something to identify the group of tests by
1333 " - options: dict of options to merge with the row/col in tests
1334 " - tests: list of cases. Each one is a list with elements:
1335 " - text
1336 " - row
1337 " - col
1338 " - expected row
1339 " - expected col
1340 " - expected width
1341 " - expected height
1342 let tests = [
1343 \ {
1344 \ 'comment': 'left-aligned with wrapping',
1345 \ 'options': {
1346 \ 'wrap': 1,
1347 \ 'pos': 'botleft',
1348 \ },
1349 \ 'tests': both_wrap_tests + [
1350 \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ],
1351 \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ],
1352 \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ],
1353 \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ],
1354 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1355 \ ],
1356 \ },
1357 \ {
1358 \ 'comment': 'left aligned without wrapping',
1359 \ 'options': {
1360 \ 'wrap': 0,
1361 \ 'pos': 'botleft',
1362 \ },
1363 \ 'tests': both_wrap_tests + [
1364 \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ],
1365 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ],
1366 \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ],
1367 \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ],
1368 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1369 \ ],
1370 \ },
1371 \ {
1372 \ 'comment': 'left aligned with fixed position',
1373 \ 'options': {
1374 \ 'wrap': 0,
1375 \ 'fixed': 1,
1376 \ 'pos': 'botleft',
1377 \ },
1378 \ 'tests': both_wrap_tests + [
1379 \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ],
1380 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
1381 \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
1382 \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
1383 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1384 \ ],
1385 \ },
1386 \ ]
1387
1388 for test_group in tests
1389 for test in test_group.tests
1390 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
1391 let options = {
1392 \ 'line': line,
1393 \ 'col': col,
1394 \ }
1395 call extend( options, test_group.options )
1396
1397 let p = popup_create( text, options )
1398
1399 let msg = string( extend( options, { 'text': text } ) )
1400 call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height )
1401 call popup_close( p )
1402 endfor
1403 endfor
1404
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001405 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001406 %bwipe!
1407endfunc
1408
Bram Moolenaar3397f742019-06-02 18:40:06 +02001409func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001410 " width of screen
1411 let X = join(map(range(&columns), {->'X'}), '')
1412
1413 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
1414 call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 )
1415
1416 redraw
1417 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1418 call assert_equal(X, line)
1419
1420 call popup_close( p )
1421 redraw
1422
1423 " Same if placed on the right hand side
1424 let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } )
1425 call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 )
1426
1427 redraw
1428 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1429 call assert_equal(X, line)
1430
1431 call popup_close( p )
1432 redraw
1433
1434 " Extend so > window width
1435 let X .= 'x'
1436
1437 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
1438 call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 )
1439
1440 redraw
1441 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1442 call assert_equal(X[ : -2 ], line)
1443
1444 call popup_close( p )
1445 redraw
1446
1447 " Shifted then truncated (the x is not visible)
1448 let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } )
1449 call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 )
1450
1451 redraw
1452 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1453 call assert_equal(X[ : -2 ], line)
1454
1455 call popup_close( p )
1456 redraw
1457
1458 " Not shifted, just truncated
1459 let p = popup_create( X,
1460 \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } )
1461 call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
1462
1463 redraw
1464 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1465 let e_line = ' ' . X[ 1 : -2 ]
1466 call assert_equal(e_line, line)
1467
1468 call popup_close( p )
1469 redraw
1470
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001471 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001472 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001473endfunc
1474
1475func Test_popup_moved()
1476 new
1477 call test_override('char_avail', 1)
1478 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1479
1480 exe "normal gg0/word\<CR>"
1481 let winid = popup_atcursor('text', {'moved': 'any'})
1482 redraw
1483 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001484 call assert_equal([1, 4, 4], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001485 " trigger the check for last_cursormoved by going into insert mode
1486 call feedkeys("li\<Esc>", 'xt')
1487 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001488 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001489
1490 exe "normal gg0/word\<CR>"
1491 let winid = popup_atcursor('text', {'moved': 'word'})
1492 redraw
1493 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001494 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001495 call feedkeys("hi\<Esc>", 'xt')
1496 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001497 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001498
1499 exe "normal gg0/word\<CR>"
1500 let winid = popup_atcursor('text', {'moved': 'word'})
1501 redraw
1502 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001503 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001504 call feedkeys("li\<Esc>", 'xt')
1505 call assert_equal(1, popup_getpos(winid).visible)
1506 call feedkeys("ei\<Esc>", 'xt')
1507 call assert_equal(1, popup_getpos(winid).visible)
1508 call feedkeys("eli\<Esc>", 'xt')
1509 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001510 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001511
Bram Moolenaar17627312019-06-02 19:53:44 +02001512 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001513 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001514 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001515 redraw
1516 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001517 call assert_equal([2, 2, 15], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001518 call feedkeys("eli\<Esc>", 'xt')
1519 call assert_equal(1, popup_getpos(winid).visible)
1520 call feedkeys("wi\<Esc>", 'xt')
1521 call assert_equal(1, popup_getpos(winid).visible)
1522 call feedkeys("Eli\<Esc>", 'xt')
1523 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001524 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001525
1526 exe "normal gg0/word\<CR>"
1527 let winid = popup_atcursor('text', {'moved': [5, 10]})
1528 redraw
1529 call assert_equal(1, popup_getpos(winid).visible)
1530 call feedkeys("eli\<Esc>", 'xt')
1531 call feedkeys("ei\<Esc>", 'xt')
1532 call assert_equal(1, popup_getpos(winid).visible)
1533 call feedkeys("eli\<Esc>", 'xt')
1534 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001535 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001536
1537 bwipe!
1538 call test_override('ALL', 0)
1539endfunc
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001540
1541func Test_notifications()
1542 if !has('timers')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02001543 throw 'Skipped: timer feature not supported'
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001544 endif
1545 if !CanRunVimInTerminal()
1546 throw 'Skipped: cannot make screendumps'
1547 endif
1548
1549 call writefile([
1550 \ "call setline(1, range(1, 20))",
1551 \ "hi Notification ctermbg=lightblue",
1552 \ "call popup_notification('first notification', {})",
1553 \], 'XtestNotifications')
1554 let buf = RunVimInTerminal('-S XtestNotifications', {'rows': 10})
1555 call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {})
1556
1557 " second one goes below the first one
Bram Moolenaardfa97f22019-06-15 14:31:55 +02001558 call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>")
1559 call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>")
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001560 call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {})
1561
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001562 " clean up
1563 call StopVimInTerminal(buf)
1564 call delete('XtestNotifications')
1565endfunc
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001566
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001567func Test_popup_scrollbar()
1568 if !CanRunVimInTerminal()
1569 throw 'Skipped: cannot make screendumps'
1570 endif
1571
1572 let lines =<< trim END
1573 call setline(1, range(1, 20))
Bram Moolenaar8da41812019-06-26 18:04:54 +02001574 hi ScrollThumb ctermbg=blue
1575 hi ScrollBar ctermbg=red
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001576 let winid = popup_create(['one', 'two', 'three', 'four', 'five',
1577 \ 'six', 'seven', 'eight', 'nine'], {
1578 \ 'minwidth': 8,
1579 \ 'maxheight': 4,
1580 \ })
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001581 func ScrollUp()
1582 call feedkeys("\<F3>\<ScrollWheelUp>", "xt")
1583 endfunc
1584 func ScrollDown()
1585 call feedkeys("\<F3>\<ScrollWheelDown>", "xt")
1586 endfunc
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001587 func ClickTop()
1588 call feedkeys("\<F4>\<LeftMouse>", "xt")
1589 endfunc
1590 func ClickBot()
Bram Moolenaarbd42b312019-07-12 16:35:34 +02001591 call popup_setoptions(g:winid, {'border': [], 'close': 'button'})
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001592 call feedkeys("\<F5>\<LeftMouse>", "xt")
1593 endfunc
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001594 map <silent> <F3> :call test_setmouse(5, 36)<CR>
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001595 map <silent> <F4> :call test_setmouse(4, 42)<CR>
1596 map <silent> <F5> :call test_setmouse(7, 42)<CR>
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001597 END
1598 call writefile(lines, 'XtestPopupScroll')
1599 let buf = RunVimInTerminal('-S XtestPopupScroll', {'rows': 10})
1600 call VerifyScreenDump(buf, 'Test_popupwin_scroll_1', {})
1601
1602 call term_sendkeys(buf, ":call popup_setoptions(winid, {'firstline': 2})\<CR>")
1603 call VerifyScreenDump(buf, 'Test_popupwin_scroll_2', {})
1604
1605 call term_sendkeys(buf, ":call popup_setoptions(winid, {'firstline': 6})\<CR>")
1606 call VerifyScreenDump(buf, 'Test_popupwin_scroll_3', {})
1607
1608 call term_sendkeys(buf, ":call popup_setoptions(winid, {'firstline': 9})\<CR>")
1609 call VerifyScreenDump(buf, 'Test_popupwin_scroll_4', {})
1610
Bram Moolenaar8da41812019-06-26 18:04:54 +02001611 call term_sendkeys(buf, ":call popup_setoptions(winid, {'scrollbarhighlight': 'ScrollBar', 'thumbhighlight': 'ScrollThumb'})\<CR>")
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001612 call term_sendkeys(buf, ":call ScrollUp()\<CR>")
1613 call VerifyScreenDump(buf, 'Test_popupwin_scroll_5', {})
1614
1615 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
1616 call VerifyScreenDump(buf, 'Test_popupwin_scroll_6', {})
1617
1618 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
Bram Moolenaar13b47c32019-06-28 21:55:48 +02001619 " wait a bit, otherwise it fails sometimes (double click recognized?)
1620 sleep 100m
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001621 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
1622 call VerifyScreenDump(buf, 'Test_popupwin_scroll_7', {})
1623
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001624 call term_sendkeys(buf, ":call ClickTop()\<CR>")
1625 sleep 100m
1626 call term_sendkeys(buf, ":call ClickTop()\<CR>")
1627 call VerifyScreenDump(buf, 'Test_popupwin_scroll_8', {})
1628
1629 call term_sendkeys(buf, ":call ClickBot()\<CR>")
1630 call VerifyScreenDump(buf, 'Test_popupwin_scroll_9', {})
1631
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001632 " clean up
1633 call StopVimInTerminal(buf)
1634 call delete('XtestPopupScroll')
1635endfunc
1636
Bram Moolenaar437a7462019-07-05 20:17:22 +02001637func Test_popup_fitting_scrollbar()
1638 " this was causing a crash, divide by zero
1639 let winid = popup_create([
1640 \ 'one', 'two', 'longer line that wraps', 'four', 'five'], {
1641 \ 'scrollbar': 1,
1642 \ 'maxwidth': 10,
1643 \ 'maxheight': 5,
1644 \ 'firstline': 2})
1645 redraw
1646 call popup_clear()
1647endfunc
1648
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001649func Test_popup_settext()
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001650 if !CanRunVimInTerminal()
1651 throw 'Skipped: cannot make screendumps'
1652 endif
1653
1654 let lines =<< trim END
1655 let opts = {'wrap': 0}
1656 let p = popup_create('test', opts)
1657 call popup_settext(p, 'this is a text')
1658 END
1659
1660 call writefile( lines, 'XtestPopupSetText' )
1661 let buf = RunVimInTerminal('-S XtestPopupSetText', {'rows': 10})
1662 call VerifyScreenDump(buf, 'Test_popup_settext_01', {})
1663
1664 " Setting to empty string clears it
1665 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>")
1666 call VerifyScreenDump(buf, 'Test_popup_settext_02', {})
1667
1668 " Setting a list
1669 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1670 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1671
1672 " Shrinking with a list
1673 call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>")
1674 call VerifyScreenDump(buf, 'Test_popup_settext_04', {})
1675
1676 " Growing with a list
1677 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1678 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1679
1680 " Empty list clears
1681 call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>")
1682 call VerifyScreenDump(buf, 'Test_popup_settext_05', {})
1683
1684 " Dicts
1685 call term_sendkeys(buf, ":call popup_settext(p, [{'text': 'aaaa'}, {'text': 'bbbb'}, {'text': 'cccc'}])\<CR>")
1686 call VerifyScreenDump(buf, 'Test_popup_settext_06', {})
1687
1688 " clean up
1689 call StopVimInTerminal(buf)
1690 call delete('XtestPopupSetText')
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001691endfunc
1692
1693func Test_popup_hidden()
1694 new
1695
1696 let winid = popup_atcursor('text', {'hidden': 1})
1697 redraw
1698 call assert_equal(0, popup_getpos(winid).visible)
1699 call popup_close(winid)
1700
1701 let winid = popup_create('text', {'hidden': 1})
1702 redraw
1703 call assert_equal(0, popup_getpos(winid).visible)
1704 call popup_close(winid)
1705
1706 func QuitCallback(id, res)
1707 let s:cb_winid = a:id
1708 let s:cb_res = a:res
1709 endfunc
1710 let winid = popup_dialog('make a choice', {'hidden': 1,
1711 \ 'filter': 'popup_filter_yesno',
1712 \ 'callback': 'QuitCallback',
1713 \ })
1714 redraw
1715 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001716 call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter)
1717 call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback)
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001718 exe "normal anot used by filter\<Esc>"
1719 call assert_equal('not used by filter', getline(1))
1720
1721 call popup_show(winid)
1722 call feedkeys('y', "xt")
1723 call assert_equal(1, s:cb_res)
1724
1725 bwipe!
1726 delfunc QuitCallback
1727endfunc
Bram Moolenaarae943152019-06-16 22:54:14 +02001728
1729" Test options not checked elsewhere
1730func Test_set_get_options()
1731 let winid = popup_create('some text', {'highlight': 'Beautiful'})
1732 let options = popup_getoptions(winid)
1733 call assert_equal(1, options.wrap)
1734 call assert_equal(0, options.drag)
1735 call assert_equal('Beautiful', options.highlight)
1736
1737 call popup_setoptions(winid, {'wrap': 0, 'drag': 1, 'highlight': 'Another'})
1738 let options = popup_getoptions(winid)
1739 call assert_equal(0, options.wrap)
1740 call assert_equal(1, options.drag)
1741 call assert_equal('Another', options.highlight)
1742
1743 call popup_close(winid)
1744endfunc
Bram Moolenaar75a1a942019-06-20 03:45:36 +02001745
1746func Test_popupwin_garbage_collect()
1747 func MyPopupFilter(x, winid, c)
1748 " NOP
1749 endfunc
1750
1751 let winid = popup_create('something', {'filter': function('MyPopupFilter', [{}])})
1752 call test_garbagecollect_now()
1753 redraw
1754 " Must not crach caused by invalid memory access
1755 call feedkeys('j', 'xt')
1756 call assert_true(v:true)
1757
1758 call popup_close(winid)
1759 delfunc MyPopupFilter
1760endfunc
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001761
1762func Test_popupwin_with_buffer()
1763 call writefile(['some text', 'in a buffer'], 'XsomeFile')
1764 let buf = bufadd('XsomeFile')
1765 call assert_equal(0, bufloaded(buf))
1766 let winid = popup_create(buf, {})
1767 call assert_notequal(0, winid)
1768 let pos = popup_getpos(winid)
1769 call assert_equal(2, pos.height)
1770 call assert_equal(1, bufloaded(buf))
1771 call popup_close(winid)
1772 call assert_equal({}, popup_getpos(winid))
1773 call assert_equal(1, bufloaded(buf))
1774 exe 'bwipe! ' .. buf
Bram Moolenaar7866b872019-07-01 22:21:01 +02001775
1776 edit test_popupwin.vim
1777 let winid = popup_create(bufnr(''), {})
1778 redraw
1779 call popup_close(winid)
Bram Moolenaar3940ec62019-07-05 21:53:24 +02001780 call delete('XsomeFile')
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001781endfunc
Bram Moolenaare296e312019-07-03 23:20:18 +02001782
1783func Test_popupwin_width()
1784 let winid = popup_create(repeat(['short', 'long long long line', 'medium width'], 50), {
1785 \ 'maxwidth': 40,
1786 \ 'maxheight': 10,
1787 \ })
1788 for top in range(1, 20)
1789 call popup_setoptions(winid, {'firstline': top})
1790 redraw
1791 call assert_equal(19, popup_getpos(winid).width)
1792 endfor
1793 call popup_clear()
1794endfunc
Bram Moolenaar5ca1ac32019-07-04 15:39:28 +02001795
1796func Test_popupwin_buf_close()
1797 let buf = bufadd('Xtestbuf')
1798 call bufload(buf)
1799 call setbufline(buf, 1, ['just', 'some', 'lines'])
1800 let winid = popup_create(buf, {})
1801 redraw
1802 call assert_equal(3, popup_getpos(winid).height)
1803 let bufinfo = getbufinfo(buf)[0]
1804 call assert_equal(1, bufinfo.changed)
1805 call assert_equal(0, bufinfo.hidden)
1806 call assert_equal(0, bufinfo.listed)
1807 call assert_equal(1, bufinfo.loaded)
1808 call assert_equal([], bufinfo.windows)
1809 call assert_equal([winid], bufinfo.popups)
1810
1811 call popup_close(winid)
1812 call assert_equal({}, popup_getpos(winid))
1813 let bufinfo = getbufinfo(buf)[0]
1814 call assert_equal(1, bufinfo.changed)
1815 call assert_equal(1, bufinfo.hidden)
1816 call assert_equal(0, bufinfo.listed)
1817 call assert_equal(1, bufinfo.loaded)
1818 call assert_equal([], bufinfo.windows)
1819 call assert_equal([], bufinfo.popups)
1820 exe 'bwipe! ' .. buf
1821endfunc
Bram Moolenaar017c2692019-07-13 14:17:51 +02001822
1823func Test_popup_menu_with_maxwidth()
1824 if !CanRunVimInTerminal()
1825 throw 'Skipped: cannot make screendumps'
1826 endif
1827
1828 let lines =<< trim END
1829 call setline(1, range(1, 10))
1830 hi ScrollThumb ctermbg=blue
1831 hi ScrollBar ctermbg=red
1832 func PopupMenu(lines, line, col, scrollbar = 0)
1833 return popup_menu(a:lines, {
1834 \ 'maxwidth': 10,
1835 \ 'maxheight': 3,
1836 \ 'pos' : 'topleft',
1837 \ 'col' : a:col,
1838 \ 'line' : a:line,
1839 \ 'scrollbar' : a:scrollbar,
1840 \ })
1841 endfunc
1842 call PopupMenu(['x'], 1, 1)
1843 call PopupMenu(['123456789|'], 1, 16)
1844 call PopupMenu(['123456789|' .. ' '], 7, 1)
1845 call PopupMenu([repeat('123456789|', 100)], 7, 16)
1846 call PopupMenu(repeat(['123456789|' .. ' '], 5), 1, 33, 1)
1847 END
1848 call writefile(lines, 'XtestPopupMenuMaxWidth')
1849 let buf = RunVimInTerminal('-S XtestPopupMenuMaxWidth', {'rows': 13})
1850 call VerifyScreenDump(buf, 'Test_popupwin_menu_maxwidth_1', {})
1851
1852 " close the menu popupwin.
1853 call term_sendkeys(buf, " ")
1854 call term_sendkeys(buf, " ")
1855 call term_sendkeys(buf, " ")
1856 call term_sendkeys(buf, " ")
1857 call term_sendkeys(buf, " ")
1858
1859 " clean up
1860 call StopVimInTerminal(buf)
1861 call delete('XtestPopupMenuMaxWidth')
1862endfunc
1863
1864" vim: shiftwidth=2 sts=2 expandtab