blob: 451f0b6b92a627a0c0f0f37bd44db91cd2aa7887 [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', '#']})",
Bram Moolenaarad24a712019-06-17 20:05:45 +0200111 \ "let winid = popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})",
Bram Moolenaar790498b2019-06-01 22:15:29 +0200112 \ "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
Bram Moolenaarad24a712019-06-17 20:05:45 +0200117 " check that changing borderchars triggers a redraw
118 call term_sendkeys(buf, ":call popup_setoptions(winid, {'borderchars': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']})\<CR>")
119 call VerifyScreenDump(buf, 'Test_popupwin_23', {})
120
Bram Moolenaar790498b2019-06-01 22:15:29 +0200121 call StopVimInTerminal(buf)
122 call delete('XtestPopupBorder')
123
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200124 let with_border_or_padding = {
125 \ 'line': 2,
126 \ 'core_line': 3,
127 \ 'col': 3,
128 \ 'core_col': 4,
129 \ 'width': 14,
130 \ 'core_width': 12,
131 \ 'height': 3,
132 \ 'core_height': 1,
133 \ 'visible': 1}
134 let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
135 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200136 let options = popup_getoptions(winid)
137 call assert_equal([], options.border)
138 call assert_false(has_key(options, "padding"))
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200139
Bram Moolenaarae943152019-06-16 22:54:14 +0200140 let winid = popup_create('hello padding', {'line': 2, 'col': 3, 'padding': []})
141 let with_border_or_padding.width = 15
142 let with_border_or_padding.core_width = 13
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200143 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200144 let options = popup_getoptions(winid)
145 call assert_false(has_key(options, "border"))
146 call assert_equal([], options.padding)
147
148 call popup_setoptions(winid, {
149 \ 'padding': [1, 2, 3, 4],
150 \ 'border': [4, 0, 7, 8],
151 \ 'borderhighlight': ['Top', 'Right', 'Bottom', 'Left'],
152 \ 'borderchars': ['1', '^', '2', '>', '3', 'v', '4', '<'],
153 \ })
154 let options = popup_getoptions(winid)
155 call assert_equal([1, 0, 1, 1], options.border)
156 call assert_equal([1, 2, 3, 4], options.padding)
157 call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
158 call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200159
160 let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []})
161 call assert_equal({
162 \ 'line': 3,
163 \ 'core_line': 5,
164 \ 'col': 8,
165 \ 'core_col': 10,
166 \ 'width': 14,
167 \ 'core_width': 10,
168 \ 'height': 5,
169 \ 'core_height': 1,
170 \ 'visible': 1}, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200171
172 call popup_clear()
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200173endfunc
174
Bram Moolenaarb4230122019-05-30 18:40:53 +0200175func Test_popup_with_syntax_win_execute()
176 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200177 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200178 endif
179 call writefile([
180 \ "call setline(1, range(1, 100))",
181 \ "hi PopupColor ctermbg=lightblue",
182 \ "let winid = popup_create([",
183 \ "\\ '#include <stdio.h>',",
184 \ "\\ 'int main(void)',",
185 \ "\\ '{',",
186 \ "\\ ' printf(123);',",
187 \ "\\ '}',",
188 \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})",
189 \ "call win_execute(winid, 'set syntax=cpp')",
190 \], 'XtestPopup')
191 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
192 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
193
194 " clean up
195 call StopVimInTerminal(buf)
196 call delete('XtestPopup')
197endfunc
198
199func Test_popup_with_syntax_setbufvar()
200 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200201 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200202 endif
Bram Moolenaar402502d2019-05-30 22:07:36 +0200203 let lines =<< trim END
204 call setline(1, range(1, 100))
205 hi PopupColor ctermbg=lightgrey
206 let winid = popup_create([
207 \ '#include <stdio.h>',
208 \ 'int main(void)',
209 \ '{',
210 \ ' printf(567);',
211 \ '}',
212 \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})
213 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
214 END
215 call writefile(lines, 'XtestPopup')
Bram Moolenaarb4230122019-05-30 18:40:53 +0200216 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
217 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
218
219 " clean up
220 call StopVimInTerminal(buf)
221 call delete('XtestPopup')
222endfunc
223
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200224func Test_popup_with_matches()
225 if !CanRunVimInTerminal()
226 throw 'Skipped: cannot make screendumps'
227 endif
228 let lines =<< trim END
229 call setline(1, ['111 222 333', '444 555 666'])
230 let winid = popup_create([
231 \ '111 222 333',
232 \ '444 555 666',
233 \], {'line': 3, 'col': 10, 'border': []})
234 set hlsearch
235 /666
236 call matchadd('ErrorMsg', '111')
237 call matchadd('ErrorMsg', '444')
238 call win_execute(winid, "call matchadd('ErrorMsg', '111')")
239 call win_execute(winid, "call matchadd('ErrorMsg', '555')")
240 END
241 call writefile(lines, 'XtestPopupMatches')
242 let buf = RunVimInTerminal('-S XtestPopupMatches', {'rows': 10})
243 call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
244
245 " clean up
246 call StopVimInTerminal(buf)
247 call delete('XtestPopupMatches')
248endfunc
249
Bram Moolenaar399d8982019-06-02 15:34:29 +0200250func Test_popup_all_corners()
251 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200252 throw 'Skipped: cannot make screendumps'
Bram Moolenaar399d8982019-06-02 15:34:29 +0200253 endif
254 let lines =<< trim END
255 call setline(1, repeat([repeat('-', 60)], 15))
256 set so=0
257 normal 2G3|r#
258 let winid1 = popup_create(['first', 'second'], {
259 \ 'line': 'cursor+1',
260 \ 'col': 'cursor',
261 \ 'pos': 'topleft',
262 \ 'border': [],
263 \ 'padding': [],
264 \ })
265 normal 25|r@
266 let winid1 = popup_create(['First', 'SeconD'], {
267 \ 'line': 'cursor+1',
268 \ 'col': 'cursor',
269 \ 'pos': 'topright',
270 \ 'border': [],
271 \ 'padding': [],
272 \ })
273 normal 9G29|r%
274 let winid1 = popup_create(['fiRSt', 'seCOnd'], {
275 \ 'line': 'cursor-1',
276 \ 'col': 'cursor',
277 \ 'pos': 'botleft',
278 \ 'border': [],
279 \ 'padding': [],
280 \ })
281 normal 51|r&
282 let winid1 = popup_create(['FIrsT', 'SEcoND'], {
283 \ 'line': 'cursor-1',
284 \ 'col': 'cursor',
285 \ 'pos': 'botright',
286 \ 'border': [],
287 \ 'padding': [],
288 \ })
289 END
290 call writefile(lines, 'XtestPopupCorners')
291 let buf = RunVimInTerminal('-S XtestPopupCorners', {'rows': 12})
292 call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
293
294 " clean up
295 call StopVimInTerminal(buf)
296 call delete('XtestPopupCorners')
297endfunc
298
Bram Moolenaar8d241042019-06-12 23:40:01 +0200299func Test_popup_firstline()
300 if !CanRunVimInTerminal()
301 throw 'Skipped: cannot make screendumps'
302 endif
303 let lines =<< trim END
304 call setline(1, range(1, 20))
305 call popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], {
306 \ 'maxheight': 4,
307 \ 'firstline': 3,
308 \ })
309 END
310 call writefile(lines, 'XtestPopupFirstline')
311 let buf = RunVimInTerminal('-S XtestPopupFirstline', {'rows': 10})
312 call VerifyScreenDump(buf, 'Test_popupwin_firstline', {})
313
314 " clean up
315 call StopVimInTerminal(buf)
316 call delete('XtestPopupFirstline')
Bram Moolenaarae943152019-06-16 22:54:14 +0200317
318 let winid = popup_create(['1111', '222222', '33333', '44444'], {
319 \ 'maxheight': 2,
320 \ 'firstline': 3,
321 \ })
322 call assert_equal(3, popup_getoptions(winid).firstline)
323 call popup_setoptions(winid, {'firstline': 1})
324 call assert_equal(1, popup_getoptions(winid).firstline)
325
326 call popup_close(winid)
Bram Moolenaar8d241042019-06-12 23:40:01 +0200327endfunc
328
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200329func Test_popup_drag()
330 if !CanRunVimInTerminal()
331 throw 'Skipped: cannot make screendumps'
332 endif
333 " create a popup that covers the command line
334 let lines =<< trim END
335 call setline(1, range(1, 20))
336 let winid = popup_create(['1111', '222222', '33333'], {
337 \ 'drag': 1,
338 \ 'border': [],
339 \ 'line': &lines - 4,
340 \ })
341 func Dragit()
342 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
343 endfunc
344 map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR>
345 map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2)<CR>
346 END
347 call writefile(lines, 'XtestPopupDrag')
348 let buf = RunVimInTerminal('-S XtestPopupDrag', {'rows': 10})
349 call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {})
350
351 call term_sendkeys(buf, ":call Dragit()\<CR>")
352 call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {})
353
354 " clean up
355 call StopVimInTerminal(buf)
356 call delete('XtestPopupDrag')
357endfunc
358
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200359func Test_popup_select()
360 if !CanRunVimInTerminal()
361 throw 'Skipped: cannot make screendumps'
362 endif
Bram Moolenaar650a6372019-06-15 00:29:33 +0200363 if !has('clipboard')
364 throw 'Skipped: clipboard feature missing'
365 endif
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200366 " create a popup with some text to be selected
367 let lines =<< trim END
Bram Moolenaar1755ec42019-06-15 13:13:54 +0200368 set clipboard=autoselect
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200369 call setline(1, range(1, 20))
370 let winid = popup_create(['the word', 'some more', 'several words here'], {
371 \ 'drag': 1,
372 \ 'border': [],
373 \ 'line': 3,
374 \ 'col': 10,
375 \ })
376 func Select1()
377 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
378 endfunc
379 map <silent> <F3> :call test_setmouse(4, 15)<CR>
380 map <silent> <F4> :call test_setmouse(6, 23)<CR>
381 END
382 call writefile(lines, 'XtestPopupSelect')
383 let buf = RunVimInTerminal('-S XtestPopupSelect', {'rows': 10})
384 call term_sendkeys(buf, ":call Select1()\<CR>")
385 call VerifyScreenDump(buf, 'Test_popupwin_select_01', {})
386
387 call term_sendkeys(buf, ":call popup_close(winid)\<CR>")
388 call term_sendkeys(buf, "\"*p")
389 call VerifyScreenDump(buf, 'Test_popupwin_select_02', {})
390
391 " clean up
392 call StopVimInTerminal(buf)
393 call delete('XtestPopupSelect')
394endfunc
395
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200396func Test_popup_in_tab()
397 " default popup is local to tab, not visible when in other tab
398 let winid = popup_create("text", {})
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200399 let bufnr = winbufnr(winid)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200400 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200401 call assert_equal(0, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200402 tabnew
403 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200404 call assert_equal(1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200405 quit
406 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200407
408 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200409 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200410 " buffer is gone now
411 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200412
413 " global popup is visible in any tab
Bram Moolenaarfc06cbb2019-06-15 14:14:31 +0200414 let winid = popup_create("text", {'tabpage': -1})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200415 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200416 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200417 tabnew
418 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200419 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200420 quit
421 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200422 call popup_clear()
Bram Moolenaara3fce622019-06-20 02:31:49 +0200423
424 " create popup in other tab
425 tabnew
426 let winid = popup_create("text", {'tabpage': 1})
427 call assert_equal(0, popup_getpos(winid).visible)
428 call assert_equal(1, popup_getoptions(winid).tabpage)
429 quit
430 call assert_equal(1, popup_getpos(winid).visible)
431 call assert_equal(0, popup_getoptions(winid).tabpage)
432 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200433endfunc
434
435func Test_popup_valid_arguments()
436 " Zero value is like the property wasn't there
437 let winid = popup_create("text", {"col": 0})
438 let pos = popup_getpos(winid)
439 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200440 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200441
442 " using cursor column has minimum value of 1
443 let winid = popup_create("text", {"col": 'cursor-100'})
444 let pos = popup_getpos(winid)
445 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200446 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200447
448 " center
449 let winid = popup_create("text", {"pos": 'center'})
450 let pos = popup_getpos(winid)
451 let around = (&columns - pos.width) / 2
452 call assert_inrange(around - 1, around + 1, pos.col)
453 let around = (&lines - pos.height) / 2
454 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200455 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200456endfunc
457
458func Test_popup_invalid_arguments()
459 call assert_fails('call popup_create(666, {})', 'E714:')
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", "none")', 'E715:')
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", {"col": "xxx"})', '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", {"col": "cursor8"})', 'E15:')
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", {"col": "cursor+x"})', 'E15:')
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", {"col": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200471 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200472
473 call assert_fails('call popup_create("text", {"line": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200474 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200475 call assert_fails('call popup_create("text", {"line": "cursor8"})', 'E15:')
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", {"line": "cursor+x"})', 'E15:')
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", {"line": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200480 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200481
482 call assert_fails('call popup_create("text", {"pos": "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200483 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200484 call assert_fails('call popup_create("text", {"padding": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200485 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200486 call assert_fails('call popup_create("text", {"border": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200487 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200488 call assert_fails('call popup_create("text", {"borderhighlight": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200489 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200490 call assert_fails('call popup_create("text", {"borderchars": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200491 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200492
493 call assert_fails('call popup_create([{"text": "text"}, 666], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200494 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200495 call assert_fails('call popup_create([{"text": "text", "props": "none"}], {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200496 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200497 call assert_fails('call popup_create([{"text": "text", "props": ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200498 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200499endfunc
500
Bram Moolenaareea16992019-05-31 17:34:48 +0200501func Test_win_execute_closing_curwin()
502 split
503 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200504 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200505 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200506endfunc
507
508func Test_win_execute_not_allowed()
509 let winid = popup_create('some text', {})
510 call assert_fails('call win_execute(winid, "split")', 'E994:')
511 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
512 call assert_fails('call win_execute(winid, "close")', 'E994:')
513 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200514 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200515 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
516 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
517 call assert_fails('call win_execute(winid, "next")', 'E994:')
518 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
519 call assert_fails('call win_execute(winid, "buf")', 'E994:')
520 call assert_fails('call win_execute(winid, "edit")', 'E994:')
521 call assert_fails('call win_execute(winid, "enew")', 'E994:')
522 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
523 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
524 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
525 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200526 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200527endfunc
528
Bram Moolenaar402502d2019-05-30 22:07:36 +0200529func Test_popup_with_wrap()
530 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200531 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200532 endif
533 let lines =<< trim END
534 call setline(1, range(1, 100))
535 let winid = popup_create(
536 \ 'a long line that wont fit',
537 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
538 END
539 call writefile(lines, 'XtestPopup')
540 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
541 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
542
543 " clean up
544 call StopVimInTerminal(buf)
545 call delete('XtestPopup')
546endfunc
547
548func Test_popup_without_wrap()
549 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200550 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200551 endif
552 let lines =<< trim END
553 call setline(1, range(1, 100))
554 let winid = popup_create(
555 \ 'a long line that wont fit',
556 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
557 END
558 call writefile(lines, 'XtestPopup')
559 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
560 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
561
562 " clean up
563 call StopVimInTerminal(buf)
564 call delete('XtestPopup')
565endfunc
566
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200567func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200568 if !has('timers')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +0200569 throw 'Skipped: timer feature not supported'
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200570 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200571 topleft vnew
572 call setline(1, 'hello')
573
574 call popup_create('world', {
575 \ 'line': 1,
576 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200577 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200578 \ 'time': 500,
579 \})
580 redraw
581 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
582 call assert_equal('world', line)
583
584 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200585 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200586 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
587 call assert_equal('hello', line)
588
589 call popup_create('on the command line', {
590 \ 'line': &lines,
591 \ 'col': 10,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200592 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200593 \ 'time': 500,
594 \})
595 redraw
596 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
597 call assert_match('.*on the command line.*', line)
598
599 sleep 700m
600 redraw
601 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
602 call assert_notmatch('.*on the command line.*', line)
603
604 bwipe!
605endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200606
607func Test_popup_hide()
608 topleft vnew
609 call setline(1, 'hello')
610
611 let winid = popup_create('world', {
612 \ 'line': 1,
613 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200614 \ 'minwidth': 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200615 \})
616 redraw
617 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
618 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200619 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200620 " buffer is still listed and active
621 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200622
623 call popup_hide(winid)
624 redraw
625 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
626 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200627 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200628 " buffer is still listed but hidden
629 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200630
631 call popup_show(winid)
632 redraw
633 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
634 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200635 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200636
637
638 call popup_close(winid)
639 redraw
640 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
641 call assert_equal('hello', line)
642
643 " error is given for existing non-popup window
644 call assert_fails('call popup_hide(win_getid())', 'E993:')
645
646 " no error non-existing window
647 call popup_hide(1234234)
648 call popup_show(41234234)
649
650 bwipe!
651endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200652
653func Test_popup_move()
654 topleft vnew
655 call setline(1, 'hello')
656
657 let winid = popup_create('world', {
658 \ 'line': 1,
659 \ 'col': 1,
660 \ 'minwidth': 20,
661 \})
662 redraw
663 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
664 call assert_equal('world ', line)
665
666 call popup_move(winid, {'line': 2, 'col': 2})
667 redraw
668 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
669 call assert_equal('hello ', line)
670 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
671 call assert_equal('~world', line)
672
673 call popup_move(winid, {'line': 1})
674 redraw
675 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
676 call assert_equal('hworld', line)
677
678 call popup_close(winid)
679
680 bwipe!
681endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200682
Bram Moolenaar402502d2019-05-30 22:07:36 +0200683func Test_popup_getpos()
Bram Moolenaarbc133542019-05-29 20:26:46 +0200684 let winid = popup_create('hello', {
685 \ 'line': 2,
686 \ 'col': 3,
687 \ 'minwidth': 10,
688 \ 'minheight': 11,
689 \})
690 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200691 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200692 call assert_equal(2, res.line)
693 call assert_equal(3, res.col)
694 call assert_equal(10, res.width)
695 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200696 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200697
698 call popup_close(winid)
699endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200700
701func Test_popup_width_longest()
702 let tests = [
703 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
704 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
705 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
706 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
707 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
708 \ ]
709
710 for test in tests
711 let winid = popup_create(test[0], {'line': 2, 'col': 3})
712 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200713 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200714 call assert_equal(test[1], position.width)
715 call popup_close(winid)
716 endfor
717endfunc
718
719func Test_popup_wraps()
720 let tests = [
721 \ ['nowrap', 6, 1],
722 \ ['a line that wraps once', 12, 2],
723 \ ['a line that wraps two times', 12, 3],
724 \ ]
725 for test in tests
726 let winid = popup_create(test[0],
727 \ {'line': 2, 'col': 3, 'maxwidth': 12})
728 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200729 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200730 call assert_equal(test[1], position.width)
731 call assert_equal(test[2], position.height)
732
733 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200734 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200735 endfor
736endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200737
738func Test_popup_getoptions()
739 let winid = popup_create('hello', {
740 \ 'line': 2,
741 \ 'col': 3,
742 \ 'minwidth': 10,
743 \ 'minheight': 11,
744 \ 'maxwidth': 20,
745 \ 'maxheight': 21,
746 \ 'zindex': 100,
747 \ 'time': 5000,
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200748 \ 'fixed': 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200749 \})
750 redraw
751 let res = popup_getoptions(winid)
752 call assert_equal(2, res.line)
753 call assert_equal(3, res.col)
754 call assert_equal(10, res.minwidth)
755 call assert_equal(11, res.minheight)
756 call assert_equal(20, res.maxwidth)
757 call assert_equal(21, res.maxheight)
758 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200759 call assert_equal(1, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200760 if has('timers')
761 call assert_equal(5000, res.time)
762 endif
763 call popup_close(winid)
764
765 let winid = popup_create('hello', {})
766 redraw
767 let res = popup_getoptions(winid)
768 call assert_equal(0, res.line)
769 call assert_equal(0, res.col)
770 call assert_equal(0, res.minwidth)
771 call assert_equal(0, res.minheight)
772 call assert_equal(0, res.maxwidth)
773 call assert_equal(0, res.maxheight)
774 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200775 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200776 if has('timers')
777 call assert_equal(0, res.time)
778 endif
779 call popup_close(winid)
780 call assert_equal({}, popup_getoptions(winid))
781endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200782
783func Test_popup_option_values()
784 new
785 " window-local
786 setlocal number
787 setlocal nowrap
788 " buffer-local
789 setlocal omnifunc=Something
790 " global/buffer-local
791 setlocal path=/there
792 " global/window-local
793 setlocal scrolloff=9
794
795 let winid = popup_create('hello', {})
796 call assert_equal(0, getwinvar(winid, '&number'))
797 call assert_equal(1, getwinvar(winid, '&wrap'))
798 call assert_equal('', getwinvar(winid, '&omnifunc'))
799 call assert_equal(&g:path, getwinvar(winid, '&path'))
800 call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
801
802 call popup_close(winid)
803 bwipe
804endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200805
806func Test_popup_atcursor()
807 topleft vnew
808 call setline(1, [
809 \ 'xxxxxxxxxxxxxxxxx',
810 \ 'xxxxxxxxxxxxxxxxx',
811 \ 'xxxxxxxxxxxxxxxxx',
812 \])
813
814 call cursor(2, 2)
815 redraw
816 let winid = popup_atcursor('vim', {})
817 redraw
818 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
819 call assert_equal('xvimxxxxxxxxxxxxx', line)
820 call popup_close(winid)
821
822 call cursor(3, 4)
823 redraw
824 let winid = popup_atcursor('vim', {})
825 redraw
826 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
827 call assert_equal('xxxvimxxxxxxxxxxx', line)
828 call popup_close(winid)
829
830 call cursor(1, 1)
831 redraw
832 let winid = popup_create('vim', {
833 \ 'line': 'cursor+2',
834 \ 'col': 'cursor+1',
835 \})
836 redraw
837 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
838 call assert_equal('xvimxxxxxxxxxxxxx', line)
839 call popup_close(winid)
840
841 call cursor(3, 3)
842 redraw
843 let winid = popup_create('vim', {
844 \ 'line': 'cursor-2',
845 \ 'col': 'cursor-1',
846 \})
847 redraw
848 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
849 call assert_equal('xvimxxxxxxxxxxxxx', line)
850 call popup_close(winid)
851
Bram Moolenaar402502d2019-05-30 22:07:36 +0200852 " just enough room above
853 call cursor(3, 3)
854 redraw
855 let winid = popup_atcursor(['vim', 'is great'], {})
856 redraw
857 let pos = popup_getpos(winid)
858 call assert_equal(1, pos.line)
859 call popup_close(winid)
860
861 " not enough room above, popup goes below the cursor
862 call cursor(3, 3)
863 redraw
864 let winid = popup_atcursor(['vim', 'is', 'great'], {})
865 redraw
866 let pos = popup_getpos(winid)
867 call assert_equal(4, pos.line)
868 call popup_close(winid)
869
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200870 " cursor in first line, popup in line 2
871 call cursor(1, 1)
872 redraw
873 let winid = popup_atcursor(['vim', 'is', 'great'], {})
874 redraw
875 let pos = popup_getpos(winid)
876 call assert_equal(2, pos.line)
877 call popup_close(winid)
878
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200879 bwipe!
880endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200881
882func Test_popup_filter()
883 new
884 call setline(1, 'some text')
885
886 func MyPopupFilter(winid, c)
887 if a:c == 'e'
888 let g:eaten = 'e'
889 return 1
890 endif
891 if a:c == '0'
892 let g:ignored = '0'
893 return 0
894 endif
895 if a:c == 'x'
896 call popup_close(a:winid)
897 return 1
898 endif
899 return 0
900 endfunc
901
902 let winid = popup_create('something', {'filter': 'MyPopupFilter'})
903 redraw
904
905 " e is consumed by the filter
906 call feedkeys('e', 'xt')
907 call assert_equal('e', g:eaten)
908
909 " 0 is ignored by the filter
910 normal $
911 call assert_equal(9, getcurpos()[2])
912 call feedkeys('0', 'xt')
913 call assert_equal('0', g:ignored)
914 call assert_equal(1, getcurpos()[2])
915
916 " x closes the popup
917 call feedkeys('x', 'xt')
918 call assert_equal('e', g:eaten)
919 call assert_equal(-1, winbufnr(winid))
920
921 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200922 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200923endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200924
Bram Moolenaara42d9452019-06-15 21:46:30 +0200925func ShowDialog(key, result)
926 let s:cb_res = 999
927 let winid = popup_dialog('do you want to quit (Yes/no)?', {
928 \ 'filter': 'popup_filter_yesno',
929 \ 'callback': 'QuitCallback',
930 \ })
931 redraw
932 call feedkeys(a:key, "xt")
933 call assert_equal(winid, s:cb_winid)
934 call assert_equal(a:result, s:cb_res)
935endfunc
936
937func Test_popup_dialog()
938 func QuitCallback(id, res)
939 let s:cb_winid = a:id
940 let s:cb_res = a:res
941 endfunc
942
943 let winid = ShowDialog("y", 1)
944 let winid = ShowDialog("Y", 1)
945 let winid = ShowDialog("n", 0)
946 let winid = ShowDialog("N", 0)
947 let winid = ShowDialog("x", 0)
948 let winid = ShowDialog("X", 0)
949 let winid = ShowDialog("\<Esc>", 0)
950 let winid = ShowDialog("\<C-C>", -1)
951
952 delfunc QuitCallback
953endfunc
954
Bram Moolenaara730e552019-06-16 19:05:31 +0200955func ShowMenu(key, result)
956 let s:cb_res = 999
957 let winid = popup_menu(['one', 'two', 'something else'], {
958 \ 'callback': 'QuitCallback',
959 \ })
960 redraw
961 call feedkeys(a:key, "xt")
962 call assert_equal(winid, s:cb_winid)
963 call assert_equal(a:result, s:cb_res)
964endfunc
965
966func Test_popup_menu()
967 func QuitCallback(id, res)
968 let s:cb_winid = a:id
969 let s:cb_res = a:res
970 endfunc
971
972 let winid = ShowMenu(" ", 1)
973 let winid = ShowMenu("j \<CR>", 2)
974 let winid = ShowMenu("JjK \<CR>", 2)
975 let winid = ShowMenu("jjjjjj ", 3)
976 let winid = ShowMenu("kkk ", 1)
977 let winid = ShowMenu("x", -1)
978 let winid = ShowMenu("X", -1)
979 let winid = ShowMenu("\<Esc>", -1)
980 let winid = ShowMenu("\<C-C>", -1)
981
982 delfunc QuitCallback
983endfunc
984
985func Test_popup_menu_screenshot()
986 if !CanRunVimInTerminal()
987 throw 'Skipped: cannot make screendumps'
988 endif
989
990 let lines =<< trim END
991 call setline(1, range(1, 20))
992 hi PopupSelected ctermbg=lightblue
Bram Moolenaareb2310d2019-06-16 20:09:10 +0200993 call popup_menu(['one', 'two', 'another'], {'callback': 'MenuDone', 'title': ' make a choice from the list '})
Bram Moolenaara730e552019-06-16 19:05:31 +0200994 func MenuDone(id, res)
995 echomsg "selected " .. a:res
996 endfunc
997 END
998 call writefile(lines, 'XtestPopupMenu')
999 let buf = RunVimInTerminal('-S XtestPopupMenu', {'rows': 10})
1000 call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {})
1001
1002 call term_sendkeys(buf, "jj")
1003 call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {})
1004
1005 call term_sendkeys(buf, " ")
1006 call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {})
1007
1008 " clean up
1009 call StopVimInTerminal(buf)
1010 call delete('XtestPopupMenu')
1011endfunc
1012
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001013func Test_popup_title()
1014 if !CanRunVimInTerminal()
1015 throw 'Skipped: cannot make screendumps'
1016 endif
1017
1018 " Create a popup without title or border, a line of padding will be added to
1019 " put the title on.
1020 let lines =<< trim END
1021 call setline(1, range(1, 20))
1022 call popup_create(['one', 'two', 'another'], {'title': 'Title String'})
1023 END
1024 call writefile(lines, 'XtestPopupTitle')
1025 let buf = RunVimInTerminal('-S XtestPopupTitle', {'rows': 10})
1026 call VerifyScreenDump(buf, 'Test_popupwin_title', {})
1027
1028 " clean up
1029 call StopVimInTerminal(buf)
1030 call delete('XtestPopupTitle')
Bram Moolenaarae943152019-06-16 22:54:14 +02001031
1032 let winid = popup_create('something', {'title': 'Some Title'})
1033 call assert_equal('Some Title', popup_getoptions(winid).title)
1034 call popup_setoptions(winid, {'title': 'Another Title'})
1035 call assert_equal('Another Title', popup_getoptions(winid).title)
1036
1037 call popup_clear()
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001038endfunc
1039
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001040func Test_popup_close_callback()
1041 func PopupDone(id, result)
1042 let g:result = a:result
1043 endfunc
1044 let winid = popup_create('something', {'callback': 'PopupDone'})
1045 redraw
1046 call popup_close(winid, 'done')
1047 call assert_equal('done', g:result)
1048endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001049
1050func Test_popup_empty()
1051 let winid = popup_create('', {'padding': [2,2,2,2]})
1052 redraw
1053 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001054 call assert_equal(5, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001055 call assert_equal(5, pos.height)
1056
1057 let winid = popup_create([], {'border': []})
1058 redraw
1059 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001060 call assert_equal(3, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001061 call assert_equal(3, pos.height)
1062endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +02001063
1064func Test_popup_never_behind()
1065 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +02001066 throw 'Skipped: cannot make screendumps'
Bram Moolenaar988c4332019-06-02 14:12:11 +02001067 endif
1068 " +-----------------------------+
1069 " | | |
1070 " | | |
1071 " | | |
1072 " | line1 |
1073 " |------------line2------------|
1074 " | line3 |
1075 " | line4 |
1076 " | |
1077 " | |
1078 " +-----------------------------+
1079 let lines =<< trim END
1080 only
1081 split
1082 vsplit
1083 let info_window1 = getwininfo()[0]
1084 let line = info_window1['height']
1085 let col = info_window1['width']
1086 call popup_create(['line1', 'line2', 'line3', 'line4'], {
1087 \ 'line' : line,
1088 \ 'col' : col,
1089 \ })
1090 END
1091 call writefile(lines, 'XtestPopupBehind')
1092 let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10})
1093 call term_sendkeys(buf, "\<C-W>w")
1094 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
1095
1096 " clean up
1097 call StopVimInTerminal(buf)
1098 call delete('XtestPopupBehind')
1099endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001100
1101func s:VerifyPosition( p, msg, line, col, width, height )
1102 call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' )
1103 call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' )
1104 call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' )
1105 call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' )
1106endfunc
1107
1108func Test_popup_position_adjust()
1109 " Anything placed past 2 cells from of the right of the screen is moved to the
1110 " left.
1111 "
1112 " When wrapping is disabled, we also shift to the left to display on the
1113 " screen, unless fixed is set.
1114
1115 " Entries for cases which don't vary based on wrapping.
1116 " Format is per tests described below
1117 let both_wrap_tests = [
1118 \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ],
1119 \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ],
1120 \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ],
1121 \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ],
1122 \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ],
1123 \
1124 \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ],
1125 \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ],
1126 \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ],
1127 \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ],
1128 \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ],
1129 \
1130 \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ],
1131 \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
1132 \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
1133 \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
1134 \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ],
1135 \ ]
1136
1137 " these test groups are dicts with:
1138 " - comment: something to identify the group of tests by
1139 " - options: dict of options to merge with the row/col in tests
1140 " - tests: list of cases. Each one is a list with elements:
1141 " - text
1142 " - row
1143 " - col
1144 " - expected row
1145 " - expected col
1146 " - expected width
1147 " - expected height
1148 let tests = [
1149 \ {
1150 \ 'comment': 'left-aligned with wrapping',
1151 \ 'options': {
1152 \ 'wrap': 1,
1153 \ 'pos': 'botleft',
1154 \ },
1155 \ 'tests': both_wrap_tests + [
1156 \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ],
1157 \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ],
1158 \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ],
1159 \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ],
1160 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1161 \ ],
1162 \ },
1163 \ {
1164 \ 'comment': 'left aligned without wrapping',
1165 \ 'options': {
1166 \ 'wrap': 0,
1167 \ 'pos': 'botleft',
1168 \ },
1169 \ 'tests': both_wrap_tests + [
1170 \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ],
1171 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ],
1172 \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ],
1173 \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ],
1174 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1175 \ ],
1176 \ },
1177 \ {
1178 \ 'comment': 'left aligned with fixed position',
1179 \ 'options': {
1180 \ 'wrap': 0,
1181 \ 'fixed': 1,
1182 \ 'pos': 'botleft',
1183 \ },
1184 \ 'tests': both_wrap_tests + [
1185 \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ],
1186 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
1187 \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
1188 \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
1189 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1190 \ ],
1191 \ },
1192 \ ]
1193
1194 for test_group in tests
1195 for test in test_group.tests
1196 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
1197 let options = {
1198 \ 'line': line,
1199 \ 'col': col,
1200 \ }
1201 call extend( options, test_group.options )
1202
1203 let p = popup_create( text, options )
1204
1205 let msg = string( extend( options, { 'text': text } ) )
1206 call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height )
1207 call popup_close( p )
1208 endfor
1209 endfor
1210
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001211 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001212 %bwipe!
1213endfunc
1214
Bram Moolenaar3397f742019-06-02 18:40:06 +02001215func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001216 " width of screen
1217 let X = join(map(range(&columns), {->'X'}), '')
1218
1219 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
1220 call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 )
1221
1222 redraw
1223 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1224 call assert_equal(X, line)
1225
1226 call popup_close( p )
1227 redraw
1228
1229 " Same if placed on the right hand side
1230 let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } )
1231 call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 )
1232
1233 redraw
1234 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1235 call assert_equal(X, line)
1236
1237 call popup_close( p )
1238 redraw
1239
1240 " Extend so > window width
1241 let X .= 'x'
1242
1243 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
1244 call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 )
1245
1246 redraw
1247 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1248 call assert_equal(X[ : -2 ], line)
1249
1250 call popup_close( p )
1251 redraw
1252
1253 " Shifted then truncated (the x is not visible)
1254 let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } )
1255 call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 )
1256
1257 redraw
1258 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1259 call assert_equal(X[ : -2 ], line)
1260
1261 call popup_close( p )
1262 redraw
1263
1264 " Not shifted, just truncated
1265 let p = popup_create( X,
1266 \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } )
1267 call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
1268
1269 redraw
1270 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1271 let e_line = ' ' . X[ 1 : -2 ]
1272 call assert_equal(e_line, line)
1273
1274 call popup_close( p )
1275 redraw
1276
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001277 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001278 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001279endfunc
1280
1281func Test_popup_moved()
1282 new
1283 call test_override('char_avail', 1)
1284 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1285
1286 exe "normal gg0/word\<CR>"
1287 let winid = popup_atcursor('text', {'moved': 'any'})
1288 redraw
1289 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001290 call assert_equal([4, 4], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001291 " trigger the check for last_cursormoved by going into insert mode
1292 call feedkeys("li\<Esc>", 'xt')
1293 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001294 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001295
1296 exe "normal gg0/word\<CR>"
1297 let winid = popup_atcursor('text', {'moved': 'word'})
1298 redraw
1299 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001300 call assert_equal([4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001301 call feedkeys("hi\<Esc>", 'xt')
1302 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001303 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001304
1305 exe "normal gg0/word\<CR>"
1306 let winid = popup_atcursor('text', {'moved': 'word'})
1307 redraw
1308 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001309 call assert_equal([4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001310 call feedkeys("li\<Esc>", 'xt')
1311 call assert_equal(1, popup_getpos(winid).visible)
1312 call feedkeys("ei\<Esc>", 'xt')
1313 call assert_equal(1, popup_getpos(winid).visible)
1314 call feedkeys("eli\<Esc>", 'xt')
1315 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001316 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001317
Bram Moolenaar17627312019-06-02 19:53:44 +02001318 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001319 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001320 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001321 redraw
1322 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001323 call assert_equal([2, 15], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001324 call feedkeys("eli\<Esc>", 'xt')
1325 call assert_equal(1, popup_getpos(winid).visible)
1326 call feedkeys("wi\<Esc>", 'xt')
1327 call assert_equal(1, popup_getpos(winid).visible)
1328 call feedkeys("Eli\<Esc>", 'xt')
1329 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001330 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001331
1332 exe "normal gg0/word\<CR>"
1333 let winid = popup_atcursor('text', {'moved': [5, 10]})
1334 redraw
1335 call assert_equal(1, popup_getpos(winid).visible)
1336 call feedkeys("eli\<Esc>", 'xt')
1337 call feedkeys("ei\<Esc>", 'xt')
1338 call assert_equal(1, popup_getpos(winid).visible)
1339 call feedkeys("eli\<Esc>", 'xt')
1340 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001341 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001342
1343 bwipe!
1344 call test_override('ALL', 0)
1345endfunc
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001346
1347func Test_notifications()
1348 if !has('timers')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02001349 throw 'Skipped: timer feature not supported'
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001350 endif
1351 if !CanRunVimInTerminal()
1352 throw 'Skipped: cannot make screendumps'
1353 endif
1354
1355 call writefile([
1356 \ "call setline(1, range(1, 20))",
1357 \ "hi Notification ctermbg=lightblue",
1358 \ "call popup_notification('first notification', {})",
1359 \], 'XtestNotifications')
1360 let buf = RunVimInTerminal('-S XtestNotifications', {'rows': 10})
1361 call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {})
1362
1363 " second one goes below the first one
Bram Moolenaardfa97f22019-06-15 14:31:55 +02001364 call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>")
1365 call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>")
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001366 call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {})
1367
1368
1369 " clean up
1370 call StopVimInTerminal(buf)
1371 call delete('XtestNotifications')
1372endfunc
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001373
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001374func Test_popup_settext()
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001375 if !CanRunVimInTerminal()
1376 throw 'Skipped: cannot make screendumps'
1377 endif
1378
1379 let lines =<< trim END
1380 let opts = {'wrap': 0}
1381 let p = popup_create('test', opts)
1382 call popup_settext(p, 'this is a text')
1383 END
1384
1385 call writefile( lines, 'XtestPopupSetText' )
1386 let buf = RunVimInTerminal('-S XtestPopupSetText', {'rows': 10})
1387 call VerifyScreenDump(buf, 'Test_popup_settext_01', {})
1388
1389 " Setting to empty string clears it
1390 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>")
1391 call VerifyScreenDump(buf, 'Test_popup_settext_02', {})
1392
1393 " Setting a list
1394 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1395 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1396
1397 " Shrinking with a list
1398 call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>")
1399 call VerifyScreenDump(buf, 'Test_popup_settext_04', {})
1400
1401 " Growing with a list
1402 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1403 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1404
1405 " Empty list clears
1406 call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>")
1407 call VerifyScreenDump(buf, 'Test_popup_settext_05', {})
1408
1409 " Dicts
1410 call term_sendkeys(buf, ":call popup_settext(p, [{'text': 'aaaa'}, {'text': 'bbbb'}, {'text': 'cccc'}])\<CR>")
1411 call VerifyScreenDump(buf, 'Test_popup_settext_06', {})
1412
1413 " clean up
1414 call StopVimInTerminal(buf)
1415 call delete('XtestPopupSetText')
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001416endfunc
1417
1418func Test_popup_hidden()
1419 new
1420
1421 let winid = popup_atcursor('text', {'hidden': 1})
1422 redraw
1423 call assert_equal(0, popup_getpos(winid).visible)
1424 call popup_close(winid)
1425
1426 let winid = popup_create('text', {'hidden': 1})
1427 redraw
1428 call assert_equal(0, popup_getpos(winid).visible)
1429 call popup_close(winid)
1430
1431 func QuitCallback(id, res)
1432 let s:cb_winid = a:id
1433 let s:cb_res = a:res
1434 endfunc
1435 let winid = popup_dialog('make a choice', {'hidden': 1,
1436 \ 'filter': 'popup_filter_yesno',
1437 \ 'callback': 'QuitCallback',
1438 \ })
1439 redraw
1440 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001441 call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter)
1442 call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback)
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001443 exe "normal anot used by filter\<Esc>"
1444 call assert_equal('not used by filter', getline(1))
1445
1446 call popup_show(winid)
1447 call feedkeys('y', "xt")
1448 call assert_equal(1, s:cb_res)
1449
1450 bwipe!
1451 delfunc QuitCallback
1452endfunc
Bram Moolenaarae943152019-06-16 22:54:14 +02001453
1454" Test options not checked elsewhere
1455func Test_set_get_options()
1456 let winid = popup_create('some text', {'highlight': 'Beautiful'})
1457 let options = popup_getoptions(winid)
1458 call assert_equal(1, options.wrap)
1459 call assert_equal(0, options.drag)
1460 call assert_equal('Beautiful', options.highlight)
1461
1462 call popup_setoptions(winid, {'wrap': 0, 'drag': 1, 'highlight': 'Another'})
1463 let options = popup_getoptions(winid)
1464 call assert_equal(0, options.wrap)
1465 call assert_equal(1, options.drag)
1466 call assert_equal('Another', options.highlight)
1467
1468 call popup_close(winid)
1469endfunc