1" test execute() 2 3func NestedEval() 4 let nested = execute('echo "nested\nlines"') 5 echo 'got: "' . nested . '"' 6endfunc 7 8func NestedRedir() 9 redir => var 10 echo 'broken' 11 redir END 12endfunc 13 14func Test_execute_string() 15 call assert_equal("\nnocompatible", execute('set compatible?')) 16 call assert_equal("\nsomething\nnice", execute('echo "something\nnice"')) 17 call assert_equal("noendofline", execute('echon "noendofline"')) 18 call assert_equal("", execute(123)) 19 20 call assert_equal("\ngot: \"\nnested\nlines\"", execute('call NestedEval()')) 21 redir => redired 22 echo 'this' 23 let evaled = execute('echo "that"') 24 echo 'theend' 25 redir END 26 call assert_equal("\nthis\ntheend", redired) 27 call assert_equal("\nthat", evaled) 28 29 call assert_fails('call execute("doesnotexist")', 'E492:') 30 call assert_fails('call execute(3.4)', 'E806:') 31 call assert_fails('call execute("call NestedRedir()")', 'E930:') 32 33 call assert_equal("\nsomething", execute('echo "something"', '')) 34 call assert_equal("\nsomething", execute('echo "something"', 'silent')) 35 call assert_equal("\nsomething", execute('echo "something"', 'silent!')) 36 call assert_equal("", execute('burp', 'silent!')) 37 call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:') 38 39 call assert_equal("", execute(test_null_string())) 40endfunc 41 42func Test_execute_list() 43 call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"'])) 44 let l = ['for n in range(0, 3)', 45 \ 'echo n', 46 \ 'endfor'] 47 call assert_equal("\n0\n1\n2\n3", execute(l)) 48 49 call assert_equal("", execute([])) 50 call assert_equal("", execute(test_null_list())) 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