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("call NestedRedir()")', 'E930:') 34 35 call assert_equal("\nsomething", execute('echo "something"', '')) 36 call assert_equal("\nsomething", execute('echo "something"', 'silent')) 37 call assert_equal("\nsomething", execute('echo "something"', 'silent!')) 38 call assert_equal("", execute('burp', 'silent!')) 39 if has('float') 40 call assert_fails('call execute(3.4)', 'E806:') 41 call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:') 42 endif 43endfunc 44 45func Test_execute_list() 46 call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"'])) 47 let l = ['for n in range(0, 3)', 48 \ 'echo n', 49 \ 'endfor'] 50 call assert_equal("\n0\n1\n2\n3", execute(l)) 51 52 call assert_equal("", execute([])) 53endfunc 54 55func Test_execute_does_not_change_col() 56 echo '' 57 echon 'abcd' 58 let x = execute('silent echo 234343') 59 echon 'xyz' 60 let text = '' 61 for col in range(1, 7) 62 let text .= nr2char(screenchar(&lines, col)) 63 endfor 64 call assert_equal('abcdxyz', text) 65endfunc 66 67func Test_execute_not_silent() 68 echo '' 69 echon 'abcd' 70 let x = execute('echon 234', '') 71 echo 'xyz' 72 let text1 = '' 73 for col in range(1, 8) 74 let text1 .= nr2char(screenchar(&lines - 1, col)) 75 endfor 76 call assert_equal('abcd234 ', text1) 77 let text2 = '' 78 for col in range(1, 4) 79 let text2 .= nr2char(screenchar(&lines, col)) 80 endfor 81 call assert_equal('xyz ', text2) 82endfunc 83 84func Test_win_execute() 85 let thiswin = win_getid() 86 new 87 let otherwin = win_getid() 88 call setline(1, 'the new window') 89 call win_gotoid(thiswin) 90 let line = win_execute(otherwin, 'echo getline(1)') 91 call assert_match('the new window', line) 92 93 if has('popupwin') 94 let popupwin = popup_create('the popup win', {'line': 2, 'col': 3}) 95 redraw 96 let line = 'echo getline(1)'->win_execute(popupwin) 97 call assert_match('the popup win', line) 98 99 call popup_close(popupwin) 100 endif 101 102 call win_gotoid(otherwin) 103 bwipe! 104endfunc 105 106func Test_win_execute_update_ruler() 107 CheckFeature quickfix 108 109 enew 110 call setline(1, range(500)) 111 20 112 split 113 let winid = win_getid() 114 set ruler 115 wincmd w 116 let height = winheight(winid) 117 redraw 118 call assert_match('20,1', Screenline(height + 1)) 119 let line = win_execute(winid, 'call cursor(100, 1)') 120 redraw 121 call assert_match('100,1', Screenline(height + 1)) 122 123 bwipe! 124endfunc 125 126func Test_win_execute_other_tab() 127 let thiswin = win_getid() 128 tabnew 129 call win_execute(thiswin, 'let xyz = 1') 130 call assert_equal(1, xyz) 131 tabclose 132 unlet xyz 133endfunc 134 135func Test_execute_null() 136 call assert_equal("", execute(test_null_string())) 137 call assert_equal("", execute(test_null_list())) 138 call assert_fails('call execute(test_null_dict())', 'E731:') 139 call assert_fails('call execute(test_null_blob())', 'E976:') 140 call assert_fails('call execute(test_null_partial())','E729:') 141 if has('job') 142 call assert_fails('call execute(test_null_job())', 'E908:') 143 call assert_fails('call execute(test_null_channel())', 'E908:') 144 endif 145endfunc 146