blob: 51eed30669648b348c138f7fb0f5c2820e65489d [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 Moolenaar17146962019-05-30 00:12:11 +020044 " resize popup, show empty line at bottom
Bram Moolenaar60cdb302019-05-27 21:54:10 +020045 call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>")
46 call term_sendkeys(buf, ":redraw\<CR>")
47 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
48
Bram Moolenaar17146962019-05-30 00:12:11 +020049 " show not fitting line at bottom
50 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
51 call term_sendkeys(buf, ":redraw\<CR>")
52 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
53
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020054 " move popup over ruler
55 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
56 call term_sendkeys(buf, ":call popup_move(popupwin, {'line': 7, 'col': 55})\<CR>")
57 call VerifyScreenDump(buf, 'Test_popupwin_07', {})
58
59 " clear all popups after moving the cursor a bit, so that ruler is updated
60 call term_sendkeys(buf, "axxx\<Esc>")
61 call term_wait(buf)
62 call term_sendkeys(buf, "0")
63 call term_wait(buf)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020064 call term_sendkeys(buf, ":call popup_clear()\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020065 call VerifyScreenDump(buf, 'Test_popupwin_08', {})
66
Bram Moolenaar4d784b22019-05-25 19:51:39 +020067 " clean up
68 call StopVimInTerminal(buf)
69 call delete('XtestPopup')
70endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020071
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020072func Test_popup_with_border_and_padding()
73 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +020074 throw 'Skipped: cannot make screendumps'
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020075 endif
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020076
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020077 for iter in range(0, 1)
78 call writefile([iter == 1 ? '' : 'set enc=latin1',
79 \ "call setline(1, range(1, 100))",
80 \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
81 \ "call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})",
82 \ "call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})",
83 \ "call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})",
84 \ "call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})",
85 \], 'XtestPopupBorder')
86 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15})
87 call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
88
89 call StopVimInTerminal(buf)
90 call delete('XtestPopupBorder')
91 endfor
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020092
Bram Moolenaar790498b2019-06-01 22:15:29 +020093 call writefile([
94 \ "call setline(1, range(1, 100))",
95 \ "hi BlueColor ctermbg=lightblue",
96 \ "hi TopColor ctermbg=253",
97 \ "hi RightColor ctermbg=245",
98 \ "hi BottomColor ctermbg=240",
99 \ "hi LeftColor ctermbg=248",
100 \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor']})",
101 \ "call popup_create(['hello border', 'and more'], {'line': 2, 'col': 23, 'border': [], 'borderhighlight': ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})",
102 \ "call popup_create(['hello border', 'lines only'], {'line': 2, 'col': 43, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x']})",
103 \ "call popup_create(['hello border', 'with corners'], {'line': 2, 'col': 60, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x', '#']})",
104 \ "call popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})",
105 \ "call popup_create(['hello border', 'just blanks'], {'line': 7, 'col': 23, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': [' ']})",
106 \], 'XtestPopupBorder')
107 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 12})
108 call VerifyScreenDump(buf, 'Test_popupwin_22', {})
109
110 call StopVimInTerminal(buf)
111 call delete('XtestPopupBorder')
112
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200113 let with_border_or_padding = {
114 \ 'line': 2,
115 \ 'core_line': 3,
116 \ 'col': 3,
117 \ 'core_col': 4,
118 \ 'width': 14,
119 \ 'core_width': 12,
120 \ 'height': 3,
121 \ 'core_height': 1,
122 \ 'visible': 1}
123 let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
124 call assert_equal(with_border_or_padding, popup_getpos(winid))
125
126 let winid = popup_create('hello paddng', {'line': 2, 'col': 3, 'padding': []})
127 call assert_equal(with_border_or_padding, popup_getpos(winid))
128
129 let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []})
130 call assert_equal({
131 \ 'line': 3,
132 \ 'core_line': 5,
133 \ 'col': 8,
134 \ 'core_col': 10,
135 \ 'width': 14,
136 \ 'core_width': 10,
137 \ 'height': 5,
138 \ 'core_height': 1,
139 \ 'visible': 1}, popup_getpos(winid))
140endfunc
141
Bram Moolenaarb4230122019-05-30 18:40:53 +0200142func Test_popup_with_syntax_win_execute()
143 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200144 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200145 endif
146 call writefile([
147 \ "call setline(1, range(1, 100))",
148 \ "hi PopupColor ctermbg=lightblue",
149 \ "let winid = popup_create([",
150 \ "\\ '#include <stdio.h>',",
151 \ "\\ 'int main(void)',",
152 \ "\\ '{',",
153 \ "\\ ' printf(123);',",
154 \ "\\ '}',",
155 \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})",
156 \ "call win_execute(winid, 'set syntax=cpp')",
157 \], 'XtestPopup')
158 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
159 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
160
161 " clean up
162 call StopVimInTerminal(buf)
163 call delete('XtestPopup')
164endfunc
165
166func Test_popup_with_syntax_setbufvar()
167 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200168 throw 'Skipped: cannot make screendumps'
Bram Moolenaarb4230122019-05-30 18:40:53 +0200169 endif
Bram Moolenaar402502d2019-05-30 22:07:36 +0200170 let lines =<< trim END
171 call setline(1, range(1, 100))
172 hi PopupColor ctermbg=lightgrey
173 let winid = popup_create([
174 \ '#include <stdio.h>',
175 \ 'int main(void)',
176 \ '{',
177 \ ' printf(567);',
178 \ '}',
179 \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})
180 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
181 END
182 call writefile(lines, 'XtestPopup')
Bram Moolenaarb4230122019-05-30 18:40:53 +0200183 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
184 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
185
186 " clean up
187 call StopVimInTerminal(buf)
188 call delete('XtestPopup')
189endfunc
190
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200191func Test_popup_with_matches()
192 if !CanRunVimInTerminal()
193 throw 'Skipped: cannot make screendumps'
194 endif
195 let lines =<< trim END
196 call setline(1, ['111 222 333', '444 555 666'])
197 let winid = popup_create([
198 \ '111 222 333',
199 \ '444 555 666',
200 \], {'line': 3, 'col': 10, 'border': []})
201 set hlsearch
202 /666
203 call matchadd('ErrorMsg', '111')
204 call matchadd('ErrorMsg', '444')
205 call win_execute(winid, "call matchadd('ErrorMsg', '111')")
206 call win_execute(winid, "call matchadd('ErrorMsg', '555')")
207 END
208 call writefile(lines, 'XtestPopupMatches')
209 let buf = RunVimInTerminal('-S XtestPopupMatches', {'rows': 10})
210 call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
211
212 " clean up
213 call StopVimInTerminal(buf)
214 call delete('XtestPopupMatches')
215endfunc
216
Bram Moolenaar399d8982019-06-02 15:34:29 +0200217func Test_popup_all_corners()
218 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200219 throw 'Skipped: cannot make screendumps'
Bram Moolenaar399d8982019-06-02 15:34:29 +0200220 endif
221 let lines =<< trim END
222 call setline(1, repeat([repeat('-', 60)], 15))
223 set so=0
224 normal 2G3|r#
225 let winid1 = popup_create(['first', 'second'], {
226 \ 'line': 'cursor+1',
227 \ 'col': 'cursor',
228 \ 'pos': 'topleft',
229 \ 'border': [],
230 \ 'padding': [],
231 \ })
232 normal 25|r@
233 let winid1 = popup_create(['First', 'SeconD'], {
234 \ 'line': 'cursor+1',
235 \ 'col': 'cursor',
236 \ 'pos': 'topright',
237 \ 'border': [],
238 \ 'padding': [],
239 \ })
240 normal 9G29|r%
241 let winid1 = popup_create(['fiRSt', 'seCOnd'], {
242 \ 'line': 'cursor-1',
243 \ 'col': 'cursor',
244 \ 'pos': 'botleft',
245 \ 'border': [],
246 \ 'padding': [],
247 \ })
248 normal 51|r&
249 let winid1 = popup_create(['FIrsT', 'SEcoND'], {
250 \ 'line': 'cursor-1',
251 \ 'col': 'cursor',
252 \ 'pos': 'botright',
253 \ 'border': [],
254 \ 'padding': [],
255 \ })
256 END
257 call writefile(lines, 'XtestPopupCorners')
258 let buf = RunVimInTerminal('-S XtestPopupCorners', {'rows': 12})
259 call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
260
261 " clean up
262 call StopVimInTerminal(buf)
263 call delete('XtestPopupCorners')
264endfunc
265
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200266func Test_popup_in_tab()
267 " default popup is local to tab, not visible when in other tab
268 let winid = popup_create("text", {})
269 call assert_equal(1, popup_getpos(winid).visible)
270 tabnew
271 call assert_equal(0, popup_getpos(winid).visible)
272 quit
273 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200274 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200275
276 " global popup is visible in any tab
277 let winid = popup_create("text", {'tab': -1})
278 call assert_equal(1, popup_getpos(winid).visible)
279 tabnew
280 call assert_equal(1, popup_getpos(winid).visible)
281 quit
282 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200283 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200284endfunc
285
286func Test_popup_valid_arguments()
287 " Zero value is like the property wasn't there
288 let winid = popup_create("text", {"col": 0})
289 let pos = popup_getpos(winid)
290 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200291 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200292
293 " using cursor column has minimum value of 1
294 let winid = popup_create("text", {"col": 'cursor-100'})
295 let pos = popup_getpos(winid)
296 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200297 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200298
299 " center
300 let winid = popup_create("text", {"pos": 'center'})
301 let pos = popup_getpos(winid)
302 let around = (&columns - pos.width) / 2
303 call assert_inrange(around - 1, around + 1, pos.col)
304 let around = (&lines - pos.height) / 2
305 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200306 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200307endfunc
308
309func Test_popup_invalid_arguments()
310 call assert_fails('call popup_create(666, {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200311 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200312 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200313 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200314
315 call assert_fails('call popup_create("text", {"col": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200316 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200317 call assert_fails('call popup_create("text", {"col": "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200318 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200319 call assert_fails('call popup_create("text", {"col": "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200320 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200321 call assert_fails('call popup_create("text", {"col": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200322 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200323
324 call assert_fails('call popup_create("text", {"line": "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200325 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200326 call assert_fails('call popup_create("text", {"line": "cursor8"})', 'E15:')
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", {"line": "cursor+x"})', '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", {"line": "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200331 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200332
333 call assert_fails('call popup_create("text", {"pos": "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200334 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200335 call assert_fails('call popup_create("text", {"padding": "none"})', 'E714:')
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", {"border": "none"})', 'E714:')
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", {"borderhighlight": "none"})', 'E714:')
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", {"borderchars": "none"})', 'E714:')
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": "text"}, 666], {})', 'E715:')
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": "text", "props": "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": "text", "props": ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200349 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200350endfunc
351
Bram Moolenaareea16992019-05-31 17:34:48 +0200352func Test_win_execute_closing_curwin()
353 split
354 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200355 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200356 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200357endfunc
358
359func Test_win_execute_not_allowed()
360 let winid = popup_create('some text', {})
361 call assert_fails('call win_execute(winid, "split")', 'E994:')
362 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
363 call assert_fails('call win_execute(winid, "close")', 'E994:')
364 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200365 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200366 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
367 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
368 call assert_fails('call win_execute(winid, "next")', 'E994:')
369 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
370 call assert_fails('call win_execute(winid, "buf")', 'E994:')
371 call assert_fails('call win_execute(winid, "edit")', 'E994:')
372 call assert_fails('call win_execute(winid, "enew")', 'E994:')
373 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
374 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
375 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
376 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200377 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200378endfunc
379
Bram Moolenaar402502d2019-05-30 22:07:36 +0200380func Test_popup_with_wrap()
381 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200382 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200383 endif
384 let lines =<< trim END
385 call setline(1, range(1, 100))
386 let winid = popup_create(
387 \ 'a long line that wont fit',
388 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
389 END
390 call writefile(lines, 'XtestPopup')
391 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
392 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
393
394 " clean up
395 call StopVimInTerminal(buf)
396 call delete('XtestPopup')
397endfunc
398
399func Test_popup_without_wrap()
400 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200401 throw 'Skipped: cannot make screendumps'
Bram Moolenaar402502d2019-05-30 22:07:36 +0200402 endif
403 let lines =<< trim END
404 call setline(1, range(1, 100))
405 let winid = popup_create(
406 \ 'a long line that wont fit',
407 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
408 END
409 call writefile(lines, 'XtestPopup')
410 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
411 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
412
413 " clean up
414 call StopVimInTerminal(buf)
415 call delete('XtestPopup')
416endfunc
417
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200418func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200419 if !has('timers')
420 return
421 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200422 topleft vnew
423 call setline(1, 'hello')
424
425 call popup_create('world', {
426 \ 'line': 1,
427 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200428 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200429 \ 'time': 500,
430 \})
431 redraw
432 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
433 call assert_equal('world', line)
434
435 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200436 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200437 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
438 call assert_equal('hello', line)
439
440 call popup_create('on the command line', {
441 \ 'line': &lines,
442 \ 'col': 10,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200443 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200444 \ 'time': 500,
445 \})
446 redraw
447 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
448 call assert_match('.*on the command line.*', line)
449
450 sleep 700m
451 redraw
452 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
453 call assert_notmatch('.*on the command line.*', line)
454
455 bwipe!
456endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200457
458func Test_popup_hide()
459 topleft vnew
460 call setline(1, 'hello')
461
462 let winid = popup_create('world', {
463 \ 'line': 1,
464 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200465 \ 'minwidth': 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200466 \})
467 redraw
468 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
469 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200470 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200471 " buffer is still listed and active
472 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200473
474 call popup_hide(winid)
475 redraw
476 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
477 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200478 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200479 " buffer is still listed but hidden
480 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200481
482 call popup_show(winid)
483 redraw
484 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
485 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200486 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200487
488
489 call popup_close(winid)
490 redraw
491 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
492 call assert_equal('hello', line)
493
494 " error is given for existing non-popup window
495 call assert_fails('call popup_hide(win_getid())', 'E993:')
496
497 " no error non-existing window
498 call popup_hide(1234234)
499 call popup_show(41234234)
500
501 bwipe!
502endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200503
504func Test_popup_move()
505 topleft vnew
506 call setline(1, 'hello')
507
508 let winid = popup_create('world', {
509 \ 'line': 1,
510 \ 'col': 1,
511 \ 'minwidth': 20,
512 \})
513 redraw
514 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
515 call assert_equal('world ', line)
516
517 call popup_move(winid, {'line': 2, 'col': 2})
518 redraw
519 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
520 call assert_equal('hello ', line)
521 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
522 call assert_equal('~world', line)
523
524 call popup_move(winid, {'line': 1})
525 redraw
526 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
527 call assert_equal('hworld', line)
528
529 call popup_close(winid)
530
531 bwipe!
532endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200533
Bram Moolenaar402502d2019-05-30 22:07:36 +0200534func Test_popup_getpos()
Bram Moolenaarbc133542019-05-29 20:26:46 +0200535 let winid = popup_create('hello', {
536 \ 'line': 2,
537 \ 'col': 3,
538 \ 'minwidth': 10,
539 \ 'minheight': 11,
540 \})
541 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200542 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200543 call assert_equal(2, res.line)
544 call assert_equal(3, res.col)
545 call assert_equal(10, res.width)
546 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200547 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200548
549 call popup_close(winid)
550endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200551
552func Test_popup_width_longest()
553 let tests = [
554 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
555 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
556 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
557 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
558 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
559 \ ]
560
561 for test in tests
562 let winid = popup_create(test[0], {'line': 2, 'col': 3})
563 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200564 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200565 call assert_equal(test[1], position.width)
566 call popup_close(winid)
567 endfor
568endfunc
569
570func Test_popup_wraps()
571 let tests = [
572 \ ['nowrap', 6, 1],
573 \ ['a line that wraps once', 12, 2],
574 \ ['a line that wraps two times', 12, 3],
575 \ ]
576 for test in tests
577 let winid = popup_create(test[0],
578 \ {'line': 2, 'col': 3, 'maxwidth': 12})
579 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200580 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200581 call assert_equal(test[1], position.width)
582 call assert_equal(test[2], position.height)
583
584 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200585 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200586 endfor
587endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200588
589func Test_popup_getoptions()
590 let winid = popup_create('hello', {
591 \ 'line': 2,
592 \ 'col': 3,
593 \ 'minwidth': 10,
594 \ 'minheight': 11,
595 \ 'maxwidth': 20,
596 \ 'maxheight': 21,
597 \ 'zindex': 100,
598 \ 'time': 5000,
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200599 \ 'fixed': 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200600 \})
601 redraw
602 let res = popup_getoptions(winid)
603 call assert_equal(2, res.line)
604 call assert_equal(3, res.col)
605 call assert_equal(10, res.minwidth)
606 call assert_equal(11, res.minheight)
607 call assert_equal(20, res.maxwidth)
608 call assert_equal(21, res.maxheight)
609 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200610 call assert_equal(1, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200611 if has('timers')
612 call assert_equal(5000, res.time)
613 endif
614 call popup_close(winid)
615
616 let winid = popup_create('hello', {})
617 redraw
618 let res = popup_getoptions(winid)
619 call assert_equal(0, res.line)
620 call assert_equal(0, res.col)
621 call assert_equal(0, res.minwidth)
622 call assert_equal(0, res.minheight)
623 call assert_equal(0, res.maxwidth)
624 call assert_equal(0, res.maxheight)
625 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200626 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200627 if has('timers')
628 call assert_equal(0, res.time)
629 endif
630 call popup_close(winid)
631 call assert_equal({}, popup_getoptions(winid))
632endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200633
634func Test_popup_option_values()
635 new
636 " window-local
637 setlocal number
638 setlocal nowrap
639 " buffer-local
640 setlocal omnifunc=Something
641 " global/buffer-local
642 setlocal path=/there
643 " global/window-local
644 setlocal scrolloff=9
645
646 let winid = popup_create('hello', {})
647 call assert_equal(0, getwinvar(winid, '&number'))
648 call assert_equal(1, getwinvar(winid, '&wrap'))
649 call assert_equal('', getwinvar(winid, '&omnifunc'))
650 call assert_equal(&g:path, getwinvar(winid, '&path'))
651 call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
652
653 call popup_close(winid)
654 bwipe
655endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200656
657func Test_popup_atcursor()
658 topleft vnew
659 call setline(1, [
660 \ 'xxxxxxxxxxxxxxxxx',
661 \ 'xxxxxxxxxxxxxxxxx',
662 \ 'xxxxxxxxxxxxxxxxx',
663 \])
664
665 call cursor(2, 2)
666 redraw
667 let winid = popup_atcursor('vim', {})
668 redraw
669 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
670 call assert_equal('xvimxxxxxxxxxxxxx', line)
671 call popup_close(winid)
672
673 call cursor(3, 4)
674 redraw
675 let winid = popup_atcursor('vim', {})
676 redraw
677 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
678 call assert_equal('xxxvimxxxxxxxxxxx', line)
679 call popup_close(winid)
680
681 call cursor(1, 1)
682 redraw
683 let winid = popup_create('vim', {
684 \ 'line': 'cursor+2',
685 \ 'col': 'cursor+1',
686 \})
687 redraw
688 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
689 call assert_equal('xvimxxxxxxxxxxxxx', line)
690 call popup_close(winid)
691
692 call cursor(3, 3)
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(1, v:val)'), '')
700 call assert_equal('xvimxxxxxxxxxxxxx', line)
701 call popup_close(winid)
702
Bram Moolenaar402502d2019-05-30 22:07:36 +0200703 " just enough room above
704 call cursor(3, 3)
705 redraw
706 let winid = popup_atcursor(['vim', 'is great'], {})
707 redraw
708 let pos = popup_getpos(winid)
709 call assert_equal(1, pos.line)
710 call popup_close(winid)
711
712 " not enough room above, popup goes below the cursor
713 call cursor(3, 3)
714 redraw
715 let winid = popup_atcursor(['vim', 'is', 'great'], {})
716 redraw
717 let pos = popup_getpos(winid)
718 call assert_equal(4, pos.line)
719 call popup_close(winid)
720
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200721 " cursor in first line, popup in line 2
722 call cursor(1, 1)
723 redraw
724 let winid = popup_atcursor(['vim', 'is', 'great'], {})
725 redraw
726 let pos = popup_getpos(winid)
727 call assert_equal(2, pos.line)
728 call popup_close(winid)
729
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200730 bwipe!
731endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200732
733func Test_popup_filter()
734 new
735 call setline(1, 'some text')
736
737 func MyPopupFilter(winid, c)
738 if a:c == 'e'
739 let g:eaten = 'e'
740 return 1
741 endif
742 if a:c == '0'
743 let g:ignored = '0'
744 return 0
745 endif
746 if a:c == 'x'
747 call popup_close(a:winid)
748 return 1
749 endif
750 return 0
751 endfunc
752
753 let winid = popup_create('something', {'filter': 'MyPopupFilter'})
754 redraw
755
756 " e is consumed by the filter
757 call feedkeys('e', 'xt')
758 call assert_equal('e', g:eaten)
759
760 " 0 is ignored by the filter
761 normal $
762 call assert_equal(9, getcurpos()[2])
763 call feedkeys('0', 'xt')
764 call assert_equal('0', g:ignored)
765 call assert_equal(1, getcurpos()[2])
766
767 " x closes the popup
768 call feedkeys('x', 'xt')
769 call assert_equal('e', g:eaten)
770 call assert_equal(-1, winbufnr(winid))
771
772 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200773 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200774endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200775
776func Test_popup_close_callback()
777 func PopupDone(id, result)
778 let g:result = a:result
779 endfunc
780 let winid = popup_create('something', {'callback': 'PopupDone'})
781 redraw
782 call popup_close(winid, 'done')
783 call assert_equal('done', g:result)
784endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +0200785
786func Test_popup_empty()
787 let winid = popup_create('', {'padding': [2,2,2,2]})
788 redraw
789 let pos = popup_getpos(winid)
790 call assert_equal(4, pos.width)
791 call assert_equal(5, pos.height)
792
793 let winid = popup_create([], {'border': []})
794 redraw
795 let pos = popup_getpos(winid)
796 call assert_equal(2, pos.width)
797 call assert_equal(3, pos.height)
798endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +0200799
800func Test_popup_never_behind()
801 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200802 throw 'Skipped: cannot make screendumps'
Bram Moolenaar988c4332019-06-02 14:12:11 +0200803 endif
804 " +-----------------------------+
805 " | | |
806 " | | |
807 " | | |
808 " | line1 |
809 " |------------line2------------|
810 " | line3 |
811 " | line4 |
812 " | |
813 " | |
814 " +-----------------------------+
815 let lines =<< trim END
816 only
817 split
818 vsplit
819 let info_window1 = getwininfo()[0]
820 let line = info_window1['height']
821 let col = info_window1['width']
822 call popup_create(['line1', 'line2', 'line3', 'line4'], {
823 \ 'line' : line,
824 \ 'col' : col,
825 \ })
826 END
827 call writefile(lines, 'XtestPopupBehind')
828 let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10})
829 call term_sendkeys(buf, "\<C-W>w")
830 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
831
832 " clean up
833 call StopVimInTerminal(buf)
834 call delete('XtestPopupBehind')
835endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200836
837func s:VerifyPosition( p, msg, line, col, width, height )
838 call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' )
839 call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' )
840 call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' )
841 call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' )
842endfunc
843
844func Test_popup_position_adjust()
845 " Anything placed past 2 cells from of the right of the screen is moved to the
846 " left.
847 "
848 " When wrapping is disabled, we also shift to the left to display on the
849 " screen, unless fixed is set.
850
851 " Entries for cases which don't vary based on wrapping.
852 " Format is per tests described below
853 let both_wrap_tests = [
854 \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ],
855 \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ],
856 \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ],
857 \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ],
858 \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ],
859 \
860 \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ],
861 \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ],
862 \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ],
863 \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ],
864 \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ],
865 \
866 \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ],
867 \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
868 \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
869 \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
870 \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ],
871 \ ]
872
873 " these test groups are dicts with:
874 " - comment: something to identify the group of tests by
875 " - options: dict of options to merge with the row/col in tests
876 " - tests: list of cases. Each one is a list with elements:
877 " - text
878 " - row
879 " - col
880 " - expected row
881 " - expected col
882 " - expected width
883 " - expected height
884 let tests = [
885 \ {
886 \ 'comment': 'left-aligned with wrapping',
887 \ 'options': {
888 \ 'wrap': 1,
889 \ 'pos': 'botleft',
890 \ },
891 \ 'tests': both_wrap_tests + [
892 \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ],
893 \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ],
894 \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ],
895 \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ],
896 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
897 \ ],
898 \ },
899 \ {
900 \ 'comment': 'left aligned without wrapping',
901 \ 'options': {
902 \ 'wrap': 0,
903 \ 'pos': 'botleft',
904 \ },
905 \ 'tests': both_wrap_tests + [
906 \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ],
907 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ],
908 \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ],
909 \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ],
910 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
911 \ ],
912 \ },
913 \ {
914 \ 'comment': 'left aligned with fixed position',
915 \ 'options': {
916 \ 'wrap': 0,
917 \ 'fixed': 1,
918 \ 'pos': 'botleft',
919 \ },
920 \ 'tests': both_wrap_tests + [
921 \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ],
922 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
923 \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
924 \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
925 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
926 \ ],
927 \ },
928 \ ]
929
930 for test_group in tests
931 for test in test_group.tests
932 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
933 let options = {
934 \ 'line': line,
935 \ 'col': col,
936 \ }
937 call extend( options, test_group.options )
938
939 let p = popup_create( text, options )
940
941 let msg = string( extend( options, { 'text': text } ) )
942 call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height )
943 call popup_close( p )
944 endfor
945 endfor
946
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200947 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200948 %bwipe!
949endfunc
950
Bram Moolenaar3397f742019-06-02 18:40:06 +0200951func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200952 " width of screen
953 let X = join(map(range(&columns), {->'X'}), '')
954
955 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
956 call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 )
957
958 redraw
959 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
960 call assert_equal(X, line)
961
962 call popup_close( p )
963 redraw
964
965 " Same if placed on the right hand side
966 let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } )
967 call s:VerifyPosition( p, 'full width topright', 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 " Extend so > window width
977 let X .= 'x'
978
979 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
980 call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 )
981
982 redraw
983 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
984 call assert_equal(X[ : -2 ], line)
985
986 call popup_close( p )
987 redraw
988
989 " Shifted then truncated (the x is not visible)
990 let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } )
991 call s:VerifyPosition( p, 'full width + 1 topright', 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 " Not shifted, just truncated
1001 let p = popup_create( X,
1002 \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } )
1003 call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
1004
1005 redraw
1006 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1007 let e_line = ' ' . X[ 1 : -2 ]
1008 call assert_equal(e_line, line)
1009
1010 call popup_close( p )
1011 redraw
1012
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001013 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001014 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001015endfunc
1016
1017func Test_popup_moved()
1018 new
1019 call test_override('char_avail', 1)
1020 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1021
1022 exe "normal gg0/word\<CR>"
1023 let winid = popup_atcursor('text', {'moved': 'any'})
1024 redraw
1025 call assert_equal(1, popup_getpos(winid).visible)
1026 " trigger the check for last_cursormoved by going into insert mode
1027 call feedkeys("li\<Esc>", 'xt')
1028 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001029 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001030
1031 exe "normal gg0/word\<CR>"
1032 let winid = popup_atcursor('text', {'moved': 'word'})
1033 redraw
1034 call assert_equal(1, popup_getpos(winid).visible)
1035 call feedkeys("hi\<Esc>", 'xt')
1036 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001037 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001038
1039 exe "normal gg0/word\<CR>"
1040 let winid = popup_atcursor('text', {'moved': 'word'})
1041 redraw
1042 call assert_equal(1, popup_getpos(winid).visible)
1043 call feedkeys("li\<Esc>", 'xt')
1044 call assert_equal(1, popup_getpos(winid).visible)
1045 call feedkeys("ei\<Esc>", 'xt')
1046 call assert_equal(1, popup_getpos(winid).visible)
1047 call feedkeys("eli\<Esc>", 'xt')
1048 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001049 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001050
Bram Moolenaar17627312019-06-02 19:53:44 +02001051 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001052 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001053 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001054 redraw
1055 call assert_equal(1, popup_getpos(winid).visible)
1056 call feedkeys("eli\<Esc>", 'xt')
1057 call assert_equal(1, popup_getpos(winid).visible)
1058 call feedkeys("wi\<Esc>", 'xt')
1059 call assert_equal(1, popup_getpos(winid).visible)
1060 call feedkeys("Eli\<Esc>", 'xt')
1061 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001062 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001063
1064 exe "normal gg0/word\<CR>"
1065 let winid = popup_atcursor('text', {'moved': [5, 10]})
1066 redraw
1067 call assert_equal(1, popup_getpos(winid).visible)
1068 call feedkeys("eli\<Esc>", 'xt')
1069 call feedkeys("ei\<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 bwipe!
1076 call test_override('ALL', 0)
1077endfunc