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