1" test execute() 2 3source view_util.vim 4source check.vim 5 6func NestedEval() 7 let nested = execute('echo "nested\nlines"') 8 echo 'got: "' . nested . '"' 9endfunc 10 11func NestedRedir() 12 redir => var 13 echo 'broken' 14 redir END 15endfunc 16 17func Test_execute_string() 18 call assert_equal("\nnocompatible", execute('set compatible?')) 19 call assert_equal("\nsomething\nnice", execute('echo "something\nnice"')) 20 call assert_equal("noendofline", execute('echon "noendofline"')) 21 call assert_equal("", execute(123)) 22 23 call assert_equal("\ngot: \"\nnested\nlines\"", execute('call NestedEval()')) 24 redir => redired 25 echo 'this' 26 let evaled = execute('echo "that"') 27 echo 'theend' 28 redir END 29 call assert_equal("\nthis\ntheend", redired) 30 call assert_equal("\nthat", evaled) 31 32 call assert_fails('call execute("doesnotexist")', 'E492:') 33 call assert_fails('call execute(3.4)', 'E806:') 34 call assert_fails('call execute("call NestedRedir()")', 'E930:') 35 36 call assert_equal("\nsomething", execute('echo "something"', '')) 37 call assert_equal("\nsomething", execute('echo "something"', 'silent')) 38 call assert_equal("\nsomething", execute('echo "something"', 'silent!')) 39 call assert_equal("", execute('burp', 'silent!')) 40 call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:') 41endfunc 42 43func Test_execute_list() 44 call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"'])) 45 let l = ['for n in range(0, 3)', 46 \ 'echo n', 47 \ 'endfor'] 48 call assert_equal("\n0\n1\n2\n3", execute(l)) 49 50 call assert_equal("", execute([])) 51endfunc 52 53func Test_execute_does_not_change_col() 54 echo '' 55 echon 'abcd' 56 let x = execute('silent echo 234343') 57 echon 'xyz' 58 let text = '' 59 for col in range(1, 7) 60 let text .= nr2char(screenchar(&lines, col)) 61 endfor 62 call assert_equal('abcdxyz', text) 63endfunc 64 65func Test_execute_not_silent() 66 echo '' 67 echon 'abcd' 68 let x = execute('echon 234', '') 69 echo 'xyz' 70 let text1 = '' 71 for col in range(1, 8) 72 let text1 .= nr2char(screenchar(&lines - 1, col)) 73 endfor 74 call assert_equal('abcd234 ', text1) 75 let text2 = '' 76 for col in range(1, 4) 77 let text2 .= nr2char(screenchar(&lines, col)) 78 endfor 79 call assert_equal('xyz ', text2) 80endfunc 81 82func Test_win_execute() 83 let thiswin = win_getid() 84 new 85 let otherwin = win_getid() 86 call setline(1, 'the new window') 87 call win_gotoid(thiswin) 88 let line = win_execute(otherwin, 'echo getline(1)') 89 call assert_match('the new window', line) 90 91 if has('popupwin') 92 let popupwin = popup_create('the popup win', {'line': 2, 'col': 3}) 93 redraw 94 let line = 'echo getline(1)'->win_execute(popupwin) 95 call assert_match('the popup win', line) 96 97 call popup_close(popupwin) 98 endif 99 100 call win_gotoid(otherwin) 101 bwipe! 102endfunc 103 104func Test_win_execute_update_ruler() 105 CheckFeature quickfix 106 107 enew 108 call setline(1, range(500)) 109 20 110 split 111 let winid = win_getid() 112 set ruler 113 wincmd w 114 let height = winheight(winid) 115 redraw 116 call assert_match('20,1', Screenline(height + 1)) 117 let line = win_execute(winid, 'call cursor(100, 1)') 118 redraw 119 call assert_match('100,1', Screenline(height + 1)) 120 121 bwipe! 122endfunc 123 124func Test_win_execute_other_tab() 125 let thiswin = win_getid() 126 tabnew 127 call win_execute(thiswin, 'let xyz = 1') 128 call assert_equal(1, xyz) 129 tabclose 130 unlet xyz 131endfunc 132 133func Test_execute_null() 134 call assert_equal("", execute(test_null_string())) 135 call assert_equal("", execute(test_null_list())) 136 call assert_fails('call execute(test_null_dict())', 'E731:') 137 call assert_fails('call execute(test_null_blob())', 'E976:') 138 call assert_fails('call execute(test_null_partial())','E729:') 139 if has('job') 140 call assert_fails('call execute(test_null_job())', 'E908:') 141 call assert_fails('call execute(test_null_channel())', 'E908:') 142 endif 143endfunc 144