blob: d100dc99388cf1ae61a12695bda48337b2663705 [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 Moolenaarb0ebbda2019-06-02 16:51:21 +0200272func Test_popup_in_tab()
273 " default popup is local to tab, not visible when in other tab
274 let winid = popup_create("text", {})
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200275 let bufnr = winbufnr(winid)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200276 call assert_equal(1, popup_getpos(winid).visible)
277 tabnew
278 call assert_equal(0, popup_getpos(winid).visible)
279 quit
280 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200281
282 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200283 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200284 " buffer is gone now
285 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200286
287 " global popup is visible in any tab
288 let winid = popup_create("text", {'tab': -1})
289 call assert_equal(1, popup_getpos(winid).visible)
290 tabnew
291 call assert_equal(1, popup_getpos(winid).visible)
292 quit
293 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200294 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200295endfunc
296
297func Test_popup_valid_arguments()
298 " Zero value is like the property wasn't there
299 let winid = popup_create("text", {"col": 0})
300 let pos = popup_getpos(winid)
301 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200302 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200303
304 " using cursor column has minimum value of 1
305 let winid = popup_create("text", {"col": 'cursor-100'})
306 let pos = popup_getpos(winid)
307 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200308 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200309
310 " center
311 let winid = popup_create("text", {"pos": 'center'})
312 let pos = popup_getpos(winid)
313 let around = (&columns - pos.width) / 2
314 call assert_inrange(around - 1, around + 1, pos.col)
315 let around = (&lines - pos.height) / 2
316 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200317 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200318endfunc
319
320func Test_popup_invalid_arguments()
321 call assert_fails('call popup_create(666, {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200322 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200323 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200324 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200325
326 call assert_fails('call popup_create("text", {"col": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200327 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200328 call assert_fails('call popup_create("text", {"col": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200329 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200330 call assert_fails('call popup_create("text", {"col": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200331 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200332 call assert_fails('call popup_create("text", {"col": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200333 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200334
335 call assert_fails('call popup_create("text", {"line": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200336 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200337 call assert_fails('call popup_create("text", {"line": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200338 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200339 call assert_fails('call popup_create("text", {"line": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200340 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200341 call assert_fails('call popup_create("text", {"line": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200342 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200343
344 call assert_fails('call popup_create("text", {"pos": "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200345 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200346 call assert_fails('call popup_create("text", {"padding": "none"})', 'E714:')
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", {"border": "none"})', 'E714:')
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", {"borderhighlight": "none"})', 'E714:')
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", {"borderchars": "none"})', 'E714:')
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": "text"}, 666], {})', 'E715:')
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": "text", "props": "none"}], {})', 'E714:')
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": "text", "props": ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200360 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200361endfunc
362
Bram Moolenaareea16992019-05-31 17:34:48 +0200363func Test_win_execute_closing_curwin()
364 split
365 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200366 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200367 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200368endfunc
369
370func Test_win_execute_not_allowed()
371 let winid = popup_create('some text', {})
372 call assert_fails('call win_execute(winid, "split")', 'E994:')
373 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
374 call assert_fails('call win_execute(winid, "close")', 'E994:')
375 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200376 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200377 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
378 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
379 call assert_fails('call win_execute(winid, "next")', 'E994:')
380 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
381 call assert_fails('call win_execute(winid, "buf")', 'E994:')
382 call assert_fails('call win_execute(winid, "edit")', 'E994:')
383 call assert_fails('call win_execute(winid, "enew")', 'E994:')
384 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
385 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
386 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
387 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200388 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200389endfunc
390
Bram Moolenaar402502d2019-05-30 22:07:36 +0200391func Test_popup_with_wrap()
392 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200393 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200394 endif
395 let lines =<< trim END
396 call setline(1, range(1, 100))
397 let winid = popup_create(
398 \ 'a long line that wont fit',
399 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
400 END
401 call writefile(lines, 'XtestPopup')
402 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
403 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
404
405 " clean up
406 call StopVimInTerminal(buf)
407 call delete('XtestPopup')
408endfunc
409
410func Test_popup_without_wrap()
411 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200412 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200413 endif
414 let lines =<< trim END
415 call setline(1, range(1, 100))
416 let winid = popup_create(
417 \ 'a long line that wont fit',
418 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
419 END
420 call writefile(lines, 'XtestPopup')
421 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
422 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
423
424 " clean up
425 call StopVimInTerminal(buf)
426 call delete('XtestPopup')
427endfunc
428
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200429func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200430 if !has('timers')
431 return
432 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200433 topleft vnew
434 call setline(1, 'hello')
435
436 call popup_create('world', {
437 \ 'line': 1,
438 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200439 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200440 \ 'time': 500,
441 \})
442 redraw
443 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
444 call assert_equal('world', line)
445
446 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200447 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200448 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
449 call assert_equal('hello', line)
450
451 call popup_create('on the command line', {
452 \ 'line': &lines,
453 \ 'col': 10,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200454 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200455 \ 'time': 500,
456 \})
457 redraw
458 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
459 call assert_match('.*on the command line.*', line)
460
461 sleep 700m
462 redraw
463 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
464 call assert_notmatch('.*on the command line.*', line)
465
466 bwipe!
467endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200468
469func Test_popup_hide()
470 topleft vnew
471 call setline(1, 'hello')
472
473 let winid = popup_create('world', {
474 \ 'line': 1,
475 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200476 \ 'minwidth': 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200477 \})
478 redraw
479 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
480 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200481 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200482 " buffer is still listed and active
483 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200484
485 call popup_hide(winid)
486 redraw
487 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
488 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200489 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200490 " buffer is still listed but hidden
491 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200492
493 call popup_show(winid)
494 redraw
495 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
496 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200497 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200498
499
500 call popup_close(winid)
501 redraw
502 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
503 call assert_equal('hello', line)
504
505 " error is given for existing non-popup window
506 call assert_fails('call popup_hide(win_getid())', 'E993:')
507
508 " no error non-existing window
509 call popup_hide(1234234)
510 call popup_show(41234234)
511
512 bwipe!
513endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200514
515func Test_popup_move()
516 topleft vnew
517 call setline(1, 'hello')
518
519 let winid = popup_create('world', {
520 \ 'line': 1,
521 \ 'col': 1,
522 \ 'minwidth': 20,
523 \})
524 redraw
525 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
526 call assert_equal('world ', line)
527
528 call popup_move(winid, {'line': 2, 'col': 2})
529 redraw
530 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
531 call assert_equal('hello ', line)
532 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
533 call assert_equal('~world', line)
534
535 call popup_move(winid, {'line': 1})
536 redraw
537 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
538 call assert_equal('hworld', line)
539
540 call popup_close(winid)
541
542 bwipe!
543endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200544
Bram Moolenaar402502d2019-05-30 22:07:36 +0200545func Test_popup_getpos()
Bram Moolenaarbc133542019-05-29 20:26:46 +0200546 let winid = popup_create('hello', {
547 \ 'line': 2,
548 \ 'col': 3,
549 \ 'minwidth': 10,
550 \ 'minheight': 11,
551 \})
552 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200553 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200554 call assert_equal(2, res.line)
555 call assert_equal(3, res.col)
556 call assert_equal(10, res.width)
557 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200558 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200559
560 call popup_close(winid)
561endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200562
563func Test_popup_width_longest()
564 let tests = [
565 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
566 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
567 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
568 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
569 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
570 \ ]
571
572 for test in tests
573 let winid = popup_create(test[0], {'line': 2, 'col': 3})
574 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200575 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200576 call assert_equal(test[1], position.width)
577 call popup_close(winid)
578 endfor
579endfunc
580
581func Test_popup_wraps()
582 let tests = [
583 \ ['nowrap', 6, 1],
584 \ ['a line that wraps once', 12, 2],
585 \ ['a line that wraps two times', 12, 3],
586 \ ]
587 for test in tests
588 let winid = popup_create(test[0],
589 \ {'line': 2, 'col': 3, 'maxwidth': 12})
590 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200591 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200592 call assert_equal(test[1], position.width)
593 call assert_equal(test[2], position.height)
594
595 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200596 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200597 endfor
598endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200599
600func Test_popup_getoptions()
601 let winid = popup_create('hello', {
602 \ 'line': 2,
603 \ 'col': 3,
604 \ 'minwidth': 10,
605 \ 'minheight': 11,
606 \ 'maxwidth': 20,
607 \ 'maxheight': 21,
608 \ 'zindex': 100,
609 \ 'time': 5000,
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200610 \ 'fixed': 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200611 \})
612 redraw
613 let res = popup_getoptions(winid)
614 call assert_equal(2, res.line)
615 call assert_equal(3, res.col)
616 call assert_equal(10, res.minwidth)
617 call assert_equal(11, res.minheight)
618 call assert_equal(20, res.maxwidth)
619 call assert_equal(21, res.maxheight)
620 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200621 call assert_equal(1, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200622 if has('timers')
623 call assert_equal(5000, res.time)
624 endif
625 call popup_close(winid)
626
627 let winid = popup_create('hello', {})
628 redraw
629 let res = popup_getoptions(winid)
630 call assert_equal(0, res.line)
631 call assert_equal(0, res.col)
632 call assert_equal(0, res.minwidth)
633 call assert_equal(0, res.minheight)
634 call assert_equal(0, res.maxwidth)
635 call assert_equal(0, res.maxheight)
636 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200637 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200638 if has('timers')
639 call assert_equal(0, res.time)
640 endif
641 call popup_close(winid)
642 call assert_equal({}, popup_getoptions(winid))
643endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200644
645func Test_popup_option_values()
646 new
647 " window-local
648 setlocal number
649 setlocal nowrap
650 " buffer-local
651 setlocal omnifunc=Something
652 " global/buffer-local
653 setlocal path=/there
654 " global/window-local
655 setlocal scrolloff=9
656
657 let winid = popup_create('hello', {})
658 call assert_equal(0, getwinvar(winid, '&number'))
659 call assert_equal(1, getwinvar(winid, '&wrap'))
660 call assert_equal('', getwinvar(winid, '&omnifunc'))
661 call assert_equal(&g:path, getwinvar(winid, '&path'))
662 call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
663
664 call popup_close(winid)
665 bwipe
666endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200667
668func Test_popup_atcursor()
669 topleft vnew
670 call setline(1, [
671 \ 'xxxxxxxxxxxxxxxxx',
672 \ 'xxxxxxxxxxxxxxxxx',
673 \ 'xxxxxxxxxxxxxxxxx',
674 \])
675
676 call cursor(2, 2)
677 redraw
678 let winid = popup_atcursor('vim', {})
679 redraw
680 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
681 call assert_equal('xvimxxxxxxxxxxxxx', line)
682 call popup_close(winid)
683
684 call cursor(3, 4)
685 redraw
686 let winid = popup_atcursor('vim', {})
687 redraw
688 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
689 call assert_equal('xxxvimxxxxxxxxxxx', line)
690 call popup_close(winid)
691
692 call cursor(1, 1)
693 redraw
694 let winid = popup_create('vim', {
695 \ 'line': 'cursor+2',
696 \ 'col': 'cursor+1',
697 \})
698 redraw
699 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
700 call assert_equal('xvimxxxxxxxxxxxxx', line)
701 call popup_close(winid)
702
703 call cursor(3, 3)
704 redraw
705 let winid = popup_create('vim', {
706 \ 'line': 'cursor-2',
707 \ 'col': 'cursor-1',
708 \})
709 redraw
710 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
711 call assert_equal('xvimxxxxxxxxxxxxx', line)
712 call popup_close(winid)
713
Bram Moolenaar402502d2019-05-30 22:07:36 +0200714 " just enough room above
715 call cursor(3, 3)
716 redraw
717 let winid = popup_atcursor(['vim', 'is great'], {})
718 redraw
719 let pos = popup_getpos(winid)
720 call assert_equal(1, pos.line)
721 call popup_close(winid)
722
723 " not enough room above, popup goes below the cursor
724 call cursor(3, 3)
725 redraw
726 let winid = popup_atcursor(['vim', 'is', 'great'], {})
727 redraw
728 let pos = popup_getpos(winid)
729 call assert_equal(4, pos.line)
730 call popup_close(winid)
731
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200732 " cursor in first line, popup in line 2
733 call cursor(1, 1)
734 redraw
735 let winid = popup_atcursor(['vim', 'is', 'great'], {})
736 redraw
737 let pos = popup_getpos(winid)
738 call assert_equal(2, pos.line)
739 call popup_close(winid)
740
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200741 bwipe!
742endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200743
744func Test_popup_filter()
745 new
746 call setline(1, 'some text')
747
748 func MyPopupFilter(winid, c)
749 if a:c == 'e'
750 let g:eaten = 'e'
751 return 1
752 endif
753 if a:c == '0'
754 let g:ignored = '0'
755 return 0
756 endif
757 if a:c == 'x'
758 call popup_close(a:winid)
759 return 1
760 endif
761 return 0
762 endfunc
763
764 let winid = popup_create('something', {'filter': 'MyPopupFilter'})
765 redraw
766
767 " e is consumed by the filter
768 call feedkeys('e', 'xt')
769 call assert_equal('e', g:eaten)
770
771 " 0 is ignored by the filter
772 normal $
773 call assert_equal(9, getcurpos()[2])
774 call feedkeys('0', 'xt')
775 call assert_equal('0', g:ignored)
776 call assert_equal(1, getcurpos()[2])
777
778 " x closes the popup
779 call feedkeys('x', 'xt')
780 call assert_equal('e', g:eaten)
781 call assert_equal(-1, winbufnr(winid))
782
783 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200784 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200785endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200786
787func Test_popup_close_callback()
788 func PopupDone(id, result)
789 let g:result = a:result
790 endfunc
791 let winid = popup_create('something', {'callback': 'PopupDone'})
792 redraw
793 call popup_close(winid, 'done')
794 call assert_equal('done', g:result)
795endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +0200796
797func Test_popup_empty()
798 let winid = popup_create('', {'padding': [2,2,2,2]})
799 redraw
800 let pos = popup_getpos(winid)
801 call assert_equal(4, pos.width)
802 call assert_equal(5, pos.height)
803
804 let winid = popup_create([], {'border': []})
805 redraw
806 let pos = popup_getpos(winid)
807 call assert_equal(2, pos.width)
808 call assert_equal(3, pos.height)
809endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +0200810
811func Test_popup_never_behind()
812 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200813 throw 'Skipped: cannot make screendumps'
Bram Moolenaar988c4332019-06-02 14:12:11 +0200814 endif
815 " +-----------------------------+
816 " | | |
817 " | | |
818 " | | |
819 " | line1 |
820 " |------------line2------------|
821 " | line3 |
822 " | line4 |
823 " | |
824 " | |
825 " +-----------------------------+
826 let lines =<< trim END
827 only
828 split
829 vsplit
830 let info_window1 = getwininfo()[0]
831 let line = info_window1['height']
832 let col = info_window1['width']
833 call popup_create(['line1', 'line2', 'line3', 'line4'], {
834 \ 'line' : line,
835 \ 'col' : col,
836 \ })
837 END
838 call writefile(lines, 'XtestPopupBehind')
839 let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10})
840 call term_sendkeys(buf, "\<C-W>w")
841 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
842
843 " clean up
844 call StopVimInTerminal(buf)
845 call delete('XtestPopupBehind')
846endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200847
848func s:VerifyPosition( p, msg, line, col, width, height )
849 call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' )
850 call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' )
851 call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' )
852 call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' )
853endfunc
854
855func Test_popup_position_adjust()
856 " Anything placed past 2 cells from of the right of the screen is moved to the
857 " left.
858 "
859 " When wrapping is disabled, we also shift to the left to display on the
860 " screen, unless fixed is set.
861
862 " Entries for cases which don't vary based on wrapping.
863 " Format is per tests described below
864 let both_wrap_tests = [
865 \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ],
866 \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ],
867 \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ],
868 \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ],
869 \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ],
870 \
871 \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ],
872 \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ],
873 \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ],
874 \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ],
875 \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ],
876 \
877 \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ],
878 \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
879 \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
880 \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
881 \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ],
882 \ ]
883
884 " these test groups are dicts with:
885 " - comment: something to identify the group of tests by
886 " - options: dict of options to merge with the row/col in tests
887 " - tests: list of cases. Each one is a list with elements:
888 " - text
889 " - row
890 " - col
891 " - expected row
892 " - expected col
893 " - expected width
894 " - expected height
895 let tests = [
896 \ {
897 \ 'comment': 'left-aligned with wrapping',
898 \ 'options': {
899 \ 'wrap': 1,
900 \ 'pos': 'botleft',
901 \ },
902 \ 'tests': both_wrap_tests + [
903 \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ],
904 \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ],
905 \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ],
906 \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ],
907 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
908 \ ],
909 \ },
910 \ {
911 \ 'comment': 'left aligned without wrapping',
912 \ 'options': {
913 \ 'wrap': 0,
914 \ 'pos': 'botleft',
915 \ },
916 \ 'tests': both_wrap_tests + [
917 \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ],
918 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ],
919 \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ],
920 \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ],
921 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
922 \ ],
923 \ },
924 \ {
925 \ 'comment': 'left aligned with fixed position',
926 \ 'options': {
927 \ 'wrap': 0,
928 \ 'fixed': 1,
929 \ 'pos': 'botleft',
930 \ },
931 \ 'tests': both_wrap_tests + [
932 \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ],
933 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
934 \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
935 \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
936 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
937 \ ],
938 \ },
939 \ ]
940
941 for test_group in tests
942 for test in test_group.tests
943 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
944 let options = {
945 \ 'line': line,
946 \ 'col': col,
947 \ }
948 call extend( options, test_group.options )
949
950 let p = popup_create( text, options )
951
952 let msg = string( extend( options, { 'text': text } ) )
953 call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height )
954 call popup_close( p )
955 endfor
956 endfor
957
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200958 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200959 %bwipe!
960endfunc
961
Bram Moolenaar3397f742019-06-02 18:40:06 +0200962func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200963 " width of screen
964 let X = join(map(range(&columns), {->'X'}), '')
965
966 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
967 call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 )
968
969 redraw
970 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
971 call assert_equal(X, line)
972
973 call popup_close( p )
974 redraw
975
976 " Same if placed on the right hand side
977 let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } )
978 call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 )
979
980 redraw
981 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
982 call assert_equal(X, line)
983
984 call popup_close( p )
985 redraw
986
987 " Extend so > window width
988 let X .= 'x'
989
990 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
991 call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 )
992
993 redraw
994 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
995 call assert_equal(X[ : -2 ], line)
996
997 call popup_close( p )
998 redraw
999
1000 " Shifted then truncated (the x is not visible)
1001 let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } )
1002 call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 )
1003
1004 redraw
1005 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1006 call assert_equal(X[ : -2 ], line)
1007
1008 call popup_close( p )
1009 redraw
1010
1011 " Not shifted, just truncated
1012 let p = popup_create( X,
1013 \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } )
1014 call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
1015
1016 redraw
1017 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1018 let e_line = ' ' . X[ 1 : -2 ]
1019 call assert_equal(e_line, line)
1020
1021 call popup_close( p )
1022 redraw
1023
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001024 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001025 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001026endfunc
1027
1028func Test_popup_moved()
1029 new
1030 call test_override('char_avail', 1)
1031 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1032
1033 exe "normal gg0/word\<CR>"
1034 let winid = popup_atcursor('text', {'moved': 'any'})
1035 redraw
1036 call assert_equal(1, popup_getpos(winid).visible)
1037 " trigger the check for last_cursormoved by going into insert mode
1038 call feedkeys("li\<Esc>", 'xt')
1039 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001040 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001041
1042 exe "normal gg0/word\<CR>"
1043 let winid = popup_atcursor('text', {'moved': 'word'})
1044 redraw
1045 call assert_equal(1, popup_getpos(winid).visible)
1046 call feedkeys("hi\<Esc>", 'xt')
1047 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001048 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001049
1050 exe "normal gg0/word\<CR>"
1051 let winid = popup_atcursor('text', {'moved': 'word'})
1052 redraw
1053 call assert_equal(1, popup_getpos(winid).visible)
1054 call feedkeys("li\<Esc>", 'xt')
1055 call assert_equal(1, popup_getpos(winid).visible)
1056 call feedkeys("ei\<Esc>", 'xt')
1057 call assert_equal(1, popup_getpos(winid).visible)
1058 call feedkeys("eli\<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
Bram Moolenaar17627312019-06-02 19:53:44 +02001062 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001063 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001064 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001065 redraw
1066 call assert_equal(1, popup_getpos(winid).visible)
1067 call feedkeys("eli\<Esc>", 'xt')
1068 call assert_equal(1, popup_getpos(winid).visible)
1069 call feedkeys("wi\<Esc>", 'xt')
1070 call assert_equal(1, popup_getpos(winid).visible)
1071 call feedkeys("Eli\<Esc>", 'xt')
1072 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001073 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001074
1075 exe "normal gg0/word\<CR>"
1076 let winid = popup_atcursor('text', {'moved': [5, 10]})
1077 redraw
1078 call assert_equal(1, popup_getpos(winid).visible)
1079 call feedkeys("eli\<Esc>", 'xt')
1080 call feedkeys("ei\<Esc>", 'xt')
1081 call assert_equal(1, popup_getpos(winid).visible)
1082 call feedkeys("eli\<Esc>", 'xt')
1083 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001084 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001085
1086 bwipe!
1087 call test_override('ALL', 0)
1088endfunc