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 | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 108 | func Test_win_execute_closing_curwin() |
| 109 | split |
| 110 | let winid = popup_create('some text', {}) |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 111 | call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994') |
| 112 | popupclear |
| 113 | endfunc |
| 114 | |
| 115 | func Test_win_execute_not_allowed() |
| 116 | let winid = popup_create('some text', {}) |
| 117 | call assert_fails('call win_execute(winid, "split")', 'E994:') |
| 118 | call assert_fails('call win_execute(winid, "vsplit")', 'E994:') |
| 119 | call assert_fails('call win_execute(winid, "close")', 'E994:') |
| 120 | call assert_fails('call win_execute(winid, "bdelete")', 'E994:') |
| 121 | call assert_fails('call win_execute(winid, "tabnew")', 'E994:') |
| 122 | call assert_fails('call win_execute(winid, "tabnext")', 'E994:') |
| 123 | call assert_fails('call win_execute(winid, "next")', 'E994:') |
| 124 | call assert_fails('call win_execute(winid, "rewind")', 'E994:') |
| 125 | call assert_fails('call win_execute(winid, "buf")', 'E994:') |
| 126 | call assert_fails('call win_execute(winid, "edit")', 'E994:') |
| 127 | call assert_fails('call win_execute(winid, "enew")', 'E994:') |
| 128 | call assert_fails('call win_execute(winid, "wincmd x")', 'E994:') |
| 129 | call assert_fails('call win_execute(winid, "wincmd w")', 'E994:') |
| 130 | call assert_fails('call win_execute(winid, "wincmd t")', 'E994:') |
| 131 | call assert_fails('call win_execute(winid, "wincmd b")', 'E994:') |
Bram Moolenaar | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 132 | popupclear |
| 133 | endfunc |
| 134 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 135 | func Test_popup_with_wrap() |
| 136 | if !CanRunVimInTerminal() |
| 137 | return |
| 138 | endif |
| 139 | let lines =<< trim END |
| 140 | call setline(1, range(1, 100)) |
| 141 | let winid = popup_create( |
| 142 | \ 'a long line that wont fit', |
| 143 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1}) |
| 144 | END |
| 145 | call writefile(lines, 'XtestPopup') |
| 146 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 147 | call VerifyScreenDump(buf, 'Test_popupwin_wrap', {}) |
| 148 | |
| 149 | " clean up |
| 150 | call StopVimInTerminal(buf) |
| 151 | call delete('XtestPopup') |
| 152 | endfunc |
| 153 | |
| 154 | func Test_popup_without_wrap() |
| 155 | if !CanRunVimInTerminal() |
| 156 | return |
| 157 | endif |
| 158 | let lines =<< trim END |
| 159 | call setline(1, range(1, 100)) |
| 160 | let winid = popup_create( |
| 161 | \ 'a long line that wont fit', |
| 162 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0}) |
| 163 | END |
| 164 | call writefile(lines, 'XtestPopup') |
| 165 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 166 | call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {}) |
| 167 | |
| 168 | " clean up |
| 169 | call StopVimInTerminal(buf) |
| 170 | call delete('XtestPopup') |
| 171 | endfunc |
| 172 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 173 | func Test_popup_time() |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 174 | if !has('timers') |
| 175 | return |
| 176 | endif |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 177 | topleft vnew |
| 178 | call setline(1, 'hello') |
| 179 | |
| 180 | call popup_create('world', { |
| 181 | \ 'line': 1, |
| 182 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 183 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 184 | \ 'time': 500, |
| 185 | \}) |
| 186 | redraw |
| 187 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 188 | call assert_equal('world', line) |
| 189 | |
| 190 | sleep 700m |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 191 | redraw |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 192 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 193 | call assert_equal('hello', line) |
| 194 | |
| 195 | call popup_create('on the command line', { |
| 196 | \ 'line': &lines, |
| 197 | \ 'col': 10, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 198 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 199 | \ 'time': 500, |
| 200 | \}) |
| 201 | redraw |
| 202 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 203 | call assert_match('.*on the command line.*', line) |
| 204 | |
| 205 | sleep 700m |
| 206 | redraw |
| 207 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 208 | call assert_notmatch('.*on the command line.*', line) |
| 209 | |
| 210 | bwipe! |
| 211 | endfunc |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 212 | |
| 213 | func Test_popup_hide() |
| 214 | topleft vnew |
| 215 | call setline(1, 'hello') |
| 216 | |
| 217 | let winid = popup_create('world', { |
| 218 | \ 'line': 1, |
| 219 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 220 | \ 'minwidth': 20, |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 221 | \}) |
| 222 | redraw |
| 223 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 224 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 225 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 226 | " buffer is still listed and active |
| 227 | call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 228 | |
| 229 | call popup_hide(winid) |
| 230 | redraw |
| 231 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 232 | call assert_equal('hello', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 233 | call assert_equal(0, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 234 | " buffer is still listed but hidden |
| 235 | call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 236 | |
| 237 | call popup_show(winid) |
| 238 | redraw |
| 239 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 240 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 241 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 242 | |
| 243 | |
| 244 | call popup_close(winid) |
| 245 | redraw |
| 246 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 247 | call assert_equal('hello', line) |
| 248 | |
| 249 | " error is given for existing non-popup window |
| 250 | call assert_fails('call popup_hide(win_getid())', 'E993:') |
| 251 | |
| 252 | " no error non-existing window |
| 253 | call popup_hide(1234234) |
| 254 | call popup_show(41234234) |
| 255 | |
| 256 | bwipe! |
| 257 | endfunc |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 258 | |
| 259 | func Test_popup_move() |
| 260 | topleft vnew |
| 261 | call setline(1, 'hello') |
| 262 | |
| 263 | let winid = popup_create('world', { |
| 264 | \ 'line': 1, |
| 265 | \ 'col': 1, |
| 266 | \ 'minwidth': 20, |
| 267 | \}) |
| 268 | redraw |
| 269 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 270 | call assert_equal('world ', line) |
| 271 | |
| 272 | call popup_move(winid, {'line': 2, 'col': 2}) |
| 273 | redraw |
| 274 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 275 | call assert_equal('hello ', line) |
| 276 | let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '') |
| 277 | call assert_equal('~world', line) |
| 278 | |
| 279 | call popup_move(winid, {'line': 1}) |
| 280 | redraw |
| 281 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 282 | call assert_equal('hworld', line) |
| 283 | |
| 284 | call popup_close(winid) |
| 285 | |
| 286 | bwipe! |
| 287 | endfunc |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 288 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 289 | func Test_popup_getpos() |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 290 | let winid = popup_create('hello', { |
| 291 | \ 'line': 2, |
| 292 | \ 'col': 3, |
| 293 | \ 'minwidth': 10, |
| 294 | \ 'minheight': 11, |
| 295 | \}) |
| 296 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 297 | let res = popup_getpos(winid) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 298 | call assert_equal(2, res.line) |
| 299 | call assert_equal(3, res.col) |
| 300 | call assert_equal(10, res.width) |
| 301 | call assert_equal(11, res.height) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 302 | call assert_equal(1, res.visible) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 303 | |
| 304 | call popup_close(winid) |
| 305 | endfunc |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 306 | |
| 307 | func Test_popup_width_longest() |
| 308 | let tests = [ |
| 309 | \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15], |
| 310 | \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15], |
| 311 | \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15], |
| 312 | \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15], |
| 313 | \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15], |
| 314 | \ ] |
| 315 | |
| 316 | for test in tests |
| 317 | let winid = popup_create(test[0], {'line': 2, 'col': 3}) |
| 318 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 319 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 320 | call assert_equal(test[1], position.width) |
| 321 | call popup_close(winid) |
| 322 | endfor |
| 323 | endfunc |
| 324 | |
| 325 | func Test_popup_wraps() |
| 326 | let tests = [ |
| 327 | \ ['nowrap', 6, 1], |
| 328 | \ ['a line that wraps once', 12, 2], |
| 329 | \ ['a line that wraps two times', 12, 3], |
| 330 | \ ] |
| 331 | for test in tests |
| 332 | let winid = popup_create(test[0], |
| 333 | \ {'line': 2, 'col': 3, 'maxwidth': 12}) |
| 334 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 335 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 336 | call assert_equal(test[1], position.width) |
| 337 | call assert_equal(test[2], position.height) |
| 338 | |
| 339 | call popup_close(winid) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 340 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 341 | endfor |
| 342 | endfunc |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 343 | |
| 344 | func Test_popup_getoptions() |
| 345 | let winid = popup_create('hello', { |
| 346 | \ 'line': 2, |
| 347 | \ 'col': 3, |
| 348 | \ 'minwidth': 10, |
| 349 | \ 'minheight': 11, |
| 350 | \ 'maxwidth': 20, |
| 351 | \ 'maxheight': 21, |
| 352 | \ 'zindex': 100, |
| 353 | \ 'time': 5000, |
| 354 | \}) |
| 355 | redraw |
| 356 | let res = popup_getoptions(winid) |
| 357 | call assert_equal(2, res.line) |
| 358 | call assert_equal(3, res.col) |
| 359 | call assert_equal(10, res.minwidth) |
| 360 | call assert_equal(11, res.minheight) |
| 361 | call assert_equal(20, res.maxwidth) |
| 362 | call assert_equal(21, res.maxheight) |
| 363 | call assert_equal(100, res.zindex) |
| 364 | if has('timers') |
| 365 | call assert_equal(5000, res.time) |
| 366 | endif |
| 367 | call popup_close(winid) |
| 368 | |
| 369 | let winid = popup_create('hello', {}) |
| 370 | redraw |
| 371 | let res = popup_getoptions(winid) |
| 372 | call assert_equal(0, res.line) |
| 373 | call assert_equal(0, res.col) |
| 374 | call assert_equal(0, res.minwidth) |
| 375 | call assert_equal(0, res.minheight) |
| 376 | call assert_equal(0, res.maxwidth) |
| 377 | call assert_equal(0, res.maxheight) |
| 378 | call assert_equal(50, res.zindex) |
| 379 | if has('timers') |
| 380 | call assert_equal(0, res.time) |
| 381 | endif |
| 382 | call popup_close(winid) |
| 383 | call assert_equal({}, popup_getoptions(winid)) |
| 384 | endfunc |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 385 | |
| 386 | func Test_popup_option_values() |
| 387 | new |
| 388 | " window-local |
| 389 | setlocal number |
| 390 | setlocal nowrap |
| 391 | " buffer-local |
| 392 | setlocal omnifunc=Something |
| 393 | " global/buffer-local |
| 394 | setlocal path=/there |
| 395 | " global/window-local |
| 396 | setlocal scrolloff=9 |
| 397 | |
| 398 | let winid = popup_create('hello', {}) |
| 399 | call assert_equal(0, getwinvar(winid, '&number')) |
| 400 | call assert_equal(1, getwinvar(winid, '&wrap')) |
| 401 | call assert_equal('', getwinvar(winid, '&omnifunc')) |
| 402 | call assert_equal(&g:path, getwinvar(winid, '&path')) |
| 403 | call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff')) |
| 404 | |
| 405 | call popup_close(winid) |
| 406 | bwipe |
| 407 | endfunc |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 408 | |
| 409 | func Test_popup_atcursor() |
| 410 | topleft vnew |
| 411 | call setline(1, [ |
| 412 | \ 'xxxxxxxxxxxxxxxxx', |
| 413 | \ 'xxxxxxxxxxxxxxxxx', |
| 414 | \ 'xxxxxxxxxxxxxxxxx', |
| 415 | \]) |
| 416 | |
| 417 | call cursor(2, 2) |
| 418 | redraw |
| 419 | let winid = popup_atcursor('vim', {}) |
| 420 | redraw |
| 421 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 422 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 423 | call popup_close(winid) |
| 424 | |
| 425 | call cursor(3, 4) |
| 426 | redraw |
| 427 | let winid = popup_atcursor('vim', {}) |
| 428 | redraw |
| 429 | let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '') |
| 430 | call assert_equal('xxxvimxxxxxxxxxxx', line) |
| 431 | call popup_close(winid) |
| 432 | |
| 433 | call cursor(1, 1) |
| 434 | redraw |
| 435 | let winid = popup_create('vim', { |
| 436 | \ 'line': 'cursor+2', |
| 437 | \ 'col': 'cursor+1', |
| 438 | \}) |
| 439 | redraw |
| 440 | let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '') |
| 441 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 442 | call popup_close(winid) |
| 443 | |
| 444 | call cursor(3, 3) |
| 445 | redraw |
| 446 | let winid = popup_create('vim', { |
| 447 | \ 'line': 'cursor-2', |
| 448 | \ 'col': 'cursor-1', |
| 449 | \}) |
| 450 | redraw |
| 451 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 452 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 453 | call popup_close(winid) |
| 454 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 455 | " just enough room above |
| 456 | call cursor(3, 3) |
| 457 | redraw |
| 458 | let winid = popup_atcursor(['vim', 'is great'], {}) |
| 459 | redraw |
| 460 | let pos = popup_getpos(winid) |
| 461 | call assert_equal(1, pos.line) |
| 462 | call popup_close(winid) |
| 463 | |
| 464 | " not enough room above, popup goes below the cursor |
| 465 | call cursor(3, 3) |
| 466 | redraw |
| 467 | let winid = popup_atcursor(['vim', 'is', 'great'], {}) |
| 468 | redraw |
| 469 | let pos = popup_getpos(winid) |
| 470 | call assert_equal(4, pos.line) |
| 471 | call popup_close(winid) |
| 472 | |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 473 | bwipe! |
| 474 | endfunc |