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