patch 8.2.3858: Vim9: not enough tests
Problem: Vim9: not enough tests.
Solution: Add tests for :try/:catch and :redir. Add missing type check.
diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim
index 6e01d99..2d86b6b 100644
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -1558,6 +1558,23 @@
redir END
END
CheckDefFailure(lines, 'E1141:')
+
+ lines =<< trim END
+ var text: string
+ redir => text
+ echo 'hello'
+ redir > Xfile
+ redir END
+ END
+ CheckDefFailure(lines, 'E1185:')
+
+ lines =<< trim END
+ var text: number
+ redir => text
+ echo 'hello'
+ redir END
+ END
+ CheckDefFailure(lines, 'E1012:')
enddef
def Test_echo_void()
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index c9ceccf..af80935 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -611,15 +611,49 @@
# no requirement for spaces before |
try|echo 0|catch|endtry
+ # return in try with finally
+ def ReturnInTry(): number
+ var ret = 4
+ try
+ return ret
+ catch /this/
+ return -1
+ catch /that/
+ return -1
+ finally
+ # changing ret has no effect
+ ret = 7
+ endtry
+ return -2
+ enddef
+ assert_equal(4, ReturnInTry())
+
+ # return in catch with finally
+ def ReturnInCatch(): number
+ var ret = 5
+ try
+ throw 'getout'
+ return -1
+ catch /getout/
+ # ret is evaluated here
+ return ret
+ finally
+ # changing ret later has no effect
+ ret = -3
+ endtry
+ return -2
+ enddef
+ assert_equal(5, ReturnInCatch())
+
# return in finally after empty catch
def ReturnInFinally(): number
try
finally
- return 4
+ return 6
endtry
- return 2
+ return -1
enddef
- assert_equal(4, ReturnInFinally())
+ assert_equal(6, ReturnInFinally())
var lines =<< trim END
vim9script