Bram Moolenaar | 79815f1 | 2016-07-09 17:07:29 +0200 | [diff] [blame] | 1 | " test execute() |
| 2 | |
| 3 | func NestedEval() |
| 4 | let nested = execute('echo "nested\nlines"') |
| 5 | echo 'got: "' . nested . '"' |
| 6 | endfunc |
| 7 | |
| 8 | func NestedRedir() |
| 9 | redir => var |
| 10 | echo 'broken' |
| 11 | redir END |
| 12 | endfunc |
| 13 | |
| 14 | func 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())) |
| 40 | endfunc |
| 41 | |
| 42 | func 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())) |
| 51 | endfunc |
Bram Moolenaar | 10ccaa1 | 2018-12-07 16:38:23 +0100 | [diff] [blame^] | 52 | |
| 53 | func 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) |
| 63 | endfunc |