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