blob: 7d723a0662258995518977e8ee913ded8c127f73 [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)
401 tabnew
402 call assert_equal(0, popup_getpos(winid).visible)
403 quit
404 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200405
406 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200407 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200408 " buffer is gone now
409 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200410
411 " global popup is visible in any tab
Bram Moolenaarfc06cbb2019-06-15 14:14:31 +0200412 let winid = popup_create("text", {'tabpage': -1})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200413 call assert_equal(1, popup_getpos(winid).visible)
414 tabnew
415 call assert_equal(1, popup_getpos(winid).visible)
416 quit
417 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200418 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200419endfunc
420
421func Test_popup_valid_arguments()
422 " Zero value is like the property wasn't there
423 let winid = popup_create("text", {"col": 0})
424 let pos = popup_getpos(winid)
425 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200426 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200427
428 " using cursor column has minimum value of 1
429 let winid = popup_create("text", {"col": 'cursor-100'})
430 let pos = popup_getpos(winid)
431 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200432 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200433
434 " center
435 let winid = popup_create("text", {"pos": 'center'})
436 let pos = popup_getpos(winid)
437 let around = (&columns - pos.width) / 2
438 call assert_inrange(around - 1, around + 1, pos.col)
439 let around = (&lines - pos.height) / 2
440 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200441 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200442endfunc
443
444func Test_popup_invalid_arguments()
445 call assert_fails('call popup_create(666, {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200446 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200447 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200448 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200449
450 call assert_fails('call popup_create("text", {"col": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200451 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200452 call assert_fails('call popup_create("text", {"col": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200453 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200454 call assert_fails('call popup_create("text", {"col": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200455 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200456 call assert_fails('call popup_create("text", {"col": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200457 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200458
459 call assert_fails('call popup_create("text", {"line": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200460 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200461 call assert_fails('call popup_create("text", {"line": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200462 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200463 call assert_fails('call popup_create("text", {"line": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200464 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200465 call assert_fails('call popup_create("text", {"line": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200466 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200467
468 call assert_fails('call popup_create("text", {"pos": "there"})', 'E475:')
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", {"padding": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200471 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200472 call assert_fails('call popup_create("text", {"border": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200473 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200474 call assert_fails('call popup_create("text", {"borderhighlight": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200475 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200476 call assert_fails('call popup_create("text", {"borderchars": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200477 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200478
479 call assert_fails('call popup_create([{"text": "text"}, 666], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200480 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200481 call assert_fails('call popup_create([{"text": "text", "props": "none"}], {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200482 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200483 call assert_fails('call popup_create([{"text": "text", "props": ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200484 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200485endfunc
486
Bram Moolenaareea16992019-05-31 17:34:48 +0200487func Test_win_execute_closing_curwin()
488 split
489 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200490 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200491 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200492endfunc
493
494func Test_win_execute_not_allowed()
495 let winid = popup_create('some text', {})
496 call assert_fails('call win_execute(winid, "split")', 'E994:')
497 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
498 call assert_fails('call win_execute(winid, "close")', 'E994:')
499 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200500 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200501 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
502 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
503 call assert_fails('call win_execute(winid, "next")', 'E994:')
504 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
505 call assert_fails('call win_execute(winid, "buf")', 'E994:')
506 call assert_fails('call win_execute(winid, "edit")', 'E994:')
507 call assert_fails('call win_execute(winid, "enew")', 'E994:')
508 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
509 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
510 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
511 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200512 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200513endfunc
514
Bram Moolenaar402502d2019-05-30 22:07:36 +0200515func Test_popup_with_wrap()
516 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200517 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200518 endif
519 let lines =<< trim END
520 call setline(1, range(1, 100))
521 let winid = popup_create(
522 \ 'a long line that wont fit',
523 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
524 END
525 call writefile(lines, 'XtestPopup')
526 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
527 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
528
529 " clean up
530 call StopVimInTerminal(buf)
531 call delete('XtestPopup')
532endfunc
533
534func Test_popup_without_wrap()
535 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200536 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200537 endif
538 let lines =<< trim END
539 call setline(1, range(1, 100))
540 let winid = popup_create(
541 \ 'a long line that wont fit',
542 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
543 END
544 call writefile(lines, 'XtestPopup')
545 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
546 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
547
548 " clean up
549 call StopVimInTerminal(buf)
550 call delete('XtestPopup')
551endfunc
552
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200553func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200554 if !has('timers')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +0200555 throw 'Skipped: timer feature not supported'
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200556 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200557 topleft vnew
558 call setline(1, 'hello')
559
560 call popup_create('world', {
561 \ 'line': 1,
562 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200563 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200564 \ 'time': 500,
565 \})
566 redraw
567 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
568 call assert_equal('world', line)
569
570 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200571 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200572 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
573 call assert_equal('hello', line)
574
575 call popup_create('on the command line', {
576 \ 'line': &lines,
577 \ 'col': 10,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200578 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200579 \ 'time': 500,
580 \})
581 redraw
582 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
583 call assert_match('.*on the command line.*', line)
584
585 sleep 700m
586 redraw
587 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
588 call assert_notmatch('.*on the command line.*', line)
589
590 bwipe!
591endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200592
593func Test_popup_hide()
594 topleft vnew
595 call setline(1, 'hello')
596
597 let winid = popup_create('world', {
598 \ 'line': 1,
599 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200600 \ 'minwidth': 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200601 \})
602 redraw
603 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
604 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200605 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200606 " buffer is still listed and active
607 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200608
609 call popup_hide(winid)
610 redraw
611 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
612 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200613 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200614 " buffer is still listed but hidden
615 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200616
617 call popup_show(winid)
618 redraw
619 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
620 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200621 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200622
623
624 call popup_close(winid)
625 redraw
626 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
627 call assert_equal('hello', line)
628
629 " error is given for existing non-popup window
630 call assert_fails('call popup_hide(win_getid())', 'E993:')
631
632 " no error non-existing window
633 call popup_hide(1234234)
634 call popup_show(41234234)
635
636 bwipe!
637endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200638
639func Test_popup_move()
640 topleft vnew
641 call setline(1, 'hello')
642
643 let winid = popup_create('world', {
644 \ 'line': 1,
645 \ 'col': 1,
646 \ 'minwidth': 20,
647 \})
648 redraw
649 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
650 call assert_equal('world ', line)
651
652 call popup_move(winid, {'line': 2, 'col': 2})
653 redraw
654 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
655 call assert_equal('hello ', line)
656 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
657 call assert_equal('~world', line)
658
659 call popup_move(winid, {'line': 1})
660 redraw
661 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
662 call assert_equal('hworld', line)
663
664 call popup_close(winid)
665
666 bwipe!
667endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200668
Bram Moolenaar402502d2019-05-30 22:07:36 +0200669func Test_popup_getpos()
Bram Moolenaarbc133542019-05-29 20:26:46 +0200670 let winid = popup_create('hello', {
671 \ 'line': 2,
672 \ 'col': 3,
673 \ 'minwidth': 10,
674 \ 'minheight': 11,
675 \})
676 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200677 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200678 call assert_equal(2, res.line)
679 call assert_equal(3, res.col)
680 call assert_equal(10, res.width)
681 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200682 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200683
684 call popup_close(winid)
685endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200686
687func Test_popup_width_longest()
688 let tests = [
689 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
690 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
691 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
692 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
693 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
694 \ ]
695
696 for test in tests
697 let winid = popup_create(test[0], {'line': 2, 'col': 3})
698 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200699 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200700 call assert_equal(test[1], position.width)
701 call popup_close(winid)
702 endfor
703endfunc
704
705func Test_popup_wraps()
706 let tests = [
707 \ ['nowrap', 6, 1],
708 \ ['a line that wraps once', 12, 2],
709 \ ['a line that wraps two times', 12, 3],
710 \ ]
711 for test in tests
712 let winid = popup_create(test[0],
713 \ {'line': 2, 'col': 3, 'maxwidth': 12})
714 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200715 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200716 call assert_equal(test[1], position.width)
717 call assert_equal(test[2], position.height)
718
719 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200720 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200721 endfor
722endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200723
724func Test_popup_getoptions()
725 let winid = popup_create('hello', {
726 \ 'line': 2,
727 \ 'col': 3,
728 \ 'minwidth': 10,
729 \ 'minheight': 11,
730 \ 'maxwidth': 20,
731 \ 'maxheight': 21,
732 \ 'zindex': 100,
733 \ 'time': 5000,
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200734 \ 'fixed': 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200735 \})
736 redraw
737 let res = popup_getoptions(winid)
738 call assert_equal(2, res.line)
739 call assert_equal(3, res.col)
740 call assert_equal(10, res.minwidth)
741 call assert_equal(11, res.minheight)
742 call assert_equal(20, res.maxwidth)
743 call assert_equal(21, res.maxheight)
744 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200745 call assert_equal(1, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200746 if has('timers')
747 call assert_equal(5000, res.time)
748 endif
749 call popup_close(winid)
750
751 let winid = popup_create('hello', {})
752 redraw
753 let res = popup_getoptions(winid)
754 call assert_equal(0, res.line)
755 call assert_equal(0, res.col)
756 call assert_equal(0, res.minwidth)
757 call assert_equal(0, res.minheight)
758 call assert_equal(0, res.maxwidth)
759 call assert_equal(0, res.maxheight)
760 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200761 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200762 if has('timers')
763 call assert_equal(0, res.time)
764 endif
765 call popup_close(winid)
766 call assert_equal({}, popup_getoptions(winid))
767endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200768
769func Test_popup_option_values()
770 new
771 " window-local
772 setlocal number
773 setlocal nowrap
774 " buffer-local
775 setlocal omnifunc=Something
776 " global/buffer-local
777 setlocal path=/there
778 " global/window-local
779 setlocal scrolloff=9
780
781 let winid = popup_create('hello', {})
782 call assert_equal(0, getwinvar(winid, '&number'))
783 call assert_equal(1, getwinvar(winid, '&wrap'))
784 call assert_equal('', getwinvar(winid, '&omnifunc'))
785 call assert_equal(&g:path, getwinvar(winid, '&path'))
786 call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
787
788 call popup_close(winid)
789 bwipe
790endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200791
792func Test_popup_atcursor()
793 topleft vnew
794 call setline(1, [
795 \ 'xxxxxxxxxxxxxxxxx',
796 \ 'xxxxxxxxxxxxxxxxx',
797 \ 'xxxxxxxxxxxxxxxxx',
798 \])
799
800 call cursor(2, 2)
801 redraw
802 let winid = popup_atcursor('vim', {})
803 redraw
804 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
805 call assert_equal('xvimxxxxxxxxxxxxx', line)
806 call popup_close(winid)
807
808 call cursor(3, 4)
809 redraw
810 let winid = popup_atcursor('vim', {})
811 redraw
812 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
813 call assert_equal('xxxvimxxxxxxxxxxx', line)
814 call popup_close(winid)
815
816 call cursor(1, 1)
817 redraw
818 let winid = popup_create('vim', {
819 \ 'line': 'cursor+2',
820 \ 'col': 'cursor+1',
821 \})
822 redraw
823 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
824 call assert_equal('xvimxxxxxxxxxxxxx', line)
825 call popup_close(winid)
826
827 call cursor(3, 3)
828 redraw
829 let winid = popup_create('vim', {
830 \ 'line': 'cursor-2',
831 \ 'col': 'cursor-1',
832 \})
833 redraw
834 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
835 call assert_equal('xvimxxxxxxxxxxxxx', line)
836 call popup_close(winid)
837
Bram Moolenaar402502d2019-05-30 22:07:36 +0200838 " just enough room above
839 call cursor(3, 3)
840 redraw
841 let winid = popup_atcursor(['vim', 'is great'], {})
842 redraw
843 let pos = popup_getpos(winid)
844 call assert_equal(1, pos.line)
845 call popup_close(winid)
846
847 " not enough room above, popup goes below the cursor
848 call cursor(3, 3)
849 redraw
850 let winid = popup_atcursor(['vim', 'is', 'great'], {})
851 redraw
852 let pos = popup_getpos(winid)
853 call assert_equal(4, pos.line)
854 call popup_close(winid)
855
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200856 " cursor in first line, popup in line 2
857 call cursor(1, 1)
858 redraw
859 let winid = popup_atcursor(['vim', 'is', 'great'], {})
860 redraw
861 let pos = popup_getpos(winid)
862 call assert_equal(2, pos.line)
863 call popup_close(winid)
864
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200865 bwipe!
866endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200867
868func Test_popup_filter()
869 new
870 call setline(1, 'some text')
871
872 func MyPopupFilter(winid, c)
873 if a:c == 'e'
874 let g:eaten = 'e'
875 return 1
876 endif
877 if a:c == '0'
878 let g:ignored = '0'
879 return 0
880 endif
881 if a:c == 'x'
882 call popup_close(a:winid)
883 return 1
884 endif
885 return 0
886 endfunc
887
888 let winid = popup_create('something', {'filter': 'MyPopupFilter'})
889 redraw
890
891 " e is consumed by the filter
892 call feedkeys('e', 'xt')
893 call assert_equal('e', g:eaten)
894
895 " 0 is ignored by the filter
896 normal $
897 call assert_equal(9, getcurpos()[2])
898 call feedkeys('0', 'xt')
899 call assert_equal('0', g:ignored)
900 call assert_equal(1, getcurpos()[2])
901
902 " x closes the popup
903 call feedkeys('x', 'xt')
904 call assert_equal('e', g:eaten)
905 call assert_equal(-1, winbufnr(winid))
906
907 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200908 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200909endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200910
Bram Moolenaara42d9452019-06-15 21:46:30 +0200911func ShowDialog(key, result)
912 let s:cb_res = 999
913 let winid = popup_dialog('do you want to quit (Yes/no)?', {
914 \ 'filter': 'popup_filter_yesno',
915 \ 'callback': 'QuitCallback',
916 \ })
917 redraw
918 call feedkeys(a:key, "xt")
919 call assert_equal(winid, s:cb_winid)
920 call assert_equal(a:result, s:cb_res)
921endfunc
922
923func Test_popup_dialog()
924 func QuitCallback(id, res)
925 let s:cb_winid = a:id
926 let s:cb_res = a:res
927 endfunc
928
929 let winid = ShowDialog("y", 1)
930 let winid = ShowDialog("Y", 1)
931 let winid = ShowDialog("n", 0)
932 let winid = ShowDialog("N", 0)
933 let winid = ShowDialog("x", 0)
934 let winid = ShowDialog("X", 0)
935 let winid = ShowDialog("\<Esc>", 0)
936 let winid = ShowDialog("\<C-C>", -1)
937
938 delfunc QuitCallback
939endfunc
940
Bram Moolenaara730e552019-06-16 19:05:31 +0200941func ShowMenu(key, result)
942 let s:cb_res = 999
943 let winid = popup_menu(['one', 'two', 'something else'], {
944 \ 'callback': 'QuitCallback',
945 \ })
946 redraw
947 call feedkeys(a:key, "xt")
948 call assert_equal(winid, s:cb_winid)
949 call assert_equal(a:result, s:cb_res)
950endfunc
951
952func Test_popup_menu()
953 func QuitCallback(id, res)
954 let s:cb_winid = a:id
955 let s:cb_res = a:res
956 endfunc
957
958 let winid = ShowMenu(" ", 1)
959 let winid = ShowMenu("j \<CR>", 2)
960 let winid = ShowMenu("JjK \<CR>", 2)
961 let winid = ShowMenu("jjjjjj ", 3)
962 let winid = ShowMenu("kkk ", 1)
963 let winid = ShowMenu("x", -1)
964 let winid = ShowMenu("X", -1)
965 let winid = ShowMenu("\<Esc>", -1)
966 let winid = ShowMenu("\<C-C>", -1)
967
968 delfunc QuitCallback
969endfunc
970
971func Test_popup_menu_screenshot()
972 if !CanRunVimInTerminal()
973 throw 'Skipped: cannot make screendumps'
974 endif
975
976 let lines =<< trim END
977 call setline(1, range(1, 20))
978 hi PopupSelected ctermbg=lightblue
Bram Moolenaareb2310d2019-06-16 20:09:10 +0200979 call popup_menu(['one', 'two', 'another'], {'callback': 'MenuDone', 'title': ' make a choice from the list '})
Bram Moolenaara730e552019-06-16 19:05:31 +0200980 func MenuDone(id, res)
981 echomsg "selected " .. a:res
982 endfunc
983 END
984 call writefile(lines, 'XtestPopupMenu')
985 let buf = RunVimInTerminal('-S XtestPopupMenu', {'rows': 10})
986 call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {})
987
988 call term_sendkeys(buf, "jj")
989 call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {})
990
991 call term_sendkeys(buf, " ")
992 call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {})
993
994 " clean up
995 call StopVimInTerminal(buf)
996 call delete('XtestPopupMenu')
997endfunc
998
Bram Moolenaareb2310d2019-06-16 20:09:10 +0200999func Test_popup_title()
1000 if !CanRunVimInTerminal()
1001 throw 'Skipped: cannot make screendumps'
1002 endif
1003
1004 " Create a popup without title or border, a line of padding will be added to
1005 " put the title on.
1006 let lines =<< trim END
1007 call setline(1, range(1, 20))
1008 call popup_create(['one', 'two', 'another'], {'title': 'Title String'})
1009 END
1010 call writefile(lines, 'XtestPopupTitle')
1011 let buf = RunVimInTerminal('-S XtestPopupTitle', {'rows': 10})
1012 call VerifyScreenDump(buf, 'Test_popupwin_title', {})
1013
1014 " clean up
1015 call StopVimInTerminal(buf)
1016 call delete('XtestPopupTitle')
Bram Moolenaarae943152019-06-16 22:54:14 +02001017
1018 let winid = popup_create('something', {'title': 'Some Title'})
1019 call assert_equal('Some Title', popup_getoptions(winid).title)
1020 call popup_setoptions(winid, {'title': 'Another Title'})
1021 call assert_equal('Another Title', popup_getoptions(winid).title)
1022
1023 call popup_clear()
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001024endfunc
1025
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001026func Test_popup_close_callback()
1027 func PopupDone(id, result)
1028 let g:result = a:result
1029 endfunc
1030 let winid = popup_create('something', {'callback': 'PopupDone'})
1031 redraw
1032 call popup_close(winid, 'done')
1033 call assert_equal('done', g:result)
1034endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001035
1036func Test_popup_empty()
1037 let winid = popup_create('', {'padding': [2,2,2,2]})
1038 redraw
1039 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001040 call assert_equal(5, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001041 call assert_equal(5, pos.height)
1042
1043 let winid = popup_create([], {'border': []})
1044 redraw
1045 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001046 call assert_equal(3, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001047 call assert_equal(3, pos.height)
1048endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +02001049
1050func Test_popup_never_behind()
1051 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +02001052 throw 'Skipped: cannot make screendumps'
Bram Moolenaar988c4332019-06-02 14:12:11 +02001053 endif
1054 " +-----------------------------+
1055 " | | |
1056 " | | |
1057 " | | |
1058 " | line1 |
1059 " |------------line2------------|
1060 " | line3 |
1061 " | line4 |
1062 " | |
1063 " | |
1064 " +-----------------------------+
1065 let lines =<< trim END
1066 only
1067 split
1068 vsplit
1069 let info_window1 = getwininfo()[0]
1070 let line = info_window1['height']
1071 let col = info_window1['width']
1072 call popup_create(['line1', 'line2', 'line3', 'line4'], {
1073 \ 'line' : line,
1074 \ 'col' : col,
1075 \ })
1076 END
1077 call writefile(lines, 'XtestPopupBehind')
1078 let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10})
1079 call term_sendkeys(buf, "\<C-W>w")
1080 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
1081
1082 " clean up
1083 call StopVimInTerminal(buf)
1084 call delete('XtestPopupBehind')
1085endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001086
1087func s:VerifyPosition( p, msg, line, col, width, height )
1088 call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' )
1089 call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' )
1090 call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' )
1091 call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' )
1092endfunc
1093
1094func Test_popup_position_adjust()
1095 " Anything placed past 2 cells from of the right of the screen is moved to the
1096 " left.
1097 "
1098 " When wrapping is disabled, we also shift to the left to display on the
1099 " screen, unless fixed is set.
1100
1101 " Entries for cases which don't vary based on wrapping.
1102 " Format is per tests described below
1103 let both_wrap_tests = [
1104 \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ],
1105 \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ],
1106 \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ],
1107 \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ],
1108 \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ],
1109 \
1110 \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ],
1111 \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ],
1112 \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ],
1113 \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ],
1114 \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ],
1115 \
1116 \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ],
1117 \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
1118 \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
1119 \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
1120 \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ],
1121 \ ]
1122
1123 " these test groups are dicts with:
1124 " - comment: something to identify the group of tests by
1125 " - options: dict of options to merge with the row/col in tests
1126 " - tests: list of cases. Each one is a list with elements:
1127 " - text
1128 " - row
1129 " - col
1130 " - expected row
1131 " - expected col
1132 " - expected width
1133 " - expected height
1134 let tests = [
1135 \ {
1136 \ 'comment': 'left-aligned with wrapping',
1137 \ 'options': {
1138 \ 'wrap': 1,
1139 \ 'pos': 'botleft',
1140 \ },
1141 \ 'tests': both_wrap_tests + [
1142 \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ],
1143 \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ],
1144 \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ],
1145 \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ],
1146 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1147 \ ],
1148 \ },
1149 \ {
1150 \ 'comment': 'left aligned without wrapping',
1151 \ 'options': {
1152 \ 'wrap': 0,
1153 \ 'pos': 'botleft',
1154 \ },
1155 \ 'tests': both_wrap_tests + [
1156 \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ],
1157 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ],
1158 \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ],
1159 \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ],
1160 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1161 \ ],
1162 \ },
1163 \ {
1164 \ 'comment': 'left aligned with fixed position',
1165 \ 'options': {
1166 \ 'wrap': 0,
1167 \ 'fixed': 1,
1168 \ 'pos': 'botleft',
1169 \ },
1170 \ 'tests': both_wrap_tests + [
1171 \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ],
1172 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
1173 \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
1174 \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
1175 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
1176 \ ],
1177 \ },
1178 \ ]
1179
1180 for test_group in tests
1181 for test in test_group.tests
1182 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
1183 let options = {
1184 \ 'line': line,
1185 \ 'col': col,
1186 \ }
1187 call extend( options, test_group.options )
1188
1189 let p = popup_create( text, options )
1190
1191 let msg = string( extend( options, { 'text': text } ) )
1192 call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height )
1193 call popup_close( p )
1194 endfor
1195 endfor
1196
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001197 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001198 %bwipe!
1199endfunc
1200
Bram Moolenaar3397f742019-06-02 18:40:06 +02001201func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001202 " width of screen
1203 let X = join(map(range(&columns), {->'X'}), '')
1204
1205 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
1206 call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 )
1207
1208 redraw
1209 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1210 call assert_equal(X, line)
1211
1212 call popup_close( p )
1213 redraw
1214
1215 " Same if placed on the right hand side
1216 let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } )
1217 call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 )
1218
1219 redraw
1220 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1221 call assert_equal(X, line)
1222
1223 call popup_close( p )
1224 redraw
1225
1226 " Extend so > window width
1227 let X .= 'x'
1228
1229 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
1230 call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 )
1231
1232 redraw
1233 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1234 call assert_equal(X[ : -2 ], line)
1235
1236 call popup_close( p )
1237 redraw
1238
1239 " Shifted then truncated (the x is not visible)
1240 let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } )
1241 call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 )
1242
1243 redraw
1244 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1245 call assert_equal(X[ : -2 ], line)
1246
1247 call popup_close( p )
1248 redraw
1249
1250 " Not shifted, just truncated
1251 let p = popup_create( X,
1252 \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } )
1253 call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
1254
1255 redraw
1256 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1257 let e_line = ' ' . X[ 1 : -2 ]
1258 call assert_equal(e_line, line)
1259
1260 call popup_close( p )
1261 redraw
1262
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001263 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001264 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001265endfunc
1266
1267func Test_popup_moved()
1268 new
1269 call test_override('char_avail', 1)
1270 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1271
1272 exe "normal gg0/word\<CR>"
1273 let winid = popup_atcursor('text', {'moved': 'any'})
1274 redraw
1275 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001276 call assert_equal([4, 4], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001277 " trigger the check for last_cursormoved by going into insert mode
1278 call feedkeys("li\<Esc>", 'xt')
1279 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001280 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001281
1282 exe "normal gg0/word\<CR>"
1283 let winid = popup_atcursor('text', {'moved': 'word'})
1284 redraw
1285 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001286 call assert_equal([4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001287 call feedkeys("hi\<Esc>", 'xt')
1288 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001289 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001290
1291 exe "normal gg0/word\<CR>"
1292 let winid = popup_atcursor('text', {'moved': 'word'})
1293 redraw
1294 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001295 call assert_equal([4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001296 call feedkeys("li\<Esc>", 'xt')
1297 call assert_equal(1, popup_getpos(winid).visible)
1298 call feedkeys("ei\<Esc>", 'xt')
1299 call assert_equal(1, popup_getpos(winid).visible)
1300 call feedkeys("eli\<Esc>", 'xt')
1301 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001302 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001303
Bram Moolenaar17627312019-06-02 19:53:44 +02001304 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001305 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001306 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001307 redraw
1308 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001309 call assert_equal([2, 15], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001310 call feedkeys("eli\<Esc>", 'xt')
1311 call assert_equal(1, popup_getpos(winid).visible)
1312 call feedkeys("wi\<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
1318 exe "normal gg0/word\<CR>"
1319 let winid = popup_atcursor('text', {'moved': [5, 10]})
1320 redraw
1321 call assert_equal(1, popup_getpos(winid).visible)
1322 call feedkeys("eli\<Esc>", 'xt')
1323 call feedkeys("ei\<Esc>", 'xt')
1324 call assert_equal(1, popup_getpos(winid).visible)
1325 call feedkeys("eli\<Esc>", 'xt')
1326 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001327 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001328
1329 bwipe!
1330 call test_override('ALL', 0)
1331endfunc
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001332
1333func Test_notifications()
1334 if !has('timers')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02001335 throw 'Skipped: timer feature not supported'
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001336 endif
1337 if !CanRunVimInTerminal()
1338 throw 'Skipped: cannot make screendumps'
1339 endif
1340
1341 call writefile([
1342 \ "call setline(1, range(1, 20))",
1343 \ "hi Notification ctermbg=lightblue",
1344 \ "call popup_notification('first notification', {})",
1345 \], 'XtestNotifications')
1346 let buf = RunVimInTerminal('-S XtestNotifications', {'rows': 10})
1347 call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {})
1348
1349 " second one goes below the first one
Bram Moolenaardfa97f22019-06-15 14:31:55 +02001350 call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>")
1351 call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>")
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001352 call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {})
1353
1354
1355 " clean up
1356 call StopVimInTerminal(buf)
1357 call delete('XtestNotifications')
1358endfunc
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001359
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001360func Test_popup_settext()
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001361 if !CanRunVimInTerminal()
1362 throw 'Skipped: cannot make screendumps'
1363 endif
1364
1365 let lines =<< trim END
1366 let opts = {'wrap': 0}
1367 let p = popup_create('test', opts)
1368 call popup_settext(p, 'this is a text')
1369 END
1370
1371 call writefile( lines, 'XtestPopupSetText' )
1372 let buf = RunVimInTerminal('-S XtestPopupSetText', {'rows': 10})
1373 call VerifyScreenDump(buf, 'Test_popup_settext_01', {})
1374
1375 " Setting to empty string clears it
1376 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>")
1377 call VerifyScreenDump(buf, 'Test_popup_settext_02', {})
1378
1379 " Setting a list
1380 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1381 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1382
1383 " Shrinking with a list
1384 call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>")
1385 call VerifyScreenDump(buf, 'Test_popup_settext_04', {})
1386
1387 " Growing with a list
1388 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1389 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1390
1391 " Empty list clears
1392 call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>")
1393 call VerifyScreenDump(buf, 'Test_popup_settext_05', {})
1394
1395 " Dicts
1396 call term_sendkeys(buf, ":call popup_settext(p, [{'text': 'aaaa'}, {'text': 'bbbb'}, {'text': 'cccc'}])\<CR>")
1397 call VerifyScreenDump(buf, 'Test_popup_settext_06', {})
1398
1399 " clean up
1400 call StopVimInTerminal(buf)
1401 call delete('XtestPopupSetText')
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001402endfunc
1403
1404func Test_popup_hidden()
1405 new
1406
1407 let winid = popup_atcursor('text', {'hidden': 1})
1408 redraw
1409 call assert_equal(0, popup_getpos(winid).visible)
1410 call popup_close(winid)
1411
1412 let winid = popup_create('text', {'hidden': 1})
1413 redraw
1414 call assert_equal(0, popup_getpos(winid).visible)
1415 call popup_close(winid)
1416
1417 func QuitCallback(id, res)
1418 let s:cb_winid = a:id
1419 let s:cb_res = a:res
1420 endfunc
1421 let winid = popup_dialog('make a choice', {'hidden': 1,
1422 \ 'filter': 'popup_filter_yesno',
1423 \ 'callback': 'QuitCallback',
1424 \ })
1425 redraw
1426 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001427 call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter)
1428 call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback)
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001429 exe "normal anot used by filter\<Esc>"
1430 call assert_equal('not used by filter', getline(1))
1431
1432 call popup_show(winid)
1433 call feedkeys('y', "xt")
1434 call assert_equal(1, s:cb_res)
1435
1436 bwipe!
1437 delfunc QuitCallback
1438endfunc
Bram Moolenaarae943152019-06-16 22:54:14 +02001439
1440" Test options not checked elsewhere
1441func Test_set_get_options()
1442 let winid = popup_create('some text', {'highlight': 'Beautiful'})
1443 let options = popup_getoptions(winid)
1444 call assert_equal(1, options.wrap)
1445 call assert_equal(0, options.drag)
1446 call assert_equal('Beautiful', options.highlight)
1447
1448 call popup_setoptions(winid, {'wrap': 0, 'drag': 1, 'highlight': 'Another'})
1449 let options = popup_getoptions(winid)
1450 call assert_equal(0, options.wrap)
1451 call assert_equal(1, options.drag)
1452 call assert_equal('Another', options.highlight)
1453
1454 call popup_close(winid)
1455endfunc