2017-01-08 21:13:51 -07:00
|
|
|
" test execute()
|
|
|
|
|
2021-04-30 19:31:15 -07:00
|
|
|
source view_util.vim
|
|
|
|
|
2017-01-08 21:13:51 -07:00
|
|
|
func NestedEval()
|
|
|
|
let nested = execute('echo "nested\nlines"')
|
|
|
|
echo 'got: "' . nested . '"'
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func NestedRedir()
|
|
|
|
redir => var
|
|
|
|
echo 'broken'
|
|
|
|
redir END
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_execute_string()
|
|
|
|
call assert_equal("\nnocompatible", execute('set compatible?'))
|
|
|
|
call assert_equal("\nsomething\nnice", execute('echo "something\nnice"'))
|
|
|
|
call assert_equal("noendofline", execute('echon "noendofline"'))
|
|
|
|
call assert_equal("", execute(123))
|
|
|
|
|
|
|
|
call assert_equal("\ngot: \"\nnested\nlines\"", execute('call NestedEval()'))
|
|
|
|
redir => redired
|
|
|
|
echo 'this'
|
|
|
|
let evaled = execute('echo "that"')
|
|
|
|
echo 'theend'
|
|
|
|
redir END
|
|
|
|
" Nvim supports execute('... :redir ...'), so this test is intentionally
|
|
|
|
" disabled.
|
|
|
|
" call assert_equal("\nthis\ntheend", redired)
|
|
|
|
call assert_equal("\nthat", evaled)
|
|
|
|
|
|
|
|
call assert_fails('call execute("doesnotexist")', 'E492:')
|
|
|
|
call assert_fails('call execute(3.4)', 'E806:')
|
|
|
|
" Nvim supports execute('... :redir ...'), so this test is intentionally
|
|
|
|
" disabled.
|
|
|
|
" call assert_fails('call execute("call NestedRedir()")', 'E930:')
|
|
|
|
|
|
|
|
call assert_equal("\nsomething", execute('echo "something"', ''))
|
|
|
|
call assert_equal("\nsomething", execute('echo "something"', 'silent'))
|
|
|
|
call assert_equal("\nsomething", execute('echo "something"', 'silent!'))
|
|
|
|
call assert_equal("", execute('burp', 'silent!'))
|
|
|
|
call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:')
|
|
|
|
|
|
|
|
call assert_equal("", execute(""))
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_execute_list()
|
|
|
|
call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"']))
|
|
|
|
let l = ['for n in range(0, 3)',
|
|
|
|
\ 'echo n',
|
|
|
|
\ 'endfor']
|
|
|
|
call assert_equal("\n0\n1\n2\n3", execute(l))
|
|
|
|
|
|
|
|
call assert_equal("", execute([]))
|
|
|
|
call assert_equal("", execute(v:_null_list))
|
|
|
|
endfunc
|
2018-12-08 12:05:07 -07:00
|
|
|
|
|
|
|
func Test_execute_does_not_change_col()
|
|
|
|
echo ''
|
|
|
|
echon 'abcd'
|
|
|
|
let x = execute('silent echo 234343')
|
|
|
|
echon 'xyz'
|
|
|
|
let text = ''
|
|
|
|
for col in range(1, 7)
|
|
|
|
let text .= nr2char(screenchar(&lines, col))
|
|
|
|
endfor
|
|
|
|
call assert_equal('abcdxyz', text)
|
|
|
|
endfunc
|
2018-12-09 06:33:11 -07:00
|
|
|
|
|
|
|
func Test_execute_not_silent()
|
|
|
|
echo ''
|
|
|
|
echon 'abcd'
|
|
|
|
let x = execute('echon 234', '')
|
|
|
|
echo 'xyz'
|
|
|
|
let text1 = ''
|
|
|
|
for col in range(1, 8)
|
|
|
|
let text1 .= nr2char(screenchar(&lines - 1, col))
|
|
|
|
endfor
|
|
|
|
call assert_equal('abcd234 ', text1)
|
|
|
|
let text2 = ''
|
|
|
|
for col in range(1, 4)
|
|
|
|
let text2 .= nr2char(screenchar(&lines, col))
|
|
|
|
endfor
|
|
|
|
call assert_equal('xyz ', text2)
|
|
|
|
endfunc
|
2021-04-24 08:09:31 -07:00
|
|
|
|
|
|
|
func Test_win_execute()
|
|
|
|
let thiswin = win_getid()
|
|
|
|
new
|
|
|
|
let otherwin = win_getid()
|
|
|
|
call setline(1, 'the new window')
|
|
|
|
call win_gotoid(thiswin)
|
|
|
|
let line = win_execute(otherwin, 'echo getline(1)')
|
|
|
|
call assert_match('the new window', line)
|
2021-04-30 19:44:21 -07:00
|
|
|
let line = win_execute(134343, 'echo getline(1)')
|
|
|
|
call assert_equal('', line)
|
2021-04-24 08:09:31 -07:00
|
|
|
|
|
|
|
if has('textprop')
|
|
|
|
let popupwin = popup_create('the popup win', {'line': 2, 'col': 3})
|
|
|
|
redraw
|
2021-11-01 09:26:19 -07:00
|
|
|
let line = 'echo getline(1)'->win_execute(popupwin)
|
2021-04-24 08:09:31 -07:00
|
|
|
call assert_match('the popup win', line)
|
|
|
|
|
|
|
|
call popup_close(popupwin)
|
|
|
|
endif
|
|
|
|
|
|
|
|
call win_gotoid(otherwin)
|
|
|
|
bwipe!
|
2021-11-17 19:18:55 -07:00
|
|
|
|
|
|
|
" check :lcd in another window does not change directory
|
|
|
|
let curid = win_getid()
|
|
|
|
let curdir = getcwd()
|
|
|
|
split Xother
|
|
|
|
lcd ..
|
|
|
|
" Use :pwd to get the actual current directory
|
|
|
|
let otherdir = execute('pwd')
|
|
|
|
call win_execute(curid, 'lcd testdir')
|
|
|
|
call assert_equal(otherdir, execute('pwd'))
|
|
|
|
bwipe!
|
|
|
|
execute 'cd ' .. curdir
|
2021-04-24 08:09:31 -07:00
|
|
|
endfunc
|
2021-04-30 19:21:14 -07:00
|
|
|
|
2021-04-30 19:31:15 -07:00
|
|
|
func Test_win_execute_update_ruler()
|
|
|
|
enew
|
|
|
|
call setline(1, range(500))
|
|
|
|
20
|
|
|
|
split
|
|
|
|
let winid = win_getid()
|
|
|
|
set ruler
|
|
|
|
wincmd w
|
|
|
|
let height = winheight(winid)
|
|
|
|
redraw
|
|
|
|
call assert_match('20,1', Screenline(height + 1))
|
|
|
|
let line = win_execute(winid, 'call cursor(100, 1)')
|
|
|
|
redraw
|
|
|
|
call assert_match('100,1', Screenline(height + 1))
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
2021-04-30 19:21:14 -07:00
|
|
|
func Test_win_execute_other_tab()
|
|
|
|
let thiswin = win_getid()
|
|
|
|
tabnew
|
|
|
|
call win_execute(thiswin, 'let xyz = 1')
|
|
|
|
call assert_equal(1, xyz)
|
|
|
|
tabclose
|
|
|
|
unlet xyz
|
|
|
|
endfunc
|
2022-01-06 06:48:37 -07:00
|
|
|
|
|
|
|
func Test_win_execute_visual_redraw()
|
|
|
|
call setline(1, ['a', 'b', 'c'])
|
|
|
|
new
|
|
|
|
wincmd p
|
2022-01-07 10:27:47 -07:00
|
|
|
" start Visual in current window, redraw in other window with fewer lines
|
2022-01-06 06:48:37 -07:00
|
|
|
call feedkeys("G\<C-V>", 'txn')
|
|
|
|
call win_execute(winnr('#')->win_getid(), 'redraw')
|
2022-01-07 10:27:47 -07:00
|
|
|
call feedkeys("\<Esc>", 'txn')
|
|
|
|
bwipe!
|
|
|
|
bwipe!
|
|
|
|
|
|
|
|
enew
|
|
|
|
new
|
|
|
|
call setline(1, ['a', 'b', 'c'])
|
|
|
|
let winid = win_getid()
|
|
|
|
wincmd p
|
|
|
|
" start Visual in current window, extend it in other window with more lines
|
|
|
|
call feedkeys("\<C-V>", 'txn')
|
|
|
|
call win_execute(winid, 'call feedkeys("G\<C-V>", ''txn'')')
|
|
|
|
redraw
|
|
|
|
|
2022-01-06 06:48:37 -07:00
|
|
|
bwipe!
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|