blob: 7b3cf21a58d99144d471247ffee6decc5fbe376a [file] [log] [blame]
Bram Moolenaar79815f12016-07-09 17:07:29 +02001" 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
Bram Moolenaar10ccaa12018-12-07 16:38:23 +010052
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