" Tests for popup windows
source check.vim
CheckFeature textprop
source screendump.vim
func Test_simple_popup()
if !CanRunVimInTerminal()
throw 'Skipped: cannot make screendumps'
endif
call writefile([
\ "call setline(1, range(1, 100))",
\ "hi PopupColor1 ctermbg=lightblue",
\ "hi PopupColor2 ctermbg=lightcyan",
\ "hi Comment ctermfg=red",
\ "call prop_type_add('comment', {'highlight': 'Comment'})",
\ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})",
\ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25, 'minwidth': 20})",
\ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
\], 'XtestPopup')
let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
call VerifyScreenDump(buf, 'Test_popupwin_01', {})
" Add a tabpage
call term_sendkeys(buf, ":tabnew\<CR>")
call term_sendkeys(buf, ":let popupwin = popup_create(["
\ .. "{'text': 'other tab'},"
\ .. "{'text': 'a comment line', 'props': [{"
\ .. "'col': 3, 'length': 7, 'minwidth': 20, 'type': 'comment'"
\ .. "}]},"
\ .. "], {'line': 4, 'col': 9, 'minwidth': 20})\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_02', {})
" switch back to first tabpage
call term_sendkeys(buf, "gt")
call VerifyScreenDump(buf, 'Test_popupwin_03', {})
" close that tabpage
call term_sendkeys(buf, ":quit!\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_04', {})
" set 'columns' to a small value, size must be recomputed
call term_sendkeys(buf, ":let cols = &columns\<CR>")
call term_sendkeys(buf, ":set columns=12\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_04a', {})
call term_sendkeys(buf, ":let &columns = cols\<CR>")
" resize popup, show empty line at bottom
call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>")
call term_sendkeys(buf, ":redraw\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_05', {})
" show not fitting line at bottom
call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
call term_sendkeys(buf, ":redraw\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_06', {})
" move popup over ruler
call term_sendkeys(buf, ":set cmdheight=2\<CR>")
call term_sendkeys(buf, ":call popup_move(popupwin, {'line': 7, 'col': 55})\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_07', {})
" clear all popups after moving the cursor a bit, so that ruler is updated
call term_sendkeys(buf, "axxx\<Esc>")
call term_wait(buf)
call term_sendkeys(buf, "0")
call term_wait(buf)
call term_sendkeys(buf, ":call popup_clear()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_08', {})
" clean up
call StopVimInTerminal(buf)
call delete('XtestPopup')
endfunc
func Test_popup_with_border_and_padding()
if !CanRunVimInTerminal()
throw 'Skipped: cannot make screendumps'
endif
for iter in range(0, 1)
call writefile([iter == 1 ? '' : 'set enc=latin1'