Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1 | " Tests for popup windows |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature textprop |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 5 | |
| 6 | source screendump.vim |
| 7 | |
| 8 | func Test_simple_popup() |
| 9 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 10 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 11 | endif |
| 12 | call writefile([ |
| 13 | \ "call setline(1, range(1, 100))", |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 14 | \ "hi PopupColor1 ctermbg=lightblue", |
| 15 | \ "hi PopupColor2 ctermbg=lightcyan", |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 16 | \ "hi Comment ctermfg=red", |
| 17 | \ "call prop_type_add('comment', {'highlight': 'Comment'})", |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 18 | \ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})", |
| 19 | \ "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] | 20 | \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')", |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 21 | \], 'XtestPopup') |
| 22 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 23 | call VerifyScreenDump(buf, 'Test_popupwin_01', {}) |
| 24 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 25 | " Add a tabpage |
| 26 | call term_sendkeys(buf, ":tabnew\<CR>") |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 27 | call term_sendkeys(buf, ":let popupwin = popup_create([" |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 28 | \ .. "{'text': 'other tab'}," |
| 29 | \ .. "{'text': 'a comment line', 'props': [{" |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 30 | \ .. "'col': 3, 'length': 7, 'minwidth': 20, 'type': 'comment'" |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 31 | \ .. "}]}," |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 32 | \ .. "], {'line': 4, 'col': 9, 'minwidth': 20})\<CR>") |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 33 | call VerifyScreenDump(buf, 'Test_popupwin_02', {}) |
| 34 | |
| 35 | " switch back to first tabpage |
| 36 | call term_sendkeys(buf, "gt") |
| 37 | call VerifyScreenDump(buf, 'Test_popupwin_03', {}) |
| 38 | |
| 39 | " close that tabpage |
| 40 | call term_sendkeys(buf, ":quit!\<CR>") |
| 41 | call VerifyScreenDump(buf, 'Test_popupwin_04', {}) |
| 42 | |
Bram Moolenaar | 202d982 | 2019-06-11 21:56:30 +0200 | [diff] [blame] | 43 | " set 'columns' to a small value, size must be recomputed |
| 44 | call term_sendkeys(buf, ":let cols = &columns\<CR>") |
| 45 | call term_sendkeys(buf, ":set columns=12\<CR>") |
| 46 | call VerifyScreenDump(buf, 'Test_popupwin_04a', {}) |
| 47 | call term_sendkeys(buf, ":let &columns = cols\<CR>") |
| 48 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 49 | " resize popup, show empty line at bottom |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 50 | call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>") |
| 51 | call term_sendkeys(buf, ":redraw\<CR>") |
| 52 | call VerifyScreenDump(buf, 'Test_popupwin_05', {}) |
| 53 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 54 | " show not fitting line at bottom |
| 55 | call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>") |
| 56 | call term_sendkeys(buf, ":redraw\<CR>") |
| 57 | call VerifyScreenDump(buf, 'Test_popupwin_06', {}) |
| 58 | |
Bram Moolenaar | 24a5ac5 | 2019-06-08 19:01:18 +0200 | [diff] [blame] | 59 | " move popup over ruler |
| 60 | call term_sendkeys(buf, ":set cmdheight=2\<CR>") |
| 61 | call term_sendkeys(buf, ":call popup_move(popupwin, {'line': 7, 'col': 55})\<CR>") |
| 62 | call VerifyScreenDump(buf, 'Test_popupwin_07', {}) |
| 63 | |
| 64 | " clear all popups after moving the cursor a bit, so that ruler is updated |
| 65 | call term_sendkeys(buf, "axxx\<Esc>") |
| 66 | call term_wait(buf) |
| 67 | call term_sendkeys(buf, "0") |
| 68 | call term_wait(buf) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 69 | call term_sendkeys(buf, ":call popup_clear()\<CR>") |
Bram Moolenaar | 24a5ac5 | 2019-06-08 19:01:18 +0200 | [diff] [blame] | 70 | call VerifyScreenDump(buf, 'Test_popupwin_08', {}) |
| 71 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 72 | " clean up |
| 73 | call StopVimInTerminal(buf) |
| 74 | call delete('XtestPopup') |
| 75 | endfunc |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 76 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 77 | func Test_popup_with_border_and_padding() |
| 78 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 79 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 80 | endif |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 81 | |
Bram Moolenaar | 3bfd04e | 2019-06-01 20:45:21 +0200 | [diff] [blame] | 82 | for iter in range(0, 1) |
| 83 | call writefile([iter == 1 ? '' : 'set enc=latin1', |
| 84 | \ "call setline(1, range(1, 100))", |
| 85 | \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})", |
| 86 | \ "call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})", |
| 87 | \ "call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})", |
| 88 | \ "call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})", |
| 89 | \ "call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})", |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 90 | \ "call popup_create('wrapped longer text', {'line': 8, 'col': 55, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})", |
| 91 | \ "call popup_create('right aligned text', {'line': 11, 'col': 56, 'wrap': 0, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})", |
Bram Moolenaar | 3bfd04e | 2019-06-01 20:45:21 +0200 | [diff] [blame] | 92 | \], 'XtestPopupBorder') |
| 93 | let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15}) |
| 94 | call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {}) |
| 95 | |
| 96 | call StopVimInTerminal(buf) |
| 97 | call delete('XtestPopupBorder') |
| 98 | endfor |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 99 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 100 | call writefile([ |
| 101 | \ "call setline(1, range(1, 100))", |
| 102 | \ "hi BlueColor ctermbg=lightblue", |
| 103 | \ "hi TopColor ctermbg=253", |
| 104 | \ "hi RightColor ctermbg=245", |
| 105 | \ "hi BottomColor ctermbg=240", |
| 106 | \ "hi LeftColor ctermbg=248", |
| 107 | \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor']})", |
| 108 | \ "call popup_create(['hello border', 'and more'], {'line': 2, 'col': 23, 'border': [], 'borderhighlight': ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})", |
| 109 | \ "call popup_create(['hello border', 'lines only'], {'line': 2, 'col': 43, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x']})", |
| 110 | \ "call popup_create(['hello border', 'with corners'], {'line': 2, 'col': 60, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x', '#']})", |
| 111 | \ "call popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})", |
| 112 | \ "call popup_create(['hello border', 'just blanks'], {'line': 7, 'col': 23, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': [' ']})", |
| 113 | \], 'XtestPopupBorder') |
| 114 | let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 12}) |
| 115 | call VerifyScreenDump(buf, 'Test_popupwin_22', {}) |
| 116 | |
| 117 | call StopVimInTerminal(buf) |
| 118 | call delete('XtestPopupBorder') |
| 119 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 120 | let with_border_or_padding = { |
| 121 | \ 'line': 2, |
| 122 | \ 'core_line': 3, |
| 123 | \ 'col': 3, |
| 124 | \ 'core_col': 4, |
| 125 | \ 'width': 14, |
| 126 | \ 'core_width': 12, |
| 127 | \ 'height': 3, |
| 128 | \ 'core_height': 1, |
| 129 | \ 'visible': 1} |
| 130 | let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})", |
| 131 | call assert_equal(with_border_or_padding, popup_getpos(winid)) |
| 132 | |
| 133 | let winid = popup_create('hello paddng', {'line': 2, 'col': 3, 'padding': []}) |
| 134 | call assert_equal(with_border_or_padding, popup_getpos(winid)) |
| 135 | |
| 136 | let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []}) |
| 137 | call assert_equal({ |
| 138 | \ 'line': 3, |
| 139 | \ 'core_line': 5, |
| 140 | \ 'col': 8, |
| 141 | \ 'core_col': 10, |
| 142 | \ 'width': 14, |
| 143 | \ 'core_width': 10, |
| 144 | \ 'height': 5, |
| 145 | \ 'core_height': 1, |
| 146 | \ 'visible': 1}, popup_getpos(winid)) |
| 147 | endfunc |
| 148 | |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 149 | func Test_popup_with_syntax_win_execute() |
| 150 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 151 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 152 | endif |
| 153 | call writefile([ |
| 154 | \ "call setline(1, range(1, 100))", |
| 155 | \ "hi PopupColor ctermbg=lightblue", |
| 156 | \ "let winid = popup_create([", |
| 157 | \ "\\ '#include <stdio.h>',", |
| 158 | \ "\\ 'int main(void)',", |
| 159 | \ "\\ '{',", |
| 160 | \ "\\ ' printf(123);',", |
| 161 | \ "\\ '}',", |
| 162 | \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})", |
| 163 | \ "call win_execute(winid, 'set syntax=cpp')", |
| 164 | \], 'XtestPopup') |
| 165 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 166 | call VerifyScreenDump(buf, 'Test_popupwin_10', {}) |
| 167 | |
| 168 | " clean up |
| 169 | call StopVimInTerminal(buf) |
| 170 | call delete('XtestPopup') |
| 171 | endfunc |
| 172 | |
| 173 | func Test_popup_with_syntax_setbufvar() |
| 174 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 175 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 176 | endif |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 177 | let lines =<< trim END |
| 178 | call setline(1, range(1, 100)) |
| 179 | hi PopupColor ctermbg=lightgrey |
| 180 | let winid = popup_create([ |
| 181 | \ '#include <stdio.h>', |
| 182 | \ 'int main(void)', |
| 183 | \ '{', |
| 184 | \ ' printf(567);', |
| 185 | \ '}', |
| 186 | \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'}) |
| 187 | call setbufvar(winbufnr(winid), '&syntax', 'cpp') |
| 188 | END |
| 189 | call writefile(lines, 'XtestPopup') |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 190 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 191 | call VerifyScreenDump(buf, 'Test_popupwin_11', {}) |
| 192 | |
| 193 | " clean up |
| 194 | call StopVimInTerminal(buf) |
| 195 | call delete('XtestPopup') |
| 196 | endfunc |
| 197 | |
Bram Moolenaar | ac2450a | 2019-06-09 18:04:28 +0200 | [diff] [blame] | 198 | func Test_popup_with_matches() |
| 199 | if !CanRunVimInTerminal() |
| 200 | throw 'Skipped: cannot make screendumps' |
| 201 | endif |
| 202 | let lines =<< trim END |
| 203 | call setline(1, ['111 222 333', '444 555 666']) |
| 204 | let winid = popup_create([ |
| 205 | \ '111 222 333', |
| 206 | \ '444 555 666', |
| 207 | \], {'line': 3, 'col': 10, 'border': []}) |
| 208 | set hlsearch |
| 209 | /666 |
| 210 | call matchadd('ErrorMsg', '111') |
| 211 | call matchadd('ErrorMsg', '444') |
| 212 | call win_execute(winid, "call matchadd('ErrorMsg', '111')") |
| 213 | call win_execute(winid, "call matchadd('ErrorMsg', '555')") |
| 214 | END |
| 215 | call writefile(lines, 'XtestPopupMatches') |
| 216 | let buf = RunVimInTerminal('-S XtestPopupMatches', {'rows': 10}) |
| 217 | call VerifyScreenDump(buf, 'Test_popupwin_matches', {}) |
| 218 | |
| 219 | " clean up |
| 220 | call StopVimInTerminal(buf) |
| 221 | call delete('XtestPopupMatches') |
| 222 | endfunc |
| 223 | |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 224 | func Test_popup_all_corners() |
| 225 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 226 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 227 | endif |
| 228 | let lines =<< trim END |
| 229 | call setline(1, repeat([repeat('-', 60)], 15)) |
| 230 | set so=0 |
| 231 | normal 2G3|r# |
| 232 | let winid1 = popup_create(['first', 'second'], { |
| 233 | \ 'line': 'cursor+1', |
| 234 | \ 'col': 'cursor', |
| 235 | \ 'pos': 'topleft', |
| 236 | \ 'border': [], |
| 237 | \ 'padding': [], |
| 238 | \ }) |
| 239 | normal 25|r@ |
| 240 | let winid1 = popup_create(['First', 'SeconD'], { |
| 241 | \ 'line': 'cursor+1', |
| 242 | \ 'col': 'cursor', |
| 243 | \ 'pos': 'topright', |
| 244 | \ 'border': [], |
| 245 | \ 'padding': [], |
| 246 | \ }) |
| 247 | normal 9G29|r% |
| 248 | let winid1 = popup_create(['fiRSt', 'seCOnd'], { |
| 249 | \ 'line': 'cursor-1', |
| 250 | \ 'col': 'cursor', |
| 251 | \ 'pos': 'botleft', |
| 252 | \ 'border': [], |
| 253 | \ 'padding': [], |
| 254 | \ }) |
| 255 | normal 51|r& |
| 256 | let winid1 = popup_create(['FIrsT', 'SEcoND'], { |
| 257 | \ 'line': 'cursor-1', |
| 258 | \ 'col': 'cursor', |
| 259 | \ 'pos': 'botright', |
| 260 | \ 'border': [], |
| 261 | \ 'padding': [], |
| 262 | \ }) |
| 263 | END |
| 264 | call writefile(lines, 'XtestPopupCorners') |
| 265 | let buf = RunVimInTerminal('-S XtestPopupCorners', {'rows': 12}) |
| 266 | call VerifyScreenDump(buf, 'Test_popupwin_corners', {}) |
| 267 | |
| 268 | " clean up |
| 269 | call StopVimInTerminal(buf) |
| 270 | call delete('XtestPopupCorners') |
| 271 | endfunc |
| 272 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 273 | func Test_popup_firstline() |
| 274 | if !CanRunVimInTerminal() |
| 275 | throw 'Skipped: cannot make screendumps' |
| 276 | endif |
| 277 | let lines =<< trim END |
| 278 | call setline(1, range(1, 20)) |
| 279 | call popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], { |
| 280 | \ 'maxheight': 4, |
| 281 | \ 'firstline': 3, |
| 282 | \ }) |
| 283 | END |
| 284 | call writefile(lines, 'XtestPopupFirstline') |
| 285 | let buf = RunVimInTerminal('-S XtestPopupFirstline', {'rows': 10}) |
| 286 | call VerifyScreenDump(buf, 'Test_popupwin_firstline', {}) |
| 287 | |
| 288 | " clean up |
| 289 | call StopVimInTerminal(buf) |
| 290 | call delete('XtestPopupFirstline') |
| 291 | endfunc |
| 292 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 293 | func Test_popup_drag() |
| 294 | if !CanRunVimInTerminal() |
| 295 | throw 'Skipped: cannot make screendumps' |
| 296 | endif |
| 297 | " create a popup that covers the command line |
| 298 | let lines =<< trim END |
| 299 | call setline(1, range(1, 20)) |
| 300 | let winid = popup_create(['1111', '222222', '33333'], { |
| 301 | \ 'drag': 1, |
| 302 | \ 'border': [], |
| 303 | \ 'line': &lines - 4, |
| 304 | \ }) |
| 305 | func Dragit() |
| 306 | call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt") |
| 307 | endfunc |
| 308 | map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR> |
| 309 | map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2)<CR> |
| 310 | END |
| 311 | call writefile(lines, 'XtestPopupDrag') |
| 312 | let buf = RunVimInTerminal('-S XtestPopupDrag', {'rows': 10}) |
| 313 | call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {}) |
| 314 | |
| 315 | call term_sendkeys(buf, ":call Dragit()\<CR>") |
| 316 | call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {}) |
| 317 | |
| 318 | " clean up |
| 319 | call StopVimInTerminal(buf) |
| 320 | call delete('XtestPopupDrag') |
| 321 | endfunc |
| 322 | |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 323 | func Test_popup_select() |
| 324 | if !CanRunVimInTerminal() |
| 325 | throw 'Skipped: cannot make screendumps' |
| 326 | endif |
Bram Moolenaar | 650a637 | 2019-06-15 00:29:33 +0200 | [diff] [blame] | 327 | if !has('clipboard') |
| 328 | throw 'Skipped: clipboard feature missing' |
| 329 | endif |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 330 | " create a popup with some text to be selected |
| 331 | let lines =<< trim END |
Bram Moolenaar | 1755ec4 | 2019-06-15 13:13:54 +0200 | [diff] [blame] | 332 | set clipboard=autoselect |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 333 | call setline(1, range(1, 20)) |
| 334 | let winid = popup_create(['the word', 'some more', 'several words here'], { |
| 335 | \ 'drag': 1, |
| 336 | \ 'border': [], |
| 337 | \ 'line': 3, |
| 338 | \ 'col': 10, |
| 339 | \ }) |
| 340 | func Select1() |
| 341 | call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt") |
| 342 | endfunc |
| 343 | map <silent> <F3> :call test_setmouse(4, 15)<CR> |
| 344 | map <silent> <F4> :call test_setmouse(6, 23)<CR> |
| 345 | END |
| 346 | call writefile(lines, 'XtestPopupSelect') |
| 347 | let buf = RunVimInTerminal('-S XtestPopupSelect', {'rows': 10}) |
| 348 | call term_sendkeys(buf, ":call Select1()\<CR>") |
| 349 | call VerifyScreenDump(buf, 'Test_popupwin_select_01', {}) |
| 350 | |
| 351 | call term_sendkeys(buf, ":call popup_close(winid)\<CR>") |
| 352 | call term_sendkeys(buf, "\"*p") |
| 353 | call VerifyScreenDump(buf, 'Test_popupwin_select_02', {}) |
| 354 | |
| 355 | " clean up |
| 356 | call StopVimInTerminal(buf) |
| 357 | call delete('XtestPopupSelect') |
| 358 | endfunc |
| 359 | |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 360 | func Test_popup_in_tab() |
| 361 | " default popup is local to tab, not visible when in other tab |
| 362 | let winid = popup_create("text", {}) |
Bram Moolenaar | 7c7f01e | 2019-06-12 21:06:32 +0200 | [diff] [blame] | 363 | let bufnr = winbufnr(winid) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 364 | call assert_equal(1, popup_getpos(winid).visible) |
| 365 | tabnew |
| 366 | call assert_equal(0, popup_getpos(winid).visible) |
| 367 | quit |
| 368 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 7c7f01e | 2019-06-12 21:06:32 +0200 | [diff] [blame] | 369 | |
| 370 | call assert_equal(1, bufexists(bufnr)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 371 | call popup_clear() |
Bram Moolenaar | 7c7f01e | 2019-06-12 21:06:32 +0200 | [diff] [blame] | 372 | " buffer is gone now |
| 373 | call assert_equal(0, bufexists(bufnr)) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 374 | |
| 375 | " global popup is visible in any tab |
Bram Moolenaar | fc06cbb | 2019-06-15 14:14:31 +0200 | [diff] [blame] | 376 | let winid = popup_create("text", {'tabpage': -1}) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 377 | call assert_equal(1, popup_getpos(winid).visible) |
| 378 | tabnew |
| 379 | call assert_equal(1, popup_getpos(winid).visible) |
| 380 | quit |
| 381 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 382 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 383 | endfunc |
| 384 | |
| 385 | func Test_popup_valid_arguments() |
| 386 | " Zero value is like the property wasn't there |
| 387 | let winid = popup_create("text", {"col": 0}) |
| 388 | let pos = popup_getpos(winid) |
| 389 | call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 390 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 391 | |
| 392 | " using cursor column has minimum value of 1 |
| 393 | let winid = popup_create("text", {"col": 'cursor-100'}) |
| 394 | let pos = popup_getpos(winid) |
| 395 | call assert_equal(1, pos.col) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 396 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 397 | |
| 398 | " center |
| 399 | let winid = popup_create("text", {"pos": 'center'}) |
| 400 | let pos = popup_getpos(winid) |
| 401 | let around = (&columns - pos.width) / 2 |
| 402 | call assert_inrange(around - 1, around + 1, pos.col) |
| 403 | let around = (&lines - pos.height) / 2 |
| 404 | call assert_inrange(around - 1, around + 1, pos.line) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 405 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 406 | endfunc |
| 407 | |
| 408 | func Test_popup_invalid_arguments() |
| 409 | call assert_fails('call popup_create(666, {})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 410 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 411 | call assert_fails('call popup_create("text", "none")', 'E715:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 412 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 413 | |
| 414 | call assert_fails('call popup_create("text", {"col": "xxx"})', 'E475:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 415 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 416 | call assert_fails('call popup_create("text", {"col": "cursor8"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 417 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 418 | call assert_fails('call popup_create("text", {"col": "cursor+x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 419 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 420 | call assert_fails('call popup_create("text", {"col": "cursor+8x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 421 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 422 | |
| 423 | call assert_fails('call popup_create("text", {"line": "xxx"})', 'E475:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 424 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 425 | call assert_fails('call popup_create("text", {"line": "cursor8"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 426 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 427 | call assert_fails('call popup_create("text", {"line": "cursor+x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 428 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 429 | call assert_fails('call popup_create("text", {"line": "cursor+8x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 430 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 431 | |
| 432 | call assert_fails('call popup_create("text", {"pos": "there"})', 'E475:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 433 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 434 | call assert_fails('call popup_create("text", {"padding": "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 435 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 436 | call assert_fails('call popup_create("text", {"border": "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 437 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 438 | call assert_fails('call popup_create("text", {"borderhighlight": "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 439 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 440 | call assert_fails('call popup_create("text", {"borderchars": "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 441 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 442 | |
| 443 | call assert_fails('call popup_create([{"text": "text"}, 666], {})', 'E715:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 444 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 445 | call assert_fails('call popup_create([{"text": "text", "props": "none"}], {})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 446 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 447 | call assert_fails('call popup_create([{"text": "text", "props": ["none"]}], {})', 'E715:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 448 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 449 | endfunc |
| 450 | |
Bram Moolenaar | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 451 | func Test_win_execute_closing_curwin() |
| 452 | split |
| 453 | let winid = popup_create('some text', {}) |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 454 | call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 455 | call popup_clear() |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 456 | endfunc |
| 457 | |
| 458 | func Test_win_execute_not_allowed() |
| 459 | let winid = popup_create('some text', {}) |
| 460 | call assert_fails('call win_execute(winid, "split")', 'E994:') |
| 461 | call assert_fails('call win_execute(winid, "vsplit")', 'E994:') |
| 462 | call assert_fails('call win_execute(winid, "close")', 'E994:') |
| 463 | call assert_fails('call win_execute(winid, "bdelete")', 'E994:') |
Bram Moolenaar | 2d24784 | 2019-06-01 17:06:25 +0200 | [diff] [blame] | 464 | call assert_fails('call win_execute(winid, "bwipe!")', 'E994:') |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 465 | call assert_fails('call win_execute(winid, "tabnew")', 'E994:') |
| 466 | call assert_fails('call win_execute(winid, "tabnext")', 'E994:') |
| 467 | call assert_fails('call win_execute(winid, "next")', 'E994:') |
| 468 | call assert_fails('call win_execute(winid, "rewind")', 'E994:') |
| 469 | call assert_fails('call win_execute(winid, "buf")', 'E994:') |
| 470 | call assert_fails('call win_execute(winid, "edit")', 'E994:') |
| 471 | call assert_fails('call win_execute(winid, "enew")', 'E994:') |
| 472 | call assert_fails('call win_execute(winid, "wincmd x")', 'E994:') |
| 473 | call assert_fails('call win_execute(winid, "wincmd w")', 'E994:') |
| 474 | call assert_fails('call win_execute(winid, "wincmd t")', 'E994:') |
| 475 | call assert_fails('call win_execute(winid, "wincmd b")', 'E994:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 476 | call popup_clear() |
Bram Moolenaar | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 477 | endfunc |
| 478 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 479 | func Test_popup_with_wrap() |
| 480 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 481 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 482 | endif |
| 483 | let lines =<< trim END |
| 484 | call setline(1, range(1, 100)) |
| 485 | let winid = popup_create( |
| 486 | \ 'a long line that wont fit', |
| 487 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1}) |
| 488 | END |
| 489 | call writefile(lines, 'XtestPopup') |
| 490 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 491 | call VerifyScreenDump(buf, 'Test_popupwin_wrap', {}) |
| 492 | |
| 493 | " clean up |
| 494 | call StopVimInTerminal(buf) |
| 495 | call delete('XtestPopup') |
| 496 | endfunc |
| 497 | |
| 498 | func Test_popup_without_wrap() |
| 499 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 500 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 501 | endif |
| 502 | let lines =<< trim END |
| 503 | call setline(1, range(1, 100)) |
| 504 | let winid = popup_create( |
| 505 | \ 'a long line that wont fit', |
| 506 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0}) |
| 507 | END |
| 508 | call writefile(lines, 'XtestPopup') |
| 509 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 510 | call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {}) |
| 511 | |
| 512 | " clean up |
| 513 | call StopVimInTerminal(buf) |
| 514 | call delete('XtestPopup') |
| 515 | endfunc |
| 516 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 517 | func Test_popup_time() |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 518 | if !has('timers') |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 519 | throw 'Skipped: timer feature not supported' |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 520 | endif |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 521 | topleft vnew |
| 522 | call setline(1, 'hello') |
| 523 | |
| 524 | call popup_create('world', { |
| 525 | \ 'line': 1, |
| 526 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 527 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 528 | \ 'time': 500, |
| 529 | \}) |
| 530 | redraw |
| 531 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 532 | call assert_equal('world', line) |
| 533 | |
| 534 | sleep 700m |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 535 | redraw |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 536 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 537 | call assert_equal('hello', line) |
| 538 | |
| 539 | call popup_create('on the command line', { |
| 540 | \ 'line': &lines, |
| 541 | \ 'col': 10, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 542 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 543 | \ 'time': 500, |
| 544 | \}) |
| 545 | redraw |
| 546 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 547 | call assert_match('.*on the command line.*', line) |
| 548 | |
| 549 | sleep 700m |
| 550 | redraw |
| 551 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 552 | call assert_notmatch('.*on the command line.*', line) |
| 553 | |
| 554 | bwipe! |
| 555 | endfunc |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 556 | |
| 557 | func Test_popup_hide() |
| 558 | topleft vnew |
| 559 | call setline(1, 'hello') |
| 560 | |
| 561 | let winid = popup_create('world', { |
| 562 | \ 'line': 1, |
| 563 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 564 | \ 'minwidth': 20, |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 565 | \}) |
| 566 | redraw |
| 567 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 568 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 569 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 570 | " buffer is still listed and active |
| 571 | call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 572 | |
| 573 | call popup_hide(winid) |
| 574 | redraw |
| 575 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 576 | call assert_equal('hello', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 577 | call assert_equal(0, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 578 | " buffer is still listed but hidden |
| 579 | call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 580 | |
| 581 | call popup_show(winid) |
| 582 | redraw |
| 583 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 584 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 585 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 586 | |
| 587 | |
| 588 | call popup_close(winid) |
| 589 | redraw |
| 590 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 591 | call assert_equal('hello', line) |
| 592 | |
| 593 | " error is given for existing non-popup window |
| 594 | call assert_fails('call popup_hide(win_getid())', 'E993:') |
| 595 | |
| 596 | " no error non-existing window |
| 597 | call popup_hide(1234234) |
| 598 | call popup_show(41234234) |
| 599 | |
| 600 | bwipe! |
| 601 | endfunc |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 602 | |
| 603 | func Test_popup_move() |
| 604 | topleft vnew |
| 605 | call setline(1, 'hello') |
| 606 | |
| 607 | let winid = popup_create('world', { |
| 608 | \ 'line': 1, |
| 609 | \ 'col': 1, |
| 610 | \ 'minwidth': 20, |
| 611 | \}) |
| 612 | redraw |
| 613 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 614 | call assert_equal('world ', line) |
| 615 | |
| 616 | call popup_move(winid, {'line': 2, 'col': 2}) |
| 617 | redraw |
| 618 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 619 | call assert_equal('hello ', line) |
| 620 | let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '') |
| 621 | call assert_equal('~world', line) |
| 622 | |
| 623 | call popup_move(winid, {'line': 1}) |
| 624 | redraw |
| 625 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 626 | call assert_equal('hworld', line) |
| 627 | |
| 628 | call popup_close(winid) |
| 629 | |
| 630 | bwipe! |
| 631 | endfunc |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 632 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 633 | func Test_popup_getpos() |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 634 | let winid = popup_create('hello', { |
| 635 | \ 'line': 2, |
| 636 | \ 'col': 3, |
| 637 | \ 'minwidth': 10, |
| 638 | \ 'minheight': 11, |
| 639 | \}) |
| 640 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 641 | let res = popup_getpos(winid) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 642 | call assert_equal(2, res.line) |
| 643 | call assert_equal(3, res.col) |
| 644 | call assert_equal(10, res.width) |
| 645 | call assert_equal(11, res.height) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 646 | call assert_equal(1, res.visible) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 647 | |
| 648 | call popup_close(winid) |
| 649 | endfunc |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 650 | |
| 651 | func Test_popup_width_longest() |
| 652 | let tests = [ |
| 653 | \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15], |
| 654 | \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15], |
| 655 | \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15], |
| 656 | \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15], |
| 657 | \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15], |
| 658 | \ ] |
| 659 | |
| 660 | for test in tests |
| 661 | let winid = popup_create(test[0], {'line': 2, 'col': 3}) |
| 662 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 663 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 664 | call assert_equal(test[1], position.width) |
| 665 | call popup_close(winid) |
| 666 | endfor |
| 667 | endfunc |
| 668 | |
| 669 | func Test_popup_wraps() |
| 670 | let tests = [ |
| 671 | \ ['nowrap', 6, 1], |
| 672 | \ ['a line that wraps once', 12, 2], |
| 673 | \ ['a line that wraps two times', 12, 3], |
| 674 | \ ] |
| 675 | for test in tests |
| 676 | let winid = popup_create(test[0], |
| 677 | \ {'line': 2, 'col': 3, 'maxwidth': 12}) |
| 678 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 679 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 680 | call assert_equal(test[1], position.width) |
| 681 | call assert_equal(test[2], position.height) |
| 682 | |
| 683 | call popup_close(winid) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 684 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 685 | endfor |
| 686 | endfunc |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 687 | |
| 688 | func Test_popup_getoptions() |
| 689 | let winid = popup_create('hello', { |
| 690 | \ 'line': 2, |
| 691 | \ 'col': 3, |
| 692 | \ 'minwidth': 10, |
| 693 | \ 'minheight': 11, |
| 694 | \ 'maxwidth': 20, |
| 695 | \ 'maxheight': 21, |
| 696 | \ 'zindex': 100, |
| 697 | \ 'time': 5000, |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 698 | \ 'fixed': 1 |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 699 | \}) |
| 700 | redraw |
| 701 | let res = popup_getoptions(winid) |
| 702 | call assert_equal(2, res.line) |
| 703 | call assert_equal(3, res.col) |
| 704 | call assert_equal(10, res.minwidth) |
| 705 | call assert_equal(11, res.minheight) |
| 706 | call assert_equal(20, res.maxwidth) |
| 707 | call assert_equal(21, res.maxheight) |
| 708 | call assert_equal(100, res.zindex) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 709 | call assert_equal(1, res.fixed) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 710 | if has('timers') |
| 711 | call assert_equal(5000, res.time) |
| 712 | endif |
| 713 | call popup_close(winid) |
| 714 | |
| 715 | let winid = popup_create('hello', {}) |
| 716 | redraw |
| 717 | let res = popup_getoptions(winid) |
| 718 | call assert_equal(0, res.line) |
| 719 | call assert_equal(0, res.col) |
| 720 | call assert_equal(0, res.minwidth) |
| 721 | call assert_equal(0, res.minheight) |
| 722 | call assert_equal(0, res.maxwidth) |
| 723 | call assert_equal(0, res.maxheight) |
| 724 | call assert_equal(50, res.zindex) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 725 | call assert_equal(0, res.fixed) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 726 | if has('timers') |
| 727 | call assert_equal(0, res.time) |
| 728 | endif |
| 729 | call popup_close(winid) |
| 730 | call assert_equal({}, popup_getoptions(winid)) |
| 731 | endfunc |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 732 | |
| 733 | func Test_popup_option_values() |
| 734 | new |
| 735 | " window-local |
| 736 | setlocal number |
| 737 | setlocal nowrap |
| 738 | " buffer-local |
| 739 | setlocal omnifunc=Something |
| 740 | " global/buffer-local |
| 741 | setlocal path=/there |
| 742 | " global/window-local |
| 743 | setlocal scrolloff=9 |
| 744 | |
| 745 | let winid = popup_create('hello', {}) |
| 746 | call assert_equal(0, getwinvar(winid, '&number')) |
| 747 | call assert_equal(1, getwinvar(winid, '&wrap')) |
| 748 | call assert_equal('', getwinvar(winid, '&omnifunc')) |
| 749 | call assert_equal(&g:path, getwinvar(winid, '&path')) |
| 750 | call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff')) |
| 751 | |
| 752 | call popup_close(winid) |
| 753 | bwipe |
| 754 | endfunc |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 755 | |
| 756 | func Test_popup_atcursor() |
| 757 | topleft vnew |
| 758 | call setline(1, [ |
| 759 | \ 'xxxxxxxxxxxxxxxxx', |
| 760 | \ 'xxxxxxxxxxxxxxxxx', |
| 761 | \ 'xxxxxxxxxxxxxxxxx', |
| 762 | \]) |
| 763 | |
| 764 | call cursor(2, 2) |
| 765 | redraw |
| 766 | let winid = popup_atcursor('vim', {}) |
| 767 | redraw |
| 768 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 769 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 770 | call popup_close(winid) |
| 771 | |
| 772 | call cursor(3, 4) |
| 773 | redraw |
| 774 | let winid = popup_atcursor('vim', {}) |
| 775 | redraw |
| 776 | let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '') |
| 777 | call assert_equal('xxxvimxxxxxxxxxxx', line) |
| 778 | call popup_close(winid) |
| 779 | |
| 780 | call cursor(1, 1) |
| 781 | redraw |
| 782 | let winid = popup_create('vim', { |
| 783 | \ 'line': 'cursor+2', |
| 784 | \ 'col': 'cursor+1', |
| 785 | \}) |
| 786 | redraw |
| 787 | let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '') |
| 788 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 789 | call popup_close(winid) |
| 790 | |
| 791 | call cursor(3, 3) |
| 792 | redraw |
| 793 | let winid = popup_create('vim', { |
| 794 | \ 'line': 'cursor-2', |
| 795 | \ 'col': 'cursor-1', |
| 796 | \}) |
| 797 | redraw |
| 798 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 799 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 800 | call popup_close(winid) |
| 801 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 802 | " just enough room above |
| 803 | call cursor(3, 3) |
| 804 | redraw |
| 805 | let winid = popup_atcursor(['vim', 'is great'], {}) |
| 806 | redraw |
| 807 | let pos = popup_getpos(winid) |
| 808 | call assert_equal(1, pos.line) |
| 809 | call popup_close(winid) |
| 810 | |
| 811 | " not enough room above, popup goes below the cursor |
| 812 | call cursor(3, 3) |
| 813 | redraw |
| 814 | let winid = popup_atcursor(['vim', 'is', 'great'], {}) |
| 815 | redraw |
| 816 | let pos = popup_getpos(winid) |
| 817 | call assert_equal(4, pos.line) |
| 818 | call popup_close(winid) |
| 819 | |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 820 | " cursor in first line, popup in line 2 |
| 821 | call cursor(1, 1) |
| 822 | redraw |
| 823 | let winid = popup_atcursor(['vim', 'is', 'great'], {}) |
| 824 | redraw |
| 825 | let pos = popup_getpos(winid) |
| 826 | call assert_equal(2, pos.line) |
| 827 | call popup_close(winid) |
| 828 | |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 829 | bwipe! |
| 830 | endfunc |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 831 | |
| 832 | func Test_popup_filter() |
| 833 | new |
| 834 | call setline(1, 'some text') |
| 835 | |
| 836 | func MyPopupFilter(winid, c) |
| 837 | if a:c == 'e' |
| 838 | let g:eaten = 'e' |
| 839 | return 1 |
| 840 | endif |
| 841 | if a:c == '0' |
| 842 | let g:ignored = '0' |
| 843 | return 0 |
| 844 | endif |
| 845 | if a:c == 'x' |
| 846 | call popup_close(a:winid) |
| 847 | return 1 |
| 848 | endif |
| 849 | return 0 |
| 850 | endfunc |
| 851 | |
| 852 | let winid = popup_create('something', {'filter': 'MyPopupFilter'}) |
| 853 | redraw |
| 854 | |
| 855 | " e is consumed by the filter |
| 856 | call feedkeys('e', 'xt') |
| 857 | call assert_equal('e', g:eaten) |
| 858 | |
| 859 | " 0 is ignored by the filter |
| 860 | normal $ |
| 861 | call assert_equal(9, getcurpos()[2]) |
| 862 | call feedkeys('0', 'xt') |
| 863 | call assert_equal('0', g:ignored) |
| 864 | call assert_equal(1, getcurpos()[2]) |
| 865 | |
| 866 | " x closes the popup |
| 867 | call feedkeys('x', 'xt') |
| 868 | call assert_equal('e', g:eaten) |
| 869 | call assert_equal(-1, winbufnr(winid)) |
| 870 | |
| 871 | delfunc MyPopupFilter |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 872 | call popup_clear() |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 873 | endfunc |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 874 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 875 | func ShowDialog(key, result) |
| 876 | let s:cb_res = 999 |
| 877 | let winid = popup_dialog('do you want to quit (Yes/no)?', { |
| 878 | \ 'filter': 'popup_filter_yesno', |
| 879 | \ 'callback': 'QuitCallback', |
| 880 | \ }) |
| 881 | redraw |
| 882 | call feedkeys(a:key, "xt") |
| 883 | call assert_equal(winid, s:cb_winid) |
| 884 | call assert_equal(a:result, s:cb_res) |
| 885 | endfunc |
| 886 | |
| 887 | func Test_popup_dialog() |
| 888 | func QuitCallback(id, res) |
| 889 | let s:cb_winid = a:id |
| 890 | let s:cb_res = a:res |
| 891 | endfunc |
| 892 | |
| 893 | let winid = ShowDialog("y", 1) |
| 894 | let winid = ShowDialog("Y", 1) |
| 895 | let winid = ShowDialog("n", 0) |
| 896 | let winid = ShowDialog("N", 0) |
| 897 | let winid = ShowDialog("x", 0) |
| 898 | let winid = ShowDialog("X", 0) |
| 899 | let winid = ShowDialog("\<Esc>", 0) |
| 900 | let winid = ShowDialog("\<C-C>", -1) |
| 901 | |
| 902 | delfunc QuitCallback |
| 903 | endfunc |
| 904 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame^] | 905 | func ShowMenu(key, result) |
| 906 | let s:cb_res = 999 |
| 907 | let winid = popup_menu(['one', 'two', 'something else'], { |
| 908 | \ 'callback': 'QuitCallback', |
| 909 | \ }) |
| 910 | redraw |
| 911 | call feedkeys(a:key, "xt") |
| 912 | call assert_equal(winid, s:cb_winid) |
| 913 | call assert_equal(a:result, s:cb_res) |
| 914 | endfunc |
| 915 | |
| 916 | func Test_popup_menu() |
| 917 | func QuitCallback(id, res) |
| 918 | let s:cb_winid = a:id |
| 919 | let s:cb_res = a:res |
| 920 | endfunc |
| 921 | |
| 922 | let winid = ShowMenu(" ", 1) |
| 923 | let winid = ShowMenu("j \<CR>", 2) |
| 924 | let winid = ShowMenu("JjK \<CR>", 2) |
| 925 | let winid = ShowMenu("jjjjjj ", 3) |
| 926 | let winid = ShowMenu("kkk ", 1) |
| 927 | let winid = ShowMenu("x", -1) |
| 928 | let winid = ShowMenu("X", -1) |
| 929 | let winid = ShowMenu("\<Esc>", -1) |
| 930 | let winid = ShowMenu("\<C-C>", -1) |
| 931 | |
| 932 | delfunc QuitCallback |
| 933 | endfunc |
| 934 | |
| 935 | func Test_popup_menu_screenshot() |
| 936 | if !CanRunVimInTerminal() |
| 937 | throw 'Skipped: cannot make screendumps' |
| 938 | endif |
| 939 | |
| 940 | let lines =<< trim END |
| 941 | call setline(1, range(1, 20)) |
| 942 | hi PopupSelected ctermbg=lightblue |
| 943 | call popup_menu(['one', 'two', 'another'], {'callback': 'MenuDone'}) |
| 944 | func MenuDone(id, res) |
| 945 | echomsg "selected " .. a:res |
| 946 | endfunc |
| 947 | END |
| 948 | call writefile(lines, 'XtestPopupMenu') |
| 949 | let buf = RunVimInTerminal('-S XtestPopupMenu', {'rows': 10}) |
| 950 | call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {}) |
| 951 | |
| 952 | call term_sendkeys(buf, "jj") |
| 953 | call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {}) |
| 954 | |
| 955 | call term_sendkeys(buf, " ") |
| 956 | call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {}) |
| 957 | |
| 958 | " clean up |
| 959 | call StopVimInTerminal(buf) |
| 960 | call delete('XtestPopupMenu') |
| 961 | endfunc |
| 962 | |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 963 | func Test_popup_close_callback() |
| 964 | func PopupDone(id, result) |
| 965 | let g:result = a:result |
| 966 | endfunc |
| 967 | let winid = popup_create('something', {'callback': 'PopupDone'}) |
| 968 | redraw |
| 969 | call popup_close(winid, 'done') |
| 970 | call assert_equal('done', g:result) |
| 971 | endfunc |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 972 | |
| 973 | func Test_popup_empty() |
| 974 | let winid = popup_create('', {'padding': [2,2,2,2]}) |
| 975 | redraw |
| 976 | let pos = popup_getpos(winid) |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 977 | call assert_equal(5, pos.width) |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 978 | call assert_equal(5, pos.height) |
| 979 | |
| 980 | let winid = popup_create([], {'border': []}) |
| 981 | redraw |
| 982 | let pos = popup_getpos(winid) |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 983 | call assert_equal(3, pos.width) |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 984 | call assert_equal(3, pos.height) |
| 985 | endfunc |
Bram Moolenaar | 988c433 | 2019-06-02 14:12:11 +0200 | [diff] [blame] | 986 | |
| 987 | func Test_popup_never_behind() |
| 988 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 989 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 988c433 | 2019-06-02 14:12:11 +0200 | [diff] [blame] | 990 | endif |
| 991 | " +-----------------------------+ |
| 992 | " | | | |
| 993 | " | | | |
| 994 | " | | | |
| 995 | " | line1 | |
| 996 | " |------------line2------------| |
| 997 | " | line3 | |
| 998 | " | line4 | |
| 999 | " | | |
| 1000 | " | | |
| 1001 | " +-----------------------------+ |
| 1002 | let lines =<< trim END |
| 1003 | only |
| 1004 | split |
| 1005 | vsplit |
| 1006 | let info_window1 = getwininfo()[0] |
| 1007 | let line = info_window1['height'] |
| 1008 | let col = info_window1['width'] |
| 1009 | call popup_create(['line1', 'line2', 'line3', 'line4'], { |
| 1010 | \ 'line' : line, |
| 1011 | \ 'col' : col, |
| 1012 | \ }) |
| 1013 | END |
| 1014 | call writefile(lines, 'XtestPopupBehind') |
| 1015 | let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10}) |
| 1016 | call term_sendkeys(buf, "\<C-W>w") |
| 1017 | call VerifyScreenDump(buf, 'Test_popupwin_behind', {}) |
| 1018 | |
| 1019 | " clean up |
| 1020 | call StopVimInTerminal(buf) |
| 1021 | call delete('XtestPopupBehind') |
| 1022 | endfunc |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1023 | |
| 1024 | func s:VerifyPosition( p, msg, line, col, width, height ) |
| 1025 | call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' ) |
| 1026 | call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' ) |
| 1027 | call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' ) |
| 1028 | call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' ) |
| 1029 | endfunc |
| 1030 | |
| 1031 | func Test_popup_position_adjust() |
| 1032 | " Anything placed past 2 cells from of the right of the screen is moved to the |
| 1033 | " left. |
| 1034 | " |
| 1035 | " When wrapping is disabled, we also shift to the left to display on the |
| 1036 | " screen, unless fixed is set. |
| 1037 | |
| 1038 | " Entries for cases which don't vary based on wrapping. |
| 1039 | " Format is per tests described below |
| 1040 | let both_wrap_tests = [ |
| 1041 | \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ], |
| 1042 | \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ], |
| 1043 | \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ], |
| 1044 | \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ], |
| 1045 | \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ], |
| 1046 | \ |
| 1047 | \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ], |
| 1048 | \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ], |
| 1049 | \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ], |
| 1050 | \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ], |
| 1051 | \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ], |
| 1052 | \ |
| 1053 | \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ], |
| 1054 | \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ], |
| 1055 | \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ], |
| 1056 | \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ], |
| 1057 | \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ], |
| 1058 | \ ] |
| 1059 | |
| 1060 | " these test groups are dicts with: |
| 1061 | " - comment: something to identify the group of tests by |
| 1062 | " - options: dict of options to merge with the row/col in tests |
| 1063 | " - tests: list of cases. Each one is a list with elements: |
| 1064 | " - text |
| 1065 | " - row |
| 1066 | " - col |
| 1067 | " - expected row |
| 1068 | " - expected col |
| 1069 | " - expected width |
| 1070 | " - expected height |
| 1071 | let tests = [ |
| 1072 | \ { |
| 1073 | \ 'comment': 'left-aligned with wrapping', |
| 1074 | \ 'options': { |
| 1075 | \ 'wrap': 1, |
| 1076 | \ 'pos': 'botleft', |
| 1077 | \ }, |
| 1078 | \ 'tests': both_wrap_tests + [ |
| 1079 | \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ], |
| 1080 | \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ], |
| 1081 | \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ], |
| 1082 | \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ], |
| 1083 | \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], |
| 1084 | \ ], |
| 1085 | \ }, |
| 1086 | \ { |
| 1087 | \ 'comment': 'left aligned without wrapping', |
| 1088 | \ 'options': { |
| 1089 | \ 'wrap': 0, |
| 1090 | \ 'pos': 'botleft', |
| 1091 | \ }, |
| 1092 | \ 'tests': both_wrap_tests + [ |
| 1093 | \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ], |
| 1094 | \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ], |
| 1095 | \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ], |
| 1096 | \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ], |
| 1097 | \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], |
| 1098 | \ ], |
| 1099 | \ }, |
| 1100 | \ { |
| 1101 | \ 'comment': 'left aligned with fixed position', |
| 1102 | \ 'options': { |
| 1103 | \ 'wrap': 0, |
| 1104 | \ 'fixed': 1, |
| 1105 | \ 'pos': 'botleft', |
| 1106 | \ }, |
| 1107 | \ 'tests': both_wrap_tests + [ |
| 1108 | \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ], |
| 1109 | \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ], |
| 1110 | \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ], |
| 1111 | \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ], |
| 1112 | \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], |
| 1113 | \ ], |
| 1114 | \ }, |
| 1115 | \ ] |
| 1116 | |
| 1117 | for test_group in tests |
| 1118 | for test in test_group.tests |
| 1119 | let [ text, line, col, e_line, e_col, e_width, e_height ] = test |
| 1120 | let options = { |
| 1121 | \ 'line': line, |
| 1122 | \ 'col': col, |
| 1123 | \ } |
| 1124 | call extend( options, test_group.options ) |
| 1125 | |
| 1126 | let p = popup_create( text, options ) |
| 1127 | |
| 1128 | let msg = string( extend( options, { 'text': text } ) ) |
| 1129 | call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height ) |
| 1130 | call popup_close( p ) |
| 1131 | endfor |
| 1132 | endfor |
| 1133 | |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1134 | call popup_clear() |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1135 | %bwipe! |
| 1136 | endfunc |
| 1137 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1138 | func Test_adjust_left_past_screen_width() |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1139 | " width of screen |
| 1140 | let X = join(map(range(&columns), {->'X'}), '') |
| 1141 | |
| 1142 | let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } ) |
| 1143 | call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 ) |
| 1144 | |
| 1145 | redraw |
| 1146 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1147 | call assert_equal(X, line) |
| 1148 | |
| 1149 | call popup_close( p ) |
| 1150 | redraw |
| 1151 | |
| 1152 | " Same if placed on the right hand side |
| 1153 | let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } ) |
| 1154 | call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 ) |
| 1155 | |
| 1156 | redraw |
| 1157 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1158 | call assert_equal(X, line) |
| 1159 | |
| 1160 | call popup_close( p ) |
| 1161 | redraw |
| 1162 | |
| 1163 | " Extend so > window width |
| 1164 | let X .= 'x' |
| 1165 | |
| 1166 | let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } ) |
| 1167 | call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 ) |
| 1168 | |
| 1169 | redraw |
| 1170 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1171 | call assert_equal(X[ : -2 ], line) |
| 1172 | |
| 1173 | call popup_close( p ) |
| 1174 | redraw |
| 1175 | |
| 1176 | " Shifted then truncated (the x is not visible) |
| 1177 | let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } ) |
| 1178 | call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 ) |
| 1179 | |
| 1180 | redraw |
| 1181 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1182 | call assert_equal(X[ : -2 ], line) |
| 1183 | |
| 1184 | call popup_close( p ) |
| 1185 | redraw |
| 1186 | |
| 1187 | " Not shifted, just truncated |
| 1188 | let p = popup_create( X, |
| 1189 | \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } ) |
| 1190 | call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1) |
| 1191 | |
| 1192 | redraw |
| 1193 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1194 | let e_line = ' ' . X[ 1 : -2 ] |
| 1195 | call assert_equal(e_line, line) |
| 1196 | |
| 1197 | call popup_close( p ) |
| 1198 | redraw |
| 1199 | |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1200 | call popup_clear() |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1201 | %bwipe! |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1202 | endfunc |
| 1203 | |
| 1204 | func Test_popup_moved() |
| 1205 | new |
| 1206 | call test_override('char_avail', 1) |
| 1207 | call setline(1, ['one word to move around', 'a WORD.and->some thing']) |
| 1208 | |
| 1209 | exe "normal gg0/word\<CR>" |
| 1210 | let winid = popup_atcursor('text', {'moved': 'any'}) |
| 1211 | redraw |
| 1212 | call assert_equal(1, popup_getpos(winid).visible) |
| 1213 | " trigger the check for last_cursormoved by going into insert mode |
| 1214 | call feedkeys("li\<Esc>", 'xt') |
| 1215 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1216 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1217 | |
| 1218 | exe "normal gg0/word\<CR>" |
| 1219 | let winid = popup_atcursor('text', {'moved': 'word'}) |
| 1220 | redraw |
| 1221 | call assert_equal(1, popup_getpos(winid).visible) |
| 1222 | call feedkeys("hi\<Esc>", 'xt') |
| 1223 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1224 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1225 | |
| 1226 | exe "normal gg0/word\<CR>" |
| 1227 | let winid = popup_atcursor('text', {'moved': 'word'}) |
| 1228 | redraw |
| 1229 | call assert_equal(1, popup_getpos(winid).visible) |
| 1230 | call feedkeys("li\<Esc>", 'xt') |
| 1231 | call assert_equal(1, popup_getpos(winid).visible) |
| 1232 | call feedkeys("ei\<Esc>", 'xt') |
| 1233 | call assert_equal(1, popup_getpos(winid).visible) |
| 1234 | call feedkeys("eli\<Esc>", 'xt') |
| 1235 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1236 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1237 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1238 | " WORD is the default |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1239 | exe "normal gg0/WORD\<CR>" |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1240 | let winid = popup_atcursor('text', {}) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1241 | redraw |
| 1242 | call assert_equal(1, popup_getpos(winid).visible) |
| 1243 | call feedkeys("eli\<Esc>", 'xt') |
| 1244 | call assert_equal(1, popup_getpos(winid).visible) |
| 1245 | call feedkeys("wi\<Esc>", 'xt') |
| 1246 | call assert_equal(1, popup_getpos(winid).visible) |
| 1247 | call feedkeys("Eli\<Esc>", 'xt') |
| 1248 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1249 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1250 | |
| 1251 | exe "normal gg0/word\<CR>" |
| 1252 | let winid = popup_atcursor('text', {'moved': [5, 10]}) |
| 1253 | redraw |
| 1254 | call assert_equal(1, popup_getpos(winid).visible) |
| 1255 | call feedkeys("eli\<Esc>", 'xt') |
| 1256 | call feedkeys("ei\<Esc>", 'xt') |
| 1257 | call assert_equal(1, popup_getpos(winid).visible) |
| 1258 | call feedkeys("eli\<Esc>", 'xt') |
| 1259 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1260 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1261 | |
| 1262 | bwipe! |
| 1263 | call test_override('ALL', 0) |
| 1264 | endfunc |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1265 | |
| 1266 | func Test_notifications() |
| 1267 | if !has('timers') |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 1268 | throw 'Skipped: timer feature not supported' |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1269 | endif |
| 1270 | if !CanRunVimInTerminal() |
| 1271 | throw 'Skipped: cannot make screendumps' |
| 1272 | endif |
| 1273 | |
| 1274 | call writefile([ |
| 1275 | \ "call setline(1, range(1, 20))", |
| 1276 | \ "hi Notification ctermbg=lightblue", |
| 1277 | \ "call popup_notification('first notification', {})", |
| 1278 | \], 'XtestNotifications') |
| 1279 | let buf = RunVimInTerminal('-S XtestNotifications', {'rows': 10}) |
| 1280 | call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {}) |
| 1281 | |
| 1282 | " second one goes below the first one |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1283 | call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>") |
| 1284 | call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>") |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1285 | call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {}) |
| 1286 | |
| 1287 | |
| 1288 | " clean up |
| 1289 | call StopVimInTerminal(buf) |
| 1290 | call delete('XtestNotifications') |
| 1291 | endfunc |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1292 | |
| 1293 | function Test_popup_settext() |
| 1294 | if !CanRunVimInTerminal() |
| 1295 | throw 'Skipped: cannot make screendumps' |
| 1296 | endif |
| 1297 | |
| 1298 | let lines =<< trim END |
| 1299 | let opts = {'wrap': 0} |
| 1300 | let p = popup_create('test', opts) |
| 1301 | call popup_settext(p, 'this is a text') |
| 1302 | END |
| 1303 | |
| 1304 | call writefile( lines, 'XtestPopupSetText' ) |
| 1305 | let buf = RunVimInTerminal('-S XtestPopupSetText', {'rows': 10}) |
| 1306 | call VerifyScreenDump(buf, 'Test_popup_settext_01', {}) |
| 1307 | |
| 1308 | " Setting to empty string clears it |
| 1309 | call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>") |
| 1310 | call VerifyScreenDump(buf, 'Test_popup_settext_02', {}) |
| 1311 | |
| 1312 | " Setting a list |
| 1313 | call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>") |
| 1314 | call VerifyScreenDump(buf, 'Test_popup_settext_03', {}) |
| 1315 | |
| 1316 | " Shrinking with a list |
| 1317 | call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>") |
| 1318 | call VerifyScreenDump(buf, 'Test_popup_settext_04', {}) |
| 1319 | |
| 1320 | " Growing with a list |
| 1321 | call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>") |
| 1322 | call VerifyScreenDump(buf, 'Test_popup_settext_03', {}) |
| 1323 | |
| 1324 | " Empty list clears |
| 1325 | call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>") |
| 1326 | call VerifyScreenDump(buf, 'Test_popup_settext_05', {}) |
| 1327 | |
| 1328 | " Dicts |
| 1329 | call term_sendkeys(buf, ":call popup_settext(p, [{'text': 'aaaa'}, {'text': 'bbbb'}, {'text': 'cccc'}])\<CR>") |
| 1330 | call VerifyScreenDump(buf, 'Test_popup_settext_06', {}) |
| 1331 | |
| 1332 | " clean up |
| 1333 | call StopVimInTerminal(buf) |
| 1334 | call delete('XtestPopupSetText') |
| 1335 | endfunction |