blob: 6def8e45a9da7f4c0e8249448c21fdd230d99f80 [file] [log] [blame]
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001" Tests for popup windows
2
3if !has('textprop')
Bram Moolenaar5d30ff12019-06-06 16:12:12 +02004 throw 'Skipped: textprop feature missing'
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005endif
6
7source screendump.vim
8
9func Test_simple_popup()
10 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +020011 throw 'Skipped: cannot make screendumps'
Bram Moolenaar4d784b22019-05-25 19:51:39 +020012 endif
13 call writefile([
14 \ "call setline(1, range(1, 100))",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020015 \ "hi PopupColor1 ctermbg=lightblue",
16 \ "hi PopupColor2 ctermbg=lightcyan",
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020017 \ "hi Comment ctermfg=red",
18 \ "call prop_type_add('comment', {'highlight': 'Comment'})",
Bram Moolenaar60cdb302019-05-27 21:54:10 +020019 \ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})",
20 \ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25, 'minwidth': 20})",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020021 \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
Bram Moolenaar4d784b22019-05-25 19:51:39 +020022 \], 'XtestPopup')
23 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
24 call VerifyScreenDump(buf, 'Test_popupwin_01', {})
25
Bram Moolenaarec583842019-05-26 14:11:23 +020026 " Add a tabpage
27 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020028 call term_sendkeys(buf, ":let popupwin = popup_create(["
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020029 \ .. "{'text': 'other tab'},"
30 \ .. "{'text': 'a comment line', 'props': [{"
Bram Moolenaar60cdb302019-05-27 21:54:10 +020031 \ .. "'col': 3, 'length': 7, 'minwidth': 20, 'type': 'comment'"
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020032 \ .. "}]},"
Bram Moolenaar60cdb302019-05-27 21:54:10 +020033 \ .. "], {'line': 4, 'col': 9, 'minwidth': 20})\<CR>")
Bram Moolenaarec583842019-05-26 14:11:23 +020034 call VerifyScreenDump(buf, 'Test_popupwin_02', {})
35
36 " switch back to first tabpage
37 call term_sendkeys(buf, "gt")
38 call VerifyScreenDump(buf, 'Test_popupwin_03', {})
39
40 " close that tabpage
41 call term_sendkeys(buf, ":quit!\<CR>")
42 call VerifyScreenDump(buf, 'Test_popupwin_04', {})
43
Bram Moolenaar202d9822019-06-11 21:56:30 +020044 " set 'columns' to a small value, size must be recomputed
45 call term_sendkeys(buf, ":let cols = &columns\<CR>")
46 call term_sendkeys(buf, ":set columns=12\<CR>")
47 call VerifyScreenDump(buf, 'Test_popupwin_04a', {})
48 call term_sendkeys(buf, ":let &columns = cols\<CR>")
49
Bram Moolenaar17146962019-05-30 00:12:11 +020050 " resize popup, show empty line at bottom
Bram Moolenaar60cdb302019-05-27 21:54:10 +020051 call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>")
52 call term_sendkeys(buf, ":redraw\<CR>")
53 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
54
Bram Moolenaar17146962019-05-30 00:12:11 +020055 " show not fitting line at bottom
56 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
57 call term_sendkeys(buf, ":redraw\<CR>")
58 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
59
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020060 " move popup over ruler
61 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
62 call term_sendkeys(buf, ":call popup_move(popupwin, {'line': 7, 'col': 55})\<CR>")
63 call VerifyScreenDump(buf, 'Test_popupwin_07', {})
64
65 " clear all popups after moving the cursor a bit, so that ruler is updated
66 call term_sendkeys(buf, "axxx\<Esc>")
67 call term_wait(buf)
68 call term_sendkeys(buf, "0")
69 call term_wait(buf)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020070 call term_sendkeys(buf, ":call popup_clear()\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020071 call VerifyScreenDump(buf, 'Test_popupwin_08', {})
72
Bram Moolenaar4d784b22019-05-25 19:51:39 +020073 " clean up
74 call StopVimInTerminal(buf)
75 call delete('XtestPopup')
76endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020077
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020078func Test_popup_with_border_and_padding()
79 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +020080 throw 'Skipped: cannot make screendumps'
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020081 endif
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020082
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020083 for iter in range(0, 1)
84 call writefile([iter == 1 ? '' : 'set enc=latin1',
85 \ "call setline(1, range(1, 100))",
86 \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
87 \ "call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})",
88 \ "call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})",
89 \ "call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})",
90 \ "call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})",
91 \], 'XtestPopupBorder')
92 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15})
93 call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
94
95 call StopVimInTerminal(buf)
96 call delete('XtestPopupBorder')
97 endfor
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020098
Bram Moolenaar790498b2019-06-01 22:15:29 +020099 call writefile([
100 \ "call setline(1, range(1, 100))",
101 \ "hi BlueColor ctermbg=lightblue",
102 \ "hi TopColor ctermbg=253",
103 \ "hi RightColor ctermbg=245",
104 \ "hi BottomColor ctermbg=240",
105 \ "hi LeftColor ctermbg=248",
106 \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor']})",
107 \ "call popup_create(['hello border', 'and more'], {'line': 2, 'col': 23, 'border': [], 'borderhighlight': ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})",
108 \ "call popup_create(['hello border', 'lines only'], {'line': 2, 'col': 43, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x']})",
109 \ "call popup_create(['hello border', 'with corners'], {'line': 2, 'col': 60, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x', '#']})",
110 \ "call popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})",
111 \ "call popup_create(['hello border', 'just blanks'], {'line': 7, 'col': 23, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': [' ']})",
112 \], 'XtestPopupBorder')
113 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 12})
114 call VerifyScreenDump(buf, 'Test_popupwin_22', {})
115
116 call StopVimInTerminal(buf)
117 call delete('XtestPopupBorder')
118
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200119 let with_border_or_padding = {
120 \ 'line': 2,
121 \ 'core_line': 3,
122 \ 'col': 3,
123 \ 'core_col': 4,
124 \ 'width': 14,
125 \ 'core_width': 12,
126 \ 'height': 3,
127 \ 'core_height': 1,
128 \ 'visible': 1}
129 let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
130 call assert_equal(with_border_or_padding, popup_getpos(winid))
131
132 let winid = popup_create('hello paddng', {'line': 2, 'col': 3, 'padding': []})
133 call assert_equal(with_border_or_padding, popup_getpos(winid))
134
135 let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []})
136 call assert_equal({
137 \ 'line': 3,
138 \ 'core_line': 5,
139 \ 'col': 8,
140 \ 'core_col': 10,
141 \ 'width': 14,
142 \ 'core_width': 10,
143 \ 'height': 5,
144 \ 'core_height': 1,
145 \ 'visible': 1}, popup_getpos(winid))
146endfunc
147
Bram Moolenaarb4230122019-05-30 18:40:53 +0200148func Test_popup_with_syntax_win_execute()
149 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200150 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200151 endif
152 call writefile([
153 \ "call setline(1, range(1, 100))",
154 \ "hi PopupColor ctermbg=lightblue",
155 \ "let winid = popup_create([",
156 \ "\\ '#include <stdio.h>',",
157 \ "\\ 'int main(void)',",
158 \ "\\ '{',",
159 \ "\\ ' printf(123);',",
160 \ "\\ '}',",
161 \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})",
162 \ "call win_execute(winid, 'set syntax=cpp')",
163 \], 'XtestPopup')
164 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
165 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
166
167 " clean up
168 call StopVimInTerminal(buf)
169 call delete('XtestPopup')
170endfunc
171
172func Test_popup_with_syntax_setbufvar()
173 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200174 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200175 endif
Bram Moolenaar402502d2019-05-30 22:07:36 +0200176 let lines =<< trim END
177 call setline(1, range(1, 100))
178 hi PopupColor ctermbg=lightgrey
179 let winid = popup_create([
180 \ '#include <stdio.h>',
181 \ 'int main(void)',
182 \ '{',
183 \ ' printf(567);',
184 \ '}',
185 \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})
186 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
187 END
188 call writefile(lines, 'XtestPopup')
Bram Moolenaarb4230122019-05-30 18:40:53 +0200189 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
190 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
191
192 " clean up
193 call StopVimInTerminal(buf)
194 call delete('XtestPopup')
195endfunc
196
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200197func Test_popup_with_matches()
198 if !CanRunVimInTerminal()
199 throw 'Skipped: cannot make screendumps'
200 endif
201 let lines =<< trim END
202 call setline(1, ['111 222 333', '444 555 666'])
203 let winid = popup_create([
204 \ '111 222 333',
205 \ '444 555 666',
206 \], {'line': 3, 'col': 10, 'border': []})
207 set hlsearch
208 /666
209 call matchadd('ErrorMsg', '111')
210 call matchadd('ErrorMsg', '444')
211 call win_execute(winid, "call matchadd('ErrorMsg', '111')")
212 call win_execute(winid, "call matchadd('ErrorMsg', '555')")
213 END
214 call writefile(lines, 'XtestPopupMatches')
215 let buf = RunVimInTerminal('-S XtestPopupMatches', {'rows': 10})
216 call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
217
218 " clean up
219 call StopVimInTerminal(buf)
220 call delete('XtestPopupMatches')
221endfunc
222
Bram Moolenaar399d8982019-06-02 15:34:29 +0200223func Test_popup_all_corners()
224 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200225 throw 'Skipped: cannot make screendumps'
Bram Moolenaar399d8982019-06-02 15:34:29 +0200226 endif
227 let lines =<< trim END
228 call setline(1, repeat([repeat('-', 60)], 15))
229 set so=0
230 normal 2G3|r#
231 let winid1 = popup_create(['first', 'second'], {
232 \ 'line': 'cursor+1',
233 \ 'col': 'cursor',
234 \ 'pos': 'topleft',
235 \ 'border': [],
236 \ 'padding': [],
237 \ })
238 normal 25|r@
239 let winid1 = popup_create(['First', 'SeconD'], {
240 \ 'line': 'cursor+1',
241 \ 'col': 'cursor',
242 \ 'pos': 'topright',
243 \ 'border': [],
244 \ 'padding': [],
245 \ })
246 normal 9G29|r%
247 let winid1 = popup_create(['fiRSt', 'seCOnd'], {
248 \ 'line': 'cursor-1',
249 \ 'col': 'cursor',
250 \ 'pos': 'botleft',
251 \ 'border': [],
252 \ 'padding': [],
253 \ })
254 normal 51|r&
255 let winid1 = popup_create(['FIrsT', 'SEcoND'], {
256 \ 'line': 'cursor-1',
257 \ 'col': 'cursor',
258 \ 'pos': 'botright',
259 \ 'border': [],
260 \ 'padding': [],
261 \ })
262 END
263 call writefile(lines, 'XtestPopupCorners')
264 let buf = RunVimInTerminal('-S XtestPopupCorners', {'rows': 12})
265 call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
266
267 " clean up
268 call StopVimInTerminal(buf)
269 call delete('XtestPopupCorners')
270endfunc
271
Bram Moolenaar8d241042019-06-12 23:40:01 +0200272func Test_popup_firstline()
273 if !CanRunVimInTerminal()
274 throw 'Skipped: cannot make screendumps'
275 endif
276 let lines =<< trim END
277 call setline(1, range(1, 20))
278 call popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], {
279 \ 'maxheight': 4,
280 \ 'firstline': 3,
281 \ })
282 END
283 call writefile(lines, 'XtestPopupFirstline')
284 let buf = RunVimInTerminal('-S XtestPopupFirstline', {'rows': 10})
285 call VerifyScreenDump(buf, 'Test_popupwin_firstline', {})
286
287 " clean up
288 call StopVimInTerminal(buf)
289 call delete('XtestPopupFirstline')
290endfunc
291
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200292func Test_popup_in_tab()
293 " default popup is local to tab, not visible when in other tab
294 let winid = popup_create("text", {})
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200295 let bufnr = winbufnr(winid)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200296 call assert_equal(1, popup_getpos(winid).visible)
297 tabnew
298 call assert_equal(0, popup_getpos(winid).visible)
299 quit
300 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200301
302 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200303 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200304 " buffer is gone now
305 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200306
307 " global popup is visible in any tab
308 let winid = popup_create("text", {'tab': -1})
309 call assert_equal(1, popup_getpos(winid).visible)
310 tabnew
311 call assert_equal(1, popup_getpos(winid).visible)
312 quit
313 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200314 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200315endfunc
316
317func Test_popup_valid_arguments()
318 " Zero value is like the property wasn't there
319 let winid = popup_create("text", {"col": 0})
320 let pos = popup_getpos(winid)
321 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200322 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200323
324 " using cursor column has minimum value of 1
325 let winid = popup_create("text", {"col": 'cursor-100'})
326 let pos = popup_getpos(winid)
327 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200328 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200329
330 " center
331 let winid = popup_create("text", {"pos": 'center'})
332 let pos = popup_getpos(winid)
333 let around = (&columns - pos.width) / 2
334 call assert_inrange(around - 1, around + 1, pos.col)
335 let around = (&lines - pos.height) / 2
336 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200337 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200338endfunc
339
340func Test_popup_invalid_arguments()
341 call assert_fails('call popup_create(666, {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200342 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200343 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200344 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200345
346 call assert_fails('call popup_create("text", {"col": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200347 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200348 call assert_fails('call popup_create("text", {"col": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200349 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200350 call assert_fails('call popup_create("text", {"col": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200351 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200352 call assert_fails('call popup_create("text", {"col": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200353 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200354
355 call assert_fails('call popup_create("text", {"line": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200356 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200357 call assert_fails('call popup_create("text", {"line": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200358 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200359 call assert_fails('call popup_create("text", {"line": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200360 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200361 call assert_fails('call popup_create("text", {"line": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200362 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200363
364 call assert_fails('call popup_create("text", {"pos": "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200365 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200366 call assert_fails('call popup_create("text", {"padding": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200367 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200368 call assert_fails('call popup_create("text", {"border": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200369 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200370 call assert_fails('call popup_create("text", {"borderhighlight": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200371 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200372 call assert_fails('call popup_create("text", {"borderchars": "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200373 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200374
375 call assert_fails('call popup_create([{"text": "text"}, 666], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200376 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200377 call assert_fails('call popup_create([{"text": "text", "props": "none"}], {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200378 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200379 call assert_fails('call popup_create([{"text": "text", "props": ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200380 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200381endfunc
382
Bram Moolenaareea16992019-05-31 17:34:48 +0200383func Test_win_execute_closing_curwin()
384 split
385 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200386 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200387 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200388endfunc
389
390func Test_win_execute_not_allowed()
391 let winid = popup_create('some text', {})
392 call assert_fails('call win_execute(winid, "split")', 'E994:')
393 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
394 call assert_fails('call win_execute(winid, "close")', 'E994:')
395 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200396 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200397 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
398 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
399 call assert_fails('call win_execute(winid, "next")', 'E994:')
400 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
401 call assert_fails('call win_execute(winid, "buf")', 'E994:')
402 call assert_fails('call win_execute(winid, "edit")', 'E994:')
403 call assert_fails('call win_execute(winid, "enew")', 'E994:')
404 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
405 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
406 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
407 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200408 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200409endfunc
410
Bram Moolenaar402502d2019-05-30 22:07:36 +0200411func Test_popup_with_wrap()
412 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200413 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200414 endif
415 let lines =<< trim END
416 call setline(1, range(1, 100))
417 let winid = popup_create(
418 \ 'a long line that wont fit',
419 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
420 END
421 call writefile(lines, 'XtestPopup')
422 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
423 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
424
425 " clean up
426 call StopVimInTerminal(buf)
427 call delete('XtestPopup')
428endfunc
429
430func Test_popup_without_wrap()
431 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200432 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200433 endif
434 let lines =<< trim END
435 call setline(1, range(1, 100))
436 let winid = popup_create(
437 \ 'a long line that wont fit',
438 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
439 END
440 call writefile(lines, 'XtestPopup')
441 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
442 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
443
444 " clean up
445 call StopVimInTerminal(buf)
446 call delete('XtestPopup')
447endfunc
448
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200449func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200450 if !has('timers')
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200451 throw 'Skipped, timer feature not supported'
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200452 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200453 topleft vnew
454 call setline(1, 'hello')
455
456 call popup_create('world', {
457 \ 'line': 1,
458 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200459 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200460 \ 'time': 500,
461 \})
462 redraw
463 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
464 call assert_equal('world', line)
465
466 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200467 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200468 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
469 call assert_equal('hello', line)
470
471 call popup_create('on the command line', {
472 \ 'line': &lines,
473 \ 'col': 10,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200474 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200475 \ 'time': 500,
476 \})
477 redraw
478 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
479 call assert_match('.*on the command line.*', line)
480
481 sleep 700m
482 redraw
483 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
484 call assert_notmatch('.*on the command line.*', line)
485
486 bwipe!
487endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200488
489func Test_popup_hide()
490 topleft vnew
491 call setline(1, 'hello')
492
493 let winid = popup_create('world', {
494 \ 'line': 1,
495 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200496 \ 'minwidth': 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200497 \})
498 redraw
499 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
500 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200501 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200502 " buffer is still listed and active
503 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200504
505 call popup_hide(winid)
506 redraw
507 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
508 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200509 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200510 " buffer is still listed but hidden
511 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200512
513 call popup_show(winid)
514 redraw
515 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
516 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200517 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200518
519
520 call popup_close(winid)
521 redraw
522 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
523 call assert_equal('hello', line)
524
525 " error is given for existing non-popup window
526 call assert_fails('call popup_hide(win_getid())', 'E993:')
527
528 " no error non-existing window
529 call popup_hide(1234234)
530 call popup_show(41234234)
531
532 bwipe!
533endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200534
535func Test_popup_move()
536 topleft vnew
537 call setline(1, 'hello')
538
539 let winid = popup_create('world', {
540 \ 'line': 1,
541 \ 'col': 1,
542 \ 'minwidth': 20,
543 \})
544 redraw
545 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
546 call assert_equal('world ', line)
547
548 call popup_move(winid, {'line': 2, 'col': 2})
549 redraw
550 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
551 call assert_equal('hello ', line)
552 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
553 call assert_equal('~world', line)
554
555 call popup_move(winid, {'line': 1})
556 redraw
557 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
558 call assert_equal('hworld', line)
559
560 call popup_close(winid)
561
562 bwipe!
563endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200564
Bram Moolenaar402502d2019-05-30 22:07:36 +0200565func Test_popup_getpos()
Bram Moolenaarbc133542019-05-29 20:26:46 +0200566 let winid = popup_create('hello', {
567 \ 'line': 2,
568 \ 'col': 3,
569 \ 'minwidth': 10,
570 \ 'minheight': 11,
571 \})
572 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200573 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200574 call assert_equal(2, res.line)
575 call assert_equal(3, res.col)
576 call assert_equal(10, res.width)
577 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200578 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200579
580 call popup_close(winid)
581endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200582
583func Test_popup_width_longest()
584 let tests = [
585 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
586 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
587 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
588 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
589 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
590 \ ]
591
592 for test in tests
593 let winid = popup_create(test[0], {'line': 2, 'col': 3})
594 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200595 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200596 call assert_equal(test[1], position.width)
597 call popup_close(winid)
598 endfor
599endfunc
600
601func Test_popup_wraps()
602 let tests = [
603 \ ['nowrap', 6, 1],
604 \ ['a line that wraps once', 12, 2],
605 \ ['a line that wraps two times', 12, 3],
606 \ ]
607 for test in tests
608 let winid = popup_create(test[0],
609 \ {'line': 2, 'col': 3, 'maxwidth': 12})
610 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200611 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200612 call assert_equal(test[1], position.width)
613 call assert_equal(test[2], position.height)
614
615 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200616 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200617 endfor
618endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200619
620func Test_popup_getoptions()
621 let winid = popup_create('hello', {
622 \ 'line': 2,
623 \ 'col': 3,
624 \ 'minwidth': 10,
625 \ 'minheight': 11,
626 \ 'maxwidth': 20,
627 \ 'maxheight': 21,
628 \ 'zindex': 100,
629 \ 'time': 5000,
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200630 \ 'fixed': 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200631 \})
632 redraw
633 let res = popup_getoptions(winid)
634 call assert_equal(2, res.line)
635 call assert_equal(3, res.col)
636 call assert_equal(10, res.minwidth)
637 call assert_equal(11, res.minheight)
638 call assert_equal(20, res.maxwidth)
639 call assert_equal(21, res.maxheight)
640 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200641 call assert_equal(1, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200642 if has('timers')
643 call assert_equal(5000, res.time)
644 endif
645 call popup_close(winid)
646
647 let winid = popup_create('hello', {})
648 redraw
649 let res = popup_getoptions(winid)
650 call assert_equal(0, res.line)
651 call assert_equal(0, res.col)
652 call assert_equal(0, res.minwidth)
653 call assert_equal(0, res.minheight)
654 call assert_equal(0, res.maxwidth)
655 call assert_equal(0, res.maxheight)
656 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200657 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200658 if has('timers')
659 call assert_equal(0, res.time)
660 endif
661 call popup_close(winid)
662 call assert_equal({}, popup_getoptions(winid))
663endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200664
665func Test_popup_option_values()
666 new
667 " window-local
668 setlocal number
669 setlocal nowrap
670 " buffer-local
671 setlocal omnifunc=Something
672 " global/buffer-local
673 setlocal path=/there
674 " global/window-local
675 setlocal scrolloff=9
676
677 let winid = popup_create('hello', {})
678 call assert_equal(0, getwinvar(winid, '&number'))
679 call assert_equal(1, getwinvar(winid, '&wrap'))
680 call assert_equal('', getwinvar(winid, '&omnifunc'))
681 call assert_equal(&g:path, getwinvar(winid, '&path'))
682 call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
683
684 call popup_close(winid)
685 bwipe
686endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200687
688func Test_popup_atcursor()
689 topleft vnew
690 call setline(1, [
691 \ 'xxxxxxxxxxxxxxxxx',
692 \ 'xxxxxxxxxxxxxxxxx',
693 \ 'xxxxxxxxxxxxxxxxx',
694 \])
695
696 call cursor(2, 2)
697 redraw
698 let winid = popup_atcursor('vim', {})
699 redraw
700 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
701 call assert_equal('xvimxxxxxxxxxxxxx', line)
702 call popup_close(winid)
703
704 call cursor(3, 4)
705 redraw
706 let winid = popup_atcursor('vim', {})
707 redraw
708 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
709 call assert_equal('xxxvimxxxxxxxxxxx', line)
710 call popup_close(winid)
711
712 call cursor(1, 1)
713 redraw
714 let winid = popup_create('vim', {
715 \ 'line': 'cursor+2',
716 \ 'col': 'cursor+1',
717 \})
718 redraw
719 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
720 call assert_equal('xvimxxxxxxxxxxxxx', line)
721 call popup_close(winid)
722
723 call cursor(3, 3)
724 redraw
725 let winid = popup_create('vim', {
726 \ 'line': 'cursor-2',
727 \ 'col': 'cursor-1',
728 \})
729 redraw
730 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
731 call assert_equal('xvimxxxxxxxxxxxxx', line)
732 call popup_close(winid)
733
Bram Moolenaar402502d2019-05-30 22:07:36 +0200734 " just enough room above
735 call cursor(3, 3)
736 redraw
737 let winid = popup_atcursor(['vim', 'is great'], {})
738 redraw
739 let pos = popup_getpos(winid)
740 call assert_equal(1, pos.line)
741 call popup_close(winid)
742
743 " not enough room above, popup goes below the cursor
744 call cursor(3, 3)
745 redraw
746 let winid = popup_atcursor(['vim', 'is', 'great'], {})
747 redraw
748 let pos = popup_getpos(winid)
749 call assert_equal(4, pos.line)
750 call popup_close(winid)
751
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200752 " cursor in first line, popup in line 2
753 call cursor(1, 1)
754 redraw
755 let winid = popup_atcursor(['vim', 'is', 'great'], {})
756 redraw
757 let pos = popup_getpos(winid)
758 call assert_equal(2, pos.line)
759 call popup_close(winid)
760
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200761 bwipe!
762endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200763
764func Test_popup_filter()
765 new
766 call setline(1, 'some text')
767
768 func MyPopupFilter(winid, c)
769 if a:c == 'e'
770 let g:eaten = 'e'
771 return 1
772 endif
773 if a:c == '0'
774 let g:ignored = '0'
775 return 0
776 endif
777 if a:c == 'x'
778 call popup_close(a:winid)
779 return 1
780 endif
781 return 0
782 endfunc
783
784 let winid = popup_create('something', {'filter': 'MyPopupFilter'})
785 redraw
786
787 " e is consumed by the filter
788 call feedkeys('e', 'xt')
789 call assert_equal('e', g:eaten)
790
791 " 0 is ignored by the filter
792 normal $
793 call assert_equal(9, getcurpos()[2])
794 call feedkeys('0', 'xt')
795 call assert_equal('0', g:ignored)
796 call assert_equal(1, getcurpos()[2])
797
798 " x closes the popup
799 call feedkeys('x', 'xt')
800 call assert_equal('e', g:eaten)
801 call assert_equal(-1, winbufnr(winid))
802
803 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200804 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200805endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200806
807func Test_popup_close_callback()
808 func PopupDone(id, result)
809 let g:result = a:result
810 endfunc
811 let winid = popup_create('something', {'callback': 'PopupDone'})
812 redraw
813 call popup_close(winid, 'done')
814 call assert_equal('done', g:result)
815endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +0200816
817func Test_popup_empty()
818 let winid = popup_create('', {'padding': [2,2,2,2]})
819 redraw
820 let pos = popup_getpos(winid)
821 call assert_equal(4, pos.width)
822 call assert_equal(5, pos.height)
823
824 let winid = popup_create([], {'border': []})
825 redraw
826 let pos = popup_getpos(winid)
827 call assert_equal(2, pos.width)
828 call assert_equal(3, pos.height)
829endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +0200830
831func Test_popup_never_behind()
832 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200833 throw 'Skipped: cannot make screendumps'
Bram Moolenaar988c4332019-06-02 14:12:11 +0200834 endif
835 " +-----------------------------+
836 " | | |
837 " | | |
838 " | | |
839 " | line1 |
840 " |------------line2------------|
841 " | line3 |
842 " | line4 |
843 " | |
844 " | |
845 " +-----------------------------+
846 let lines =<< trim END
847 only
848 split
849 vsplit
850 let info_window1 = getwininfo()[0]
851 let line = info_window1['height']
852 let col = info_window1['width']
853 call popup_create(['line1', 'line2', 'line3', 'line4'], {
854 \ 'line' : line,
855 \ 'col' : col,
856 \ })
857 END
858 call writefile(lines, 'XtestPopupBehind')
859 let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10})
860 call term_sendkeys(buf, "\<C-W>w")
861 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
862
863 " clean up
864 call StopVimInTerminal(buf)
865 call delete('XtestPopupBehind')
866endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200867
868func s:VerifyPosition( p, msg, line, col, width, height )
869 call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' )
870 call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' )
871 call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' )
872 call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' )
873endfunc
874
875func Test_popup_position_adjust()
876 " Anything placed past 2 cells from of the right of the screen is moved to the
877 " left.
878 "
879 " When wrapping is disabled, we also shift to the left to display on the
880 " screen, unless fixed is set.
881
882 " Entries for cases which don't vary based on wrapping.
883 " Format is per tests described below
884 let both_wrap_tests = [
885 \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ],
886 \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ],
887 \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ],
888 \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ],
889 \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ],
890 \
891 \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ],
892 \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ],
893 \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ],
894 \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ],
895 \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ],
896 \
897 \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ],
898 \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
899 \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
900 \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
901 \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ],
902 \ ]
903
904 " these test groups are dicts with:
905 " - comment: something to identify the group of tests by
906 " - options: dict of options to merge with the row/col in tests
907 " - tests: list of cases. Each one is a list with elements:
908 " - text
909 " - row
910 " - col
911 " - expected row
912 " - expected col
913 " - expected width
914 " - expected height
915 let tests = [
916 \ {
917 \ 'comment': 'left-aligned with wrapping',
918 \ 'options': {
919 \ 'wrap': 1,
920 \ 'pos': 'botleft',
921 \ },
922 \ 'tests': both_wrap_tests + [
923 \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ],
924 \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ],
925 \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ],
926 \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ],
927 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
928 \ ],
929 \ },
930 \ {
931 \ 'comment': 'left aligned without wrapping',
932 \ 'options': {
933 \ 'wrap': 0,
934 \ 'pos': 'botleft',
935 \ },
936 \ 'tests': both_wrap_tests + [
937 \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ],
938 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ],
939 \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ],
940 \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ],
941 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
942 \ ],
943 \ },
944 \ {
945 \ 'comment': 'left aligned with fixed position',
946 \ 'options': {
947 \ 'wrap': 0,
948 \ 'fixed': 1,
949 \ 'pos': 'botleft',
950 \ },
951 \ 'tests': both_wrap_tests + [
952 \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ],
953 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
954 \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
955 \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
956 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
957 \ ],
958 \ },
959 \ ]
960
961 for test_group in tests
962 for test in test_group.tests
963 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
964 let options = {
965 \ 'line': line,
966 \ 'col': col,
967 \ }
968 call extend( options, test_group.options )
969
970 let p = popup_create( text, options )
971
972 let msg = string( extend( options, { 'text': text } ) )
973 call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height )
974 call popup_close( p )
975 endfor
976 endfor
977
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200978 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200979 %bwipe!
980endfunc
981
Bram Moolenaar3397f742019-06-02 18:40:06 +0200982func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200983 " width of screen
984 let X = join(map(range(&columns), {->'X'}), '')
985
986 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
987 call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 )
988
989 redraw
990 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
991 call assert_equal(X, line)
992
993 call popup_close( p )
994 redraw
995
996 " Same if placed on the right hand side
997 let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } )
998 call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 )
999
1000 redraw
1001 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1002 call assert_equal(X, line)
1003
1004 call popup_close( p )
1005 redraw
1006
1007 " Extend so > window width
1008 let X .= 'x'
1009
1010 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
1011 call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 )
1012
1013 redraw
1014 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1015 call assert_equal(X[ : -2 ], line)
1016
1017 call popup_close( p )
1018 redraw
1019
1020 " Shifted then truncated (the x is not visible)
1021 let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } )
1022 call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 )
1023
1024 redraw
1025 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1026 call assert_equal(X[ : -2 ], line)
1027
1028 call popup_close( p )
1029 redraw
1030
1031 " Not shifted, just truncated
1032 let p = popup_create( X,
1033 \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } )
1034 call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
1035
1036 redraw
1037 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1038 let e_line = ' ' . X[ 1 : -2 ]
1039 call assert_equal(e_line, line)
1040
1041 call popup_close( p )
1042 redraw
1043
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001044 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001045 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001046endfunc
1047
1048func Test_popup_moved()
1049 new
1050 call test_override('char_avail', 1)
1051 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1052
1053 exe "normal gg0/word\<CR>"
1054 let winid = popup_atcursor('text', {'moved': 'any'})
1055 redraw
1056 call assert_equal(1, popup_getpos(winid).visible)
1057 " trigger the check for last_cursormoved by going into insert mode
1058 call feedkeys("li\<Esc>", 'xt')
1059 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001060 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001061
1062 exe "normal gg0/word\<CR>"
1063 let winid = popup_atcursor('text', {'moved': 'word'})
1064 redraw
1065 call assert_equal(1, popup_getpos(winid).visible)
1066 call feedkeys("hi\<Esc>", 'xt')
1067 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001068 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001069
1070 exe "normal gg0/word\<CR>"
1071 let winid = popup_atcursor('text', {'moved': 'word'})
1072 redraw
1073 call assert_equal(1, popup_getpos(winid).visible)
1074 call feedkeys("li\<Esc>", 'xt')
1075 call assert_equal(1, popup_getpos(winid).visible)
1076 call feedkeys("ei\<Esc>", 'xt')
1077 call assert_equal(1, popup_getpos(winid).visible)
1078 call feedkeys("eli\<Esc>", 'xt')
1079 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001080 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001081
Bram Moolenaar17627312019-06-02 19:53:44 +02001082 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001083 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001084 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001085 redraw
1086 call assert_equal(1, popup_getpos(winid).visible)
1087 call feedkeys("eli\<Esc>", 'xt')
1088 call assert_equal(1, popup_getpos(winid).visible)
1089 call feedkeys("wi\<Esc>", 'xt')
1090 call assert_equal(1, popup_getpos(winid).visible)
1091 call feedkeys("Eli\<Esc>", 'xt')
1092 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001093 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001094
1095 exe "normal gg0/word\<CR>"
1096 let winid = popup_atcursor('text', {'moved': [5, 10]})
1097 redraw
1098 call assert_equal(1, popup_getpos(winid).visible)
1099 call feedkeys("eli\<Esc>", 'xt')
1100 call feedkeys("ei\<Esc>", 'xt')
1101 call assert_equal(1, popup_getpos(winid).visible)
1102 call feedkeys("eli\<Esc>", 'xt')
1103 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001104 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001105
1106 bwipe!
1107 call test_override('ALL', 0)
1108endfunc
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001109
1110func Test_notifications()
1111 if !has('timers')
1112 throw 'Skipped, timer feature not supported'
1113 endif
1114 if !CanRunVimInTerminal()
1115 throw 'Skipped: cannot make screendumps'
1116 endif
1117
1118 call writefile([
1119 \ "call setline(1, range(1, 20))",
1120 \ "hi Notification ctermbg=lightblue",
1121 \ "call popup_notification('first notification', {})",
1122 \], 'XtestNotifications')
1123 let buf = RunVimInTerminal('-S XtestNotifications', {'rows': 10})
1124 call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {})
1125
1126 " second one goes below the first one
1127 call term_sendkeys(buf, ":call popup_notification('another important notification', {'highlight': 'Notification'})\<CR>")
1128 call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {})
1129
1130
1131 " clean up
1132 call StopVimInTerminal(buf)
1133 call delete('XtestNotifications')
1134endfunc