Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1 | " Tests for popup windows |
| 2 | |
| 3 | if !has('textprop') |
| 4 | finish |
| 5 | endif |
| 6 | |
| 7 | source screendump.vim |
| 8 | |
| 9 | func Test_simple_popup() |
| 10 | if !CanRunVimInTerminal() |
| 11 | return |
| 12 | endif |
| 13 | call writefile([ |
| 14 | \ "call setline(1, range(1, 100))", |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 15 | \ "hi PopupColor1 ctermbg=lightblue", |
| 16 | \ "hi PopupColor2 ctermbg=lightcyan", |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 17 | \ "hi Comment ctermfg=red", |
| 18 | \ "call prop_type_add('comment', {'highlight': 'Comment'})", |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 19 | \ "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 Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 21 | \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')", |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 22 | \], 'XtestPopup') |
| 23 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 24 | call VerifyScreenDump(buf, 'Test_popupwin_01', {}) |
| 25 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 26 | " Add a tabpage |
| 27 | call term_sendkeys(buf, ":tabnew\<CR>") |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 28 | call term_sendkeys(buf, ":let popupwin = popup_create([" |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 29 | \ .. "{'text': 'other tab'}," |
| 30 | \ .. "{'text': 'a comment line', 'props': [{" |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 31 | \ .. "'col': 3, 'length': 7, 'minwidth': 20, 'type': 'comment'" |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 32 | \ .. "}]}," |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 33 | \ .. "], {'line': 4, 'col': 9, 'minwidth': 20})\<CR>") |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 34 | 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 Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 44 | " resize popup, show empty line at bottom |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 45 | 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 Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 49 | " 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 54 | " clean up |
| 55 | call StopVimInTerminal(buf) |
| 56 | call delete('XtestPopup') |
| 57 | endfunc |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 58 | |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 59 | func Test_popup_with_syntax_win_execute() |
| 60 | if !CanRunVimInTerminal() |
| 61 | return |
| 62 | endif |
| 63 | call writefile([ |
| 64 | \ "call setline(1, range(1, 100))", |
| 65 | \ "hi PopupColor ctermbg=lightblue", |
| 66 | \ "let winid = popup_create([", |
| 67 | \ "\\ '#include <stdio.h>',", |
| 68 | \ "\\ 'int main(void)',", |
| 69 | \ "\\ '{',", |
| 70 | \ "\\ ' printf(123);',", |
| 71 | \ "\\ '}',", |
| 72 | \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})", |
| 73 | \ "call win_execute(winid, 'set syntax=cpp')", |
| 74 | \], 'XtestPopup') |
| 75 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 76 | call VerifyScreenDump(buf, 'Test_popupwin_10', {}) |
| 77 | |
| 78 | " clean up |
| 79 | call StopVimInTerminal(buf) |
| 80 | call delete('XtestPopup') |
| 81 | endfunc |
| 82 | |
| 83 | func Test_popup_with_syntax_setbufvar() |
| 84 | if !CanRunVimInTerminal() |
| 85 | return |
| 86 | endif |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 87 | let lines =<< trim END |
| 88 | call setline(1, range(1, 100)) |
| 89 | hi PopupColor ctermbg=lightgrey |
| 90 | let winid = popup_create([ |
| 91 | \ '#include <stdio.h>', |
| 92 | \ 'int main(void)', |
| 93 | \ '{', |
| 94 | \ ' printf(567);', |
| 95 | \ '}', |
| 96 | \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'}) |
| 97 | call setbufvar(winbufnr(winid), '&syntax', 'cpp') |
| 98 | END |
| 99 | call writefile(lines, 'XtestPopup') |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 100 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 101 | call VerifyScreenDump(buf, 'Test_popupwin_11', {}) |
| 102 | |
| 103 | " clean up |
| 104 | call StopVimInTerminal(buf) |
| 105 | call delete('XtestPopup') |
| 106 | endfunc |
| 107 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 108 | func Test_popup_with_wrap() |
| 109 | if !CanRunVimInTerminal() |
| 110 | return |
| 111 | endif |
| 112 | let lines =<< trim END |
| 113 | call setline(1, range(1, 100)) |
| 114 | let winid = popup_create( |
| 115 | \ 'a long line that wont fit', |
| 116 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1}) |
| 117 | END |
| 118 | call writefile(lines, 'XtestPopup') |
| 119 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 120 | call VerifyScreenDump(buf, 'Test_popupwin_wrap', {}) |
| 121 | |
| 122 | " clean up |
| 123 | call StopVimInTerminal(buf) |
| 124 | call delete('XtestPopup') |
| 125 | endfunc |
| 126 | |
| 127 | func Test_popup_without_wrap() |
| 128 | if !CanRunVimInTerminal() |
| 129 | return |
| 130 | endif |
| 131 | let lines =<< trim END |
| 132 | call setline(1, range(1, 100)) |
| 133 | let winid = popup_create( |
| 134 | \ 'a long line that wont fit', |
| 135 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0}) |
| 136 | END |
| 137 | call writefile(lines, 'XtestPopup') |
| 138 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 139 | call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {}) |
| 140 | |
| 141 | " clean up |
| 142 | call StopVimInTerminal(buf) |
| 143 | call delete('XtestPopup') |
| 144 | endfunc |
| 145 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 146 | func Test_popup_time() |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 147 | if !has('timers') |
| 148 | return |
| 149 | endif |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 150 | topleft vnew |
| 151 | call setline(1, 'hello') |
| 152 | |
| 153 | call popup_create('world', { |
| 154 | \ 'line': 1, |
| 155 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 156 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 157 | \ 'time': 500, |
| 158 | \}) |
| 159 | redraw |
| 160 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 161 | call assert_equal('world', line) |
| 162 | |
| 163 | sleep 700m |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 164 | redraw |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 165 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 166 | call assert_equal('hello', line) |
| 167 | |
| 168 | call popup_create('on the command line', { |
| 169 | \ 'line': &lines, |
| 170 | \ 'col': 10, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 171 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 172 | \ 'time': 500, |
| 173 | \}) |
| 174 | redraw |
| 175 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 176 | call assert_match('.*on the command line.*', line) |
| 177 | |
| 178 | sleep 700m |
| 179 | redraw |
| 180 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 181 | call assert_notmatch('.*on the command line.*', line) |
| 182 | |
| 183 | bwipe! |
| 184 | endfunc |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 185 | |
| 186 | func Test_popup_hide() |
| 187 | topleft vnew |
| 188 | call setline(1, 'hello') |
| 189 | |
| 190 | let winid = popup_create('world', { |
| 191 | \ 'line': 1, |
| 192 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 193 | \ 'minwidth': 20, |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 194 | \}) |
| 195 | redraw |
| 196 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 197 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 198 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 199 | |
| 200 | call popup_hide(winid) |
| 201 | redraw |
| 202 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 203 | call assert_equal('hello', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 204 | call assert_equal(0, popup_getpos(winid).visible) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 205 | |
| 206 | call popup_show(winid) |
| 207 | redraw |
| 208 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 209 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 210 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 211 | |
| 212 | |
| 213 | call popup_close(winid) |
| 214 | redraw |
| 215 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 216 | call assert_equal('hello', line) |
| 217 | |
| 218 | " error is given for existing non-popup window |
| 219 | call assert_fails('call popup_hide(win_getid())', 'E993:') |
| 220 | |
| 221 | " no error non-existing window |
| 222 | call popup_hide(1234234) |
| 223 | call popup_show(41234234) |
| 224 | |
| 225 | bwipe! |
| 226 | endfunc |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 227 | |
| 228 | func Test_popup_move() |
| 229 | topleft vnew |
| 230 | call setline(1, 'hello') |
| 231 | |
| 232 | let winid = popup_create('world', { |
| 233 | \ 'line': 1, |
| 234 | \ 'col': 1, |
| 235 | \ 'minwidth': 20, |
| 236 | \}) |
| 237 | redraw |
| 238 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 239 | call assert_equal('world ', line) |
| 240 | |
| 241 | call popup_move(winid, {'line': 2, 'col': 2}) |
| 242 | redraw |
| 243 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 244 | call assert_equal('hello ', line) |
| 245 | let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '') |
| 246 | call assert_equal('~world', line) |
| 247 | |
| 248 | call popup_move(winid, {'line': 1}) |
| 249 | redraw |
| 250 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 251 | call assert_equal('hworld', line) |
| 252 | |
| 253 | call popup_close(winid) |
| 254 | |
| 255 | bwipe! |
| 256 | endfunc |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 257 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 258 | func Test_popup_getpos() |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 259 | let winid = popup_create('hello', { |
| 260 | \ 'line': 2, |
| 261 | \ 'col': 3, |
| 262 | \ 'minwidth': 10, |
| 263 | \ 'minheight': 11, |
| 264 | \}) |
| 265 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 266 | let res = popup_getpos(winid) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 267 | call assert_equal(2, res.line) |
| 268 | call assert_equal(3, res.col) |
| 269 | call assert_equal(10, res.width) |
| 270 | call assert_equal(11, res.height) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 271 | call assert_equal(1, res.visible) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 272 | |
| 273 | call popup_close(winid) |
| 274 | endfunc |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 275 | |
| 276 | func Test_popup_width_longest() |
| 277 | let tests = [ |
| 278 | \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15], |
| 279 | \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15], |
| 280 | \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15], |
| 281 | \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15], |
| 282 | \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15], |
| 283 | \ ] |
| 284 | |
| 285 | for test in tests |
| 286 | let winid = popup_create(test[0], {'line': 2, 'col': 3}) |
| 287 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 288 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 289 | call assert_equal(test[1], position.width) |
| 290 | call popup_close(winid) |
| 291 | endfor |
| 292 | endfunc |
| 293 | |
| 294 | func Test_popup_wraps() |
| 295 | let tests = [ |
| 296 | \ ['nowrap', 6, 1], |
| 297 | \ ['a line that wraps once', 12, 2], |
| 298 | \ ['a line that wraps two times', 12, 3], |
| 299 | \ ] |
| 300 | for test in tests |
| 301 | let winid = popup_create(test[0], |
| 302 | \ {'line': 2, 'col': 3, 'maxwidth': 12}) |
| 303 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 304 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 305 | call assert_equal(test[1], position.width) |
| 306 | call assert_equal(test[2], position.height) |
| 307 | |
| 308 | call popup_close(winid) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 309 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 310 | endfor |
| 311 | endfunc |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 312 | |
| 313 | func Test_popup_getoptions() |
| 314 | let winid = popup_create('hello', { |
| 315 | \ 'line': 2, |
| 316 | \ 'col': 3, |
| 317 | \ 'minwidth': 10, |
| 318 | \ 'minheight': 11, |
| 319 | \ 'maxwidth': 20, |
| 320 | \ 'maxheight': 21, |
| 321 | \ 'zindex': 100, |
| 322 | \ 'time': 5000, |
| 323 | \}) |
| 324 | redraw |
| 325 | let res = popup_getoptions(winid) |
| 326 | call assert_equal(2, res.line) |
| 327 | call assert_equal(3, res.col) |
| 328 | call assert_equal(10, res.minwidth) |
| 329 | call assert_equal(11, res.minheight) |
| 330 | call assert_equal(20, res.maxwidth) |
| 331 | call assert_equal(21, res.maxheight) |
| 332 | call assert_equal(100, res.zindex) |
| 333 | if has('timers') |
| 334 | call assert_equal(5000, res.time) |
| 335 | endif |
| 336 | call popup_close(winid) |
| 337 | |
| 338 | let winid = popup_create('hello', {}) |
| 339 | redraw |
| 340 | let res = popup_getoptions(winid) |
| 341 | call assert_equal(0, res.line) |
| 342 | call assert_equal(0, res.col) |
| 343 | call assert_equal(0, res.minwidth) |
| 344 | call assert_equal(0, res.minheight) |
| 345 | call assert_equal(0, res.maxwidth) |
| 346 | call assert_equal(0, res.maxheight) |
| 347 | call assert_equal(50, res.zindex) |
| 348 | if has('timers') |
| 349 | call assert_equal(0, res.time) |
| 350 | endif |
| 351 | call popup_close(winid) |
| 352 | call assert_equal({}, popup_getoptions(winid)) |
| 353 | endfunc |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 354 | |
| 355 | func Test_popup_option_values() |
| 356 | new |
| 357 | " window-local |
| 358 | setlocal number |
| 359 | setlocal nowrap |
| 360 | " buffer-local |
| 361 | setlocal omnifunc=Something |
| 362 | " global/buffer-local |
| 363 | setlocal path=/there |
| 364 | " global/window-local |
| 365 | setlocal scrolloff=9 |
| 366 | |
| 367 | let winid = popup_create('hello', {}) |
| 368 | call assert_equal(0, getwinvar(winid, '&number')) |
| 369 | call assert_equal(1, getwinvar(winid, '&wrap')) |
| 370 | call assert_equal('', getwinvar(winid, '&omnifunc')) |
| 371 | call assert_equal(&g:path, getwinvar(winid, '&path')) |
| 372 | call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff')) |
| 373 | |
| 374 | call popup_close(winid) |
| 375 | bwipe |
| 376 | endfunc |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 377 | |
| 378 | func Test_popup_atcursor() |
| 379 | topleft vnew |
| 380 | call setline(1, [ |
| 381 | \ 'xxxxxxxxxxxxxxxxx', |
| 382 | \ 'xxxxxxxxxxxxxxxxx', |
| 383 | \ 'xxxxxxxxxxxxxxxxx', |
| 384 | \]) |
| 385 | |
| 386 | call cursor(2, 2) |
| 387 | redraw |
| 388 | let winid = popup_atcursor('vim', {}) |
| 389 | redraw |
| 390 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 391 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 392 | call popup_close(winid) |
| 393 | |
| 394 | call cursor(3, 4) |
| 395 | redraw |
| 396 | let winid = popup_atcursor('vim', {}) |
| 397 | redraw |
| 398 | let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '') |
| 399 | call assert_equal('xxxvimxxxxxxxxxxx', line) |
| 400 | call popup_close(winid) |
| 401 | |
| 402 | call cursor(1, 1) |
| 403 | redraw |
| 404 | let winid = popup_create('vim', { |
| 405 | \ 'line': 'cursor+2', |
| 406 | \ 'col': 'cursor+1', |
| 407 | \}) |
| 408 | redraw |
| 409 | let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '') |
| 410 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 411 | call popup_close(winid) |
| 412 | |
| 413 | call cursor(3, 3) |
| 414 | redraw |
| 415 | let winid = popup_create('vim', { |
| 416 | \ 'line': 'cursor-2', |
| 417 | \ 'col': 'cursor-1', |
| 418 | \}) |
| 419 | redraw |
| 420 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 421 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 422 | call popup_close(winid) |
| 423 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame^] | 424 | " just enough room above |
| 425 | call cursor(3, 3) |
| 426 | redraw |
| 427 | let winid = popup_atcursor(['vim', 'is great'], {}) |
| 428 | redraw |
| 429 | let pos = popup_getpos(winid) |
| 430 | call assert_equal(1, pos.line) |
| 431 | call popup_close(winid) |
| 432 | |
| 433 | " not enough room above, popup goes below the cursor |
| 434 | call cursor(3, 3) |
| 435 | redraw |
| 436 | let winid = popup_atcursor(['vim', 'is', 'great'], {}) |
| 437 | redraw |
| 438 | let pos = popup_getpos(winid) |
| 439 | call assert_equal(4, pos.line) |
| 440 | call popup_close(winid) |
| 441 | |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 442 | bwipe! |
| 443 | endfunc |