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 | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 59 | func Test_popup_with_border_and_padding() |
| 60 | if !CanRunVimInTerminal() |
| 61 | return |
| 62 | endif |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 63 | |
Bram Moolenaar | 3bfd04e | 2019-06-01 20:45:21 +0200 | [diff] [blame] | 64 | for iter in range(0, 1) |
| 65 | call writefile([iter == 1 ? '' : 'set enc=latin1', |
| 66 | \ "call setline(1, range(1, 100))", |
| 67 | \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})", |
| 68 | \ "call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})", |
| 69 | \ "call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})", |
| 70 | \ "call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})", |
| 71 | \ "call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})", |
| 72 | \], 'XtestPopupBorder') |
| 73 | let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15}) |
| 74 | call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {}) |
| 75 | |
| 76 | call StopVimInTerminal(buf) |
| 77 | call delete('XtestPopupBorder') |
| 78 | endfor |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 79 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 80 | call writefile([ |
| 81 | \ "call setline(1, range(1, 100))", |
| 82 | \ "hi BlueColor ctermbg=lightblue", |
| 83 | \ "hi TopColor ctermbg=253", |
| 84 | \ "hi RightColor ctermbg=245", |
| 85 | \ "hi BottomColor ctermbg=240", |
| 86 | \ "hi LeftColor ctermbg=248", |
| 87 | \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor']})", |
| 88 | \ "call popup_create(['hello border', 'and more'], {'line': 2, 'col': 23, 'border': [], 'borderhighlight': ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})", |
| 89 | \ "call popup_create(['hello border', 'lines only'], {'line': 2, 'col': 43, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x']})", |
| 90 | \ "call popup_create(['hello border', 'with corners'], {'line': 2, 'col': 60, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x', '#']})", |
| 91 | \ "call popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})", |
| 92 | \ "call popup_create(['hello border', 'just blanks'], {'line': 7, 'col': 23, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': [' ']})", |
| 93 | \], 'XtestPopupBorder') |
| 94 | let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 12}) |
| 95 | call VerifyScreenDump(buf, 'Test_popupwin_22', {}) |
| 96 | |
| 97 | call StopVimInTerminal(buf) |
| 98 | call delete('XtestPopupBorder') |
| 99 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 100 | let with_border_or_padding = { |
| 101 | \ 'line': 2, |
| 102 | \ 'core_line': 3, |
| 103 | \ 'col': 3, |
| 104 | \ 'core_col': 4, |
| 105 | \ 'width': 14, |
| 106 | \ 'core_width': 12, |
| 107 | \ 'height': 3, |
| 108 | \ 'core_height': 1, |
| 109 | \ 'visible': 1} |
| 110 | let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})", |
| 111 | call assert_equal(with_border_or_padding, popup_getpos(winid)) |
| 112 | |
| 113 | let winid = popup_create('hello paddng', {'line': 2, 'col': 3, 'padding': []}) |
| 114 | call assert_equal(with_border_or_padding, popup_getpos(winid)) |
| 115 | |
| 116 | let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []}) |
| 117 | call assert_equal({ |
| 118 | \ 'line': 3, |
| 119 | \ 'core_line': 5, |
| 120 | \ 'col': 8, |
| 121 | \ 'core_col': 10, |
| 122 | \ 'width': 14, |
| 123 | \ 'core_width': 10, |
| 124 | \ 'height': 5, |
| 125 | \ 'core_height': 1, |
| 126 | \ 'visible': 1}, popup_getpos(winid)) |
| 127 | endfunc |
| 128 | |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 129 | func Test_popup_with_syntax_win_execute() |
| 130 | if !CanRunVimInTerminal() |
| 131 | return |
| 132 | endif |
| 133 | call writefile([ |
| 134 | \ "call setline(1, range(1, 100))", |
| 135 | \ "hi PopupColor ctermbg=lightblue", |
| 136 | \ "let winid = popup_create([", |
| 137 | \ "\\ '#include <stdio.h>',", |
| 138 | \ "\\ 'int main(void)',", |
| 139 | \ "\\ '{',", |
| 140 | \ "\\ ' printf(123);',", |
| 141 | \ "\\ '}',", |
| 142 | \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})", |
| 143 | \ "call win_execute(winid, 'set syntax=cpp')", |
| 144 | \], 'XtestPopup') |
| 145 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 146 | call VerifyScreenDump(buf, 'Test_popupwin_10', {}) |
| 147 | |
| 148 | " clean up |
| 149 | call StopVimInTerminal(buf) |
| 150 | call delete('XtestPopup') |
| 151 | endfunc |
| 152 | |
| 153 | func Test_popup_with_syntax_setbufvar() |
| 154 | if !CanRunVimInTerminal() |
| 155 | return |
| 156 | endif |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 157 | let lines =<< trim END |
| 158 | call setline(1, range(1, 100)) |
| 159 | hi PopupColor ctermbg=lightgrey |
| 160 | let winid = popup_create([ |
| 161 | \ '#include <stdio.h>', |
| 162 | \ 'int main(void)', |
| 163 | \ '{', |
| 164 | \ ' printf(567);', |
| 165 | \ '}', |
| 166 | \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'}) |
| 167 | call setbufvar(winbufnr(winid), '&syntax', 'cpp') |
| 168 | END |
| 169 | call writefile(lines, 'XtestPopup') |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 170 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 171 | call VerifyScreenDump(buf, 'Test_popupwin_11', {}) |
| 172 | |
| 173 | " clean up |
| 174 | call StopVimInTerminal(buf) |
| 175 | call delete('XtestPopup') |
| 176 | endfunc |
| 177 | |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 178 | func Test_popup_all_corners() |
| 179 | if !CanRunVimInTerminal() |
| 180 | return |
| 181 | endif |
| 182 | let lines =<< trim END |
| 183 | call setline(1, repeat([repeat('-', 60)], 15)) |
| 184 | set so=0 |
| 185 | normal 2G3|r# |
| 186 | let winid1 = popup_create(['first', 'second'], { |
| 187 | \ 'line': 'cursor+1', |
| 188 | \ 'col': 'cursor', |
| 189 | \ 'pos': 'topleft', |
| 190 | \ 'border': [], |
| 191 | \ 'padding': [], |
| 192 | \ }) |
| 193 | normal 25|r@ |
| 194 | let winid1 = popup_create(['First', 'SeconD'], { |
| 195 | \ 'line': 'cursor+1', |
| 196 | \ 'col': 'cursor', |
| 197 | \ 'pos': 'topright', |
| 198 | \ 'border': [], |
| 199 | \ 'padding': [], |
| 200 | \ }) |
| 201 | normal 9G29|r% |
| 202 | let winid1 = popup_create(['fiRSt', 'seCOnd'], { |
| 203 | \ 'line': 'cursor-1', |
| 204 | \ 'col': 'cursor', |
| 205 | \ 'pos': 'botleft', |
| 206 | \ 'border': [], |
| 207 | \ 'padding': [], |
| 208 | \ }) |
| 209 | normal 51|r& |
| 210 | let winid1 = popup_create(['FIrsT', 'SEcoND'], { |
| 211 | \ 'line': 'cursor-1', |
| 212 | \ 'col': 'cursor', |
| 213 | \ 'pos': 'botright', |
| 214 | \ 'border': [], |
| 215 | \ 'padding': [], |
| 216 | \ }) |
| 217 | END |
| 218 | call writefile(lines, 'XtestPopupCorners') |
| 219 | let buf = RunVimInTerminal('-S XtestPopupCorners', {'rows': 12}) |
| 220 | call VerifyScreenDump(buf, 'Test_popupwin_corners', {}) |
| 221 | |
| 222 | " clean up |
| 223 | call StopVimInTerminal(buf) |
| 224 | call delete('XtestPopupCorners') |
| 225 | endfunc |
| 226 | |
Bram Moolenaar | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 227 | func Test_win_execute_closing_curwin() |
| 228 | split |
| 229 | let winid = popup_create('some text', {}) |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 230 | call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994') |
| 231 | popupclear |
| 232 | endfunc |
| 233 | |
| 234 | func Test_win_execute_not_allowed() |
| 235 | let winid = popup_create('some text', {}) |
| 236 | call assert_fails('call win_execute(winid, "split")', 'E994:') |
| 237 | call assert_fails('call win_execute(winid, "vsplit")', 'E994:') |
| 238 | call assert_fails('call win_execute(winid, "close")', 'E994:') |
| 239 | call assert_fails('call win_execute(winid, "bdelete")', 'E994:') |
Bram Moolenaar | 2d24784 | 2019-06-01 17:06:25 +0200 | [diff] [blame] | 240 | call assert_fails('call win_execute(winid, "bwipe!")', 'E994:') |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 241 | call assert_fails('call win_execute(winid, "tabnew")', 'E994:') |
| 242 | call assert_fails('call win_execute(winid, "tabnext")', 'E994:') |
| 243 | call assert_fails('call win_execute(winid, "next")', 'E994:') |
| 244 | call assert_fails('call win_execute(winid, "rewind")', 'E994:') |
| 245 | call assert_fails('call win_execute(winid, "buf")', 'E994:') |
| 246 | call assert_fails('call win_execute(winid, "edit")', 'E994:') |
| 247 | call assert_fails('call win_execute(winid, "enew")', 'E994:') |
| 248 | call assert_fails('call win_execute(winid, "wincmd x")', 'E994:') |
| 249 | call assert_fails('call win_execute(winid, "wincmd w")', 'E994:') |
| 250 | call assert_fails('call win_execute(winid, "wincmd t")', 'E994:') |
| 251 | call assert_fails('call win_execute(winid, "wincmd b")', 'E994:') |
Bram Moolenaar | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 252 | popupclear |
| 253 | endfunc |
| 254 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 255 | func Test_popup_with_wrap() |
| 256 | if !CanRunVimInTerminal() |
| 257 | return |
| 258 | endif |
| 259 | let lines =<< trim END |
| 260 | call setline(1, range(1, 100)) |
| 261 | let winid = popup_create( |
| 262 | \ 'a long line that wont fit', |
| 263 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1}) |
| 264 | END |
| 265 | call writefile(lines, 'XtestPopup') |
| 266 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 267 | call VerifyScreenDump(buf, 'Test_popupwin_wrap', {}) |
| 268 | |
| 269 | " clean up |
| 270 | call StopVimInTerminal(buf) |
| 271 | call delete('XtestPopup') |
| 272 | endfunc |
| 273 | |
| 274 | func Test_popup_without_wrap() |
| 275 | if !CanRunVimInTerminal() |
| 276 | return |
| 277 | endif |
| 278 | let lines =<< trim END |
| 279 | call setline(1, range(1, 100)) |
| 280 | let winid = popup_create( |
| 281 | \ 'a long line that wont fit', |
| 282 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0}) |
| 283 | END |
| 284 | call writefile(lines, 'XtestPopup') |
| 285 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 286 | call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {}) |
| 287 | |
| 288 | " clean up |
| 289 | call StopVimInTerminal(buf) |
| 290 | call delete('XtestPopup') |
| 291 | endfunc |
| 292 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 293 | func Test_popup_time() |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 294 | if !has('timers') |
| 295 | return |
| 296 | endif |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 297 | topleft vnew |
| 298 | call setline(1, 'hello') |
| 299 | |
| 300 | call popup_create('world', { |
| 301 | \ 'line': 1, |
| 302 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 303 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 304 | \ 'time': 500, |
| 305 | \}) |
| 306 | redraw |
| 307 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 308 | call assert_equal('world', line) |
| 309 | |
| 310 | sleep 700m |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 311 | redraw |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 312 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 313 | call assert_equal('hello', line) |
| 314 | |
| 315 | call popup_create('on the command line', { |
| 316 | \ 'line': &lines, |
| 317 | \ 'col': 10, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 318 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 319 | \ 'time': 500, |
| 320 | \}) |
| 321 | redraw |
| 322 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 323 | call assert_match('.*on the command line.*', line) |
| 324 | |
| 325 | sleep 700m |
| 326 | redraw |
| 327 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 328 | call assert_notmatch('.*on the command line.*', line) |
| 329 | |
| 330 | bwipe! |
| 331 | endfunc |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 332 | |
| 333 | func Test_popup_hide() |
| 334 | topleft vnew |
| 335 | call setline(1, 'hello') |
| 336 | |
| 337 | let winid = popup_create('world', { |
| 338 | \ 'line': 1, |
| 339 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 340 | \ 'minwidth': 20, |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 341 | \}) |
| 342 | redraw |
| 343 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 344 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 345 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 346 | " buffer is still listed and active |
| 347 | call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 348 | |
| 349 | call popup_hide(winid) |
| 350 | redraw |
| 351 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 352 | call assert_equal('hello', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 353 | call assert_equal(0, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 354 | " buffer is still listed but hidden |
| 355 | call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 356 | |
| 357 | call popup_show(winid) |
| 358 | redraw |
| 359 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 360 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 361 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 362 | |
| 363 | |
| 364 | call popup_close(winid) |
| 365 | redraw |
| 366 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 367 | call assert_equal('hello', line) |
| 368 | |
| 369 | " error is given for existing non-popup window |
| 370 | call assert_fails('call popup_hide(win_getid())', 'E993:') |
| 371 | |
| 372 | " no error non-existing window |
| 373 | call popup_hide(1234234) |
| 374 | call popup_show(41234234) |
| 375 | |
| 376 | bwipe! |
| 377 | endfunc |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 378 | |
| 379 | func Test_popup_move() |
| 380 | topleft vnew |
| 381 | call setline(1, 'hello') |
| 382 | |
| 383 | let winid = popup_create('world', { |
| 384 | \ 'line': 1, |
| 385 | \ 'col': 1, |
| 386 | \ 'minwidth': 20, |
| 387 | \}) |
| 388 | redraw |
| 389 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 390 | call assert_equal('world ', line) |
| 391 | |
| 392 | call popup_move(winid, {'line': 2, 'col': 2}) |
| 393 | redraw |
| 394 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 395 | call assert_equal('hello ', line) |
| 396 | let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '') |
| 397 | call assert_equal('~world', line) |
| 398 | |
| 399 | call popup_move(winid, {'line': 1}) |
| 400 | redraw |
| 401 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 402 | call assert_equal('hworld', line) |
| 403 | |
| 404 | call popup_close(winid) |
| 405 | |
| 406 | bwipe! |
| 407 | endfunc |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 408 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 409 | func Test_popup_getpos() |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 410 | let winid = popup_create('hello', { |
| 411 | \ 'line': 2, |
| 412 | \ 'col': 3, |
| 413 | \ 'minwidth': 10, |
| 414 | \ 'minheight': 11, |
| 415 | \}) |
| 416 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 417 | let res = popup_getpos(winid) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 418 | call assert_equal(2, res.line) |
| 419 | call assert_equal(3, res.col) |
| 420 | call assert_equal(10, res.width) |
| 421 | call assert_equal(11, res.height) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 422 | call assert_equal(1, res.visible) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 423 | |
| 424 | call popup_close(winid) |
| 425 | endfunc |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 426 | |
| 427 | func Test_popup_width_longest() |
| 428 | let tests = [ |
| 429 | \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15], |
| 430 | \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15], |
| 431 | \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15], |
| 432 | \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15], |
| 433 | \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15], |
| 434 | \ ] |
| 435 | |
| 436 | for test in tests |
| 437 | let winid = popup_create(test[0], {'line': 2, 'col': 3}) |
| 438 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 439 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 440 | call assert_equal(test[1], position.width) |
| 441 | call popup_close(winid) |
| 442 | endfor |
| 443 | endfunc |
| 444 | |
| 445 | func Test_popup_wraps() |
| 446 | let tests = [ |
| 447 | \ ['nowrap', 6, 1], |
| 448 | \ ['a line that wraps once', 12, 2], |
| 449 | \ ['a line that wraps two times', 12, 3], |
| 450 | \ ] |
| 451 | for test in tests |
| 452 | let winid = popup_create(test[0], |
| 453 | \ {'line': 2, 'col': 3, 'maxwidth': 12}) |
| 454 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 455 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 456 | call assert_equal(test[1], position.width) |
| 457 | call assert_equal(test[2], position.height) |
| 458 | |
| 459 | call popup_close(winid) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 460 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 461 | endfor |
| 462 | endfunc |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 463 | |
| 464 | func Test_popup_getoptions() |
| 465 | let winid = popup_create('hello', { |
| 466 | \ 'line': 2, |
| 467 | \ 'col': 3, |
| 468 | \ 'minwidth': 10, |
| 469 | \ 'minheight': 11, |
| 470 | \ 'maxwidth': 20, |
| 471 | \ 'maxheight': 21, |
| 472 | \ 'zindex': 100, |
| 473 | \ 'time': 5000, |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 474 | \ 'fixed': 1 |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 475 | \}) |
| 476 | redraw |
| 477 | let res = popup_getoptions(winid) |
| 478 | call assert_equal(2, res.line) |
| 479 | call assert_equal(3, res.col) |
| 480 | call assert_equal(10, res.minwidth) |
| 481 | call assert_equal(11, res.minheight) |
| 482 | call assert_equal(20, res.maxwidth) |
| 483 | call assert_equal(21, res.maxheight) |
| 484 | call assert_equal(100, res.zindex) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 485 | call assert_equal(1, res.fixed) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 486 | if has('timers') |
| 487 | call assert_equal(5000, res.time) |
| 488 | endif |
| 489 | call popup_close(winid) |
| 490 | |
| 491 | let winid = popup_create('hello', {}) |
| 492 | redraw |
| 493 | let res = popup_getoptions(winid) |
| 494 | call assert_equal(0, res.line) |
| 495 | call assert_equal(0, res.col) |
| 496 | call assert_equal(0, res.minwidth) |
| 497 | call assert_equal(0, res.minheight) |
| 498 | call assert_equal(0, res.maxwidth) |
| 499 | call assert_equal(0, res.maxheight) |
| 500 | call assert_equal(50, res.zindex) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 501 | call assert_equal(0, res.fixed) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 502 | if has('timers') |
| 503 | call assert_equal(0, res.time) |
| 504 | endif |
| 505 | call popup_close(winid) |
| 506 | call assert_equal({}, popup_getoptions(winid)) |
| 507 | endfunc |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 508 | |
| 509 | func Test_popup_option_values() |
| 510 | new |
| 511 | " window-local |
| 512 | setlocal number |
| 513 | setlocal nowrap |
| 514 | " buffer-local |
| 515 | setlocal omnifunc=Something |
| 516 | " global/buffer-local |
| 517 | setlocal path=/there |
| 518 | " global/window-local |
| 519 | setlocal scrolloff=9 |
| 520 | |
| 521 | let winid = popup_create('hello', {}) |
| 522 | call assert_equal(0, getwinvar(winid, '&number')) |
| 523 | call assert_equal(1, getwinvar(winid, '&wrap')) |
| 524 | call assert_equal('', getwinvar(winid, '&omnifunc')) |
| 525 | call assert_equal(&g:path, getwinvar(winid, '&path')) |
| 526 | call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff')) |
| 527 | |
| 528 | call popup_close(winid) |
| 529 | bwipe |
| 530 | endfunc |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 531 | |
| 532 | func Test_popup_atcursor() |
| 533 | topleft vnew |
| 534 | call setline(1, [ |
| 535 | \ 'xxxxxxxxxxxxxxxxx', |
| 536 | \ 'xxxxxxxxxxxxxxxxx', |
| 537 | \ 'xxxxxxxxxxxxxxxxx', |
| 538 | \]) |
| 539 | |
| 540 | call cursor(2, 2) |
| 541 | redraw |
| 542 | let winid = popup_atcursor('vim', {}) |
| 543 | redraw |
| 544 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 545 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 546 | call popup_close(winid) |
| 547 | |
| 548 | call cursor(3, 4) |
| 549 | redraw |
| 550 | let winid = popup_atcursor('vim', {}) |
| 551 | redraw |
| 552 | let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '') |
| 553 | call assert_equal('xxxvimxxxxxxxxxxx', line) |
| 554 | call popup_close(winid) |
| 555 | |
| 556 | call cursor(1, 1) |
| 557 | redraw |
| 558 | let winid = popup_create('vim', { |
| 559 | \ 'line': 'cursor+2', |
| 560 | \ 'col': 'cursor+1', |
| 561 | \}) |
| 562 | redraw |
| 563 | let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '') |
| 564 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 565 | call popup_close(winid) |
| 566 | |
| 567 | call cursor(3, 3) |
| 568 | redraw |
| 569 | let winid = popup_create('vim', { |
| 570 | \ 'line': 'cursor-2', |
| 571 | \ 'col': 'cursor-1', |
| 572 | \}) |
| 573 | redraw |
| 574 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 575 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 576 | call popup_close(winid) |
| 577 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 578 | " just enough room above |
| 579 | call cursor(3, 3) |
| 580 | redraw |
| 581 | let winid = popup_atcursor(['vim', 'is great'], {}) |
| 582 | redraw |
| 583 | let pos = popup_getpos(winid) |
| 584 | call assert_equal(1, pos.line) |
| 585 | call popup_close(winid) |
| 586 | |
| 587 | " not enough room above, popup goes below the cursor |
| 588 | call cursor(3, 3) |
| 589 | redraw |
| 590 | let winid = popup_atcursor(['vim', 'is', 'great'], {}) |
| 591 | redraw |
| 592 | let pos = popup_getpos(winid) |
| 593 | call assert_equal(4, pos.line) |
| 594 | call popup_close(winid) |
| 595 | |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 596 | bwipe! |
| 597 | endfunc |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 598 | |
| 599 | func Test_popup_filter() |
| 600 | new |
| 601 | call setline(1, 'some text') |
| 602 | |
| 603 | func MyPopupFilter(winid, c) |
| 604 | if a:c == 'e' |
| 605 | let g:eaten = 'e' |
| 606 | return 1 |
| 607 | endif |
| 608 | if a:c == '0' |
| 609 | let g:ignored = '0' |
| 610 | return 0 |
| 611 | endif |
| 612 | if a:c == 'x' |
| 613 | call popup_close(a:winid) |
| 614 | return 1 |
| 615 | endif |
| 616 | return 0 |
| 617 | endfunc |
| 618 | |
| 619 | let winid = popup_create('something', {'filter': 'MyPopupFilter'}) |
| 620 | redraw |
| 621 | |
| 622 | " e is consumed by the filter |
| 623 | call feedkeys('e', 'xt') |
| 624 | call assert_equal('e', g:eaten) |
| 625 | |
| 626 | " 0 is ignored by the filter |
| 627 | normal $ |
| 628 | call assert_equal(9, getcurpos()[2]) |
| 629 | call feedkeys('0', 'xt') |
| 630 | call assert_equal('0', g:ignored) |
| 631 | call assert_equal(1, getcurpos()[2]) |
| 632 | |
| 633 | " x closes the popup |
| 634 | call feedkeys('x', 'xt') |
| 635 | call assert_equal('e', g:eaten) |
| 636 | call assert_equal(-1, winbufnr(winid)) |
| 637 | |
| 638 | delfunc MyPopupFilter |
| 639 | popupclear |
| 640 | endfunc |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 641 | |
| 642 | func Test_popup_close_callback() |
| 643 | func PopupDone(id, result) |
| 644 | let g:result = a:result |
| 645 | endfunc |
| 646 | let winid = popup_create('something', {'callback': 'PopupDone'}) |
| 647 | redraw |
| 648 | call popup_close(winid, 'done') |
| 649 | call assert_equal('done', g:result) |
| 650 | endfunc |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 651 | |
| 652 | func Test_popup_empty() |
| 653 | let winid = popup_create('', {'padding': [2,2,2,2]}) |
| 654 | redraw |
| 655 | let pos = popup_getpos(winid) |
| 656 | call assert_equal(4, pos.width) |
| 657 | call assert_equal(5, pos.height) |
| 658 | |
| 659 | let winid = popup_create([], {'border': []}) |
| 660 | redraw |
| 661 | let pos = popup_getpos(winid) |
| 662 | call assert_equal(2, pos.width) |
| 663 | call assert_equal(3, pos.height) |
| 664 | endfunc |
Bram Moolenaar | 988c433 | 2019-06-02 14:12:11 +0200 | [diff] [blame] | 665 | |
| 666 | func Test_popup_never_behind() |
| 667 | if !CanRunVimInTerminal() |
| 668 | return |
| 669 | endif |
| 670 | " +-----------------------------+ |
| 671 | " | | | |
| 672 | " | | | |
| 673 | " | | | |
| 674 | " | line1 | |
| 675 | " |------------line2------------| |
| 676 | " | line3 | |
| 677 | " | line4 | |
| 678 | " | | |
| 679 | " | | |
| 680 | " +-----------------------------+ |
| 681 | let lines =<< trim END |
| 682 | only |
| 683 | split |
| 684 | vsplit |
| 685 | let info_window1 = getwininfo()[0] |
| 686 | let line = info_window1['height'] |
| 687 | let col = info_window1['width'] |
| 688 | call popup_create(['line1', 'line2', 'line3', 'line4'], { |
| 689 | \ 'line' : line, |
| 690 | \ 'col' : col, |
| 691 | \ }) |
| 692 | END |
| 693 | call writefile(lines, 'XtestPopupBehind') |
| 694 | let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10}) |
| 695 | call term_sendkeys(buf, "\<C-W>w") |
| 696 | call VerifyScreenDump(buf, 'Test_popupwin_behind', {}) |
| 697 | |
| 698 | " clean up |
| 699 | call StopVimInTerminal(buf) |
| 700 | call delete('XtestPopupBehind') |
| 701 | endfunc |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 702 | |
| 703 | func s:VerifyPosition( p, msg, line, col, width, height ) |
| 704 | call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' ) |
| 705 | call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' ) |
| 706 | call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' ) |
| 707 | call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' ) |
| 708 | endfunc |
| 709 | |
| 710 | func Test_popup_position_adjust() |
| 711 | " Anything placed past 2 cells from of the right of the screen is moved to the |
| 712 | " left. |
| 713 | " |
| 714 | " When wrapping is disabled, we also shift to the left to display on the |
| 715 | " screen, unless fixed is set. |
| 716 | |
| 717 | " Entries for cases which don't vary based on wrapping. |
| 718 | " Format is per tests described below |
| 719 | let both_wrap_tests = [ |
| 720 | \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ], |
| 721 | \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ], |
| 722 | \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ], |
| 723 | \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ], |
| 724 | \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ], |
| 725 | \ |
| 726 | \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ], |
| 727 | \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ], |
| 728 | \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ], |
| 729 | \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ], |
| 730 | \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ], |
| 731 | \ |
| 732 | \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ], |
| 733 | \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ], |
| 734 | \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ], |
| 735 | \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ], |
| 736 | \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ], |
| 737 | \ ] |
| 738 | |
| 739 | " these test groups are dicts with: |
| 740 | " - comment: something to identify the group of tests by |
| 741 | " - options: dict of options to merge with the row/col in tests |
| 742 | " - tests: list of cases. Each one is a list with elements: |
| 743 | " - text |
| 744 | " - row |
| 745 | " - col |
| 746 | " - expected row |
| 747 | " - expected col |
| 748 | " - expected width |
| 749 | " - expected height |
| 750 | let tests = [ |
| 751 | \ { |
| 752 | \ 'comment': 'left-aligned with wrapping', |
| 753 | \ 'options': { |
| 754 | \ 'wrap': 1, |
| 755 | \ 'pos': 'botleft', |
| 756 | \ }, |
| 757 | \ 'tests': both_wrap_tests + [ |
| 758 | \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ], |
| 759 | \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ], |
| 760 | \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ], |
| 761 | \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ], |
| 762 | \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], |
| 763 | \ ], |
| 764 | \ }, |
| 765 | \ { |
| 766 | \ 'comment': 'left aligned without wrapping', |
| 767 | \ 'options': { |
| 768 | \ 'wrap': 0, |
| 769 | \ 'pos': 'botleft', |
| 770 | \ }, |
| 771 | \ 'tests': both_wrap_tests + [ |
| 772 | \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ], |
| 773 | \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ], |
| 774 | \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ], |
| 775 | \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ], |
| 776 | \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], |
| 777 | \ ], |
| 778 | \ }, |
| 779 | \ { |
| 780 | \ 'comment': 'left aligned with fixed position', |
| 781 | \ 'options': { |
| 782 | \ 'wrap': 0, |
| 783 | \ 'fixed': 1, |
| 784 | \ 'pos': 'botleft', |
| 785 | \ }, |
| 786 | \ 'tests': both_wrap_tests + [ |
| 787 | \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ], |
| 788 | \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ], |
| 789 | \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ], |
| 790 | \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ], |
| 791 | \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], |
| 792 | \ ], |
| 793 | \ }, |
| 794 | \ ] |
| 795 | |
| 796 | for test_group in tests |
| 797 | for test in test_group.tests |
| 798 | let [ text, line, col, e_line, e_col, e_width, e_height ] = test |
| 799 | let options = { |
| 800 | \ 'line': line, |
| 801 | \ 'col': col, |
| 802 | \ } |
| 803 | call extend( options, test_group.options ) |
| 804 | |
| 805 | let p = popup_create( text, options ) |
| 806 | |
| 807 | let msg = string( extend( options, { 'text': text } ) ) |
| 808 | call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height ) |
| 809 | call popup_close( p ) |
| 810 | endfor |
| 811 | endfor |
| 812 | |
| 813 | popupclear |
| 814 | %bwipe! |
| 815 | endfunc |
| 816 | |
| 817 | function Test_adjust_left_past_screen_width() |
| 818 | " width of screen |
| 819 | let X = join(map(range(&columns), {->'X'}), '') |
| 820 | |
| 821 | let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } ) |
| 822 | call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 ) |
| 823 | |
| 824 | redraw |
| 825 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 826 | call assert_equal(X, line) |
| 827 | |
| 828 | call popup_close( p ) |
| 829 | redraw |
| 830 | |
| 831 | " Same if placed on the right hand side |
| 832 | let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } ) |
| 833 | call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 ) |
| 834 | |
| 835 | redraw |
| 836 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 837 | call assert_equal(X, line) |
| 838 | |
| 839 | call popup_close( p ) |
| 840 | redraw |
| 841 | |
| 842 | " Extend so > window width |
| 843 | let X .= 'x' |
| 844 | |
| 845 | let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } ) |
| 846 | call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 ) |
| 847 | |
| 848 | redraw |
| 849 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 850 | call assert_equal(X[ : -2 ], line) |
| 851 | |
| 852 | call popup_close( p ) |
| 853 | redraw |
| 854 | |
| 855 | " Shifted then truncated (the x is not visible) |
| 856 | let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } ) |
| 857 | call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 ) |
| 858 | |
| 859 | redraw |
| 860 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 861 | call assert_equal(X[ : -2 ], line) |
| 862 | |
| 863 | call popup_close( p ) |
| 864 | redraw |
| 865 | |
| 866 | " Not shifted, just truncated |
| 867 | let p = popup_create( X, |
| 868 | \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } ) |
| 869 | call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1) |
| 870 | |
| 871 | redraw |
| 872 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 873 | let e_line = ' ' . X[ 1 : -2 ] |
| 874 | call assert_equal(e_line, line) |
| 875 | |
| 876 | call popup_close( p ) |
| 877 | redraw |
| 878 | |
| 879 | popupclear |
| 880 | %bwipe! |
| 881 | endfunction |