summaryrefslogtreecommitdiff
path: root/src/testdir/test_execute_func.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-07-09 17:07:29 +0200
committerBram Moolenaar <Bram@vim.org>2016-07-09 17:07:29 +0200
commit79815f1ec77406f2f21a618c053e5793b597db7a (patch)
tree7a99af24de8d373cc9a12408b39a57118a6577b9 /src/testdir/test_execute_func.vim
parentfc4ad616073a169badfb2b9906fee2844f76f730 (diff)
downloadvim-git-79815f1ec77406f2f21a618c053e5793b597db7a.tar.gz
patch 7.4.2008v7.4.2008
Problem: evalcmd() has a confusing name. Solution: Rename to execute(). Make silent optional. Support a list of commands.
Diffstat (limited to 'src/testdir/test_execute_func.vim')
-rw-r--r--src/testdir/test_execute_func.vim51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/testdir/test_execute_func.vim b/src/testdir/test_execute_func.vim
new file mode 100644
index 000000000..dd07e4a62
--- /dev/null
+++ b/src/testdir/test_execute_func.vim
@@ -0,0 +1,51 @@
+" test execute()
+
+func NestedEval()
+ let nested = execute('echo "nested\nlines"')
+ echo 'got: "' . nested . '"'
+endfunc
+
+func NestedRedir()
+ redir => var
+ echo 'broken'
+ redir END
+endfunc
+
+func Test_execute_string()
+ call assert_equal("\nnocompatible", execute('set compatible?'))
+ call assert_equal("\nsomething\nnice", execute('echo "something\nnice"'))
+ call assert_equal("noendofline", execute('echon "noendofline"'))
+ call assert_equal("", execute(123))
+
+ call assert_equal("\ngot: \"\nnested\nlines\"", execute('call NestedEval()'))
+ redir => redired
+ echo 'this'
+ let evaled = execute('echo "that"')
+ echo 'theend'
+ redir END
+ call assert_equal("\nthis\ntheend", redired)
+ call assert_equal("\nthat", evaled)
+
+ call assert_fails('call execute("doesnotexist")', 'E492:')
+ call assert_fails('call execute(3.4)', 'E806:')
+ call assert_fails('call execute("call NestedRedir()")', 'E930:')
+
+ call assert_equal("\nsomething", execute('echo "something"', ''))
+ call assert_equal("\nsomething", execute('echo "something"', 'silent'))
+ call assert_equal("\nsomething", execute('echo "something"', 'silent!'))
+ call assert_equal("", execute('burp', 'silent!'))
+ call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:')
+
+ call assert_equal("", execute(test_null_string()))
+endfunc
+
+func Test_execute_list()
+ call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"']))
+ let l = ['for n in range(0, 3)',
+ \ 'echo n',
+ \ 'endfor']
+ call assert_equal("\n0\n1\n2\n3", execute(l))
+
+ call assert_equal("", execute([]))
+ call assert_equal("", execute(test_null_list()))
+endfunc