diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 02:10:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 02:10:58 +0000 |
commit | bee19c22d569e54513a9c591441c7f411811dc81 (patch) | |
tree | b990d2df9fddb8194bfe49e9205005a0d952bc1f /src/testdir/test_vim9_assign.vim | |
parent | Adding upstream version 2:9.1.0199. (diff) | |
download | vim-bee19c22d569e54513a9c591441c7f411811dc81.tar.xz vim-bee19c22d569e54513a9c591441c7f411811dc81.zip |
Adding upstream version 2:9.1.0374.upstream/2%9.1.0374
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/testdir/test_vim9_assign.vim')
-rw-r--r-- | src/testdir/test_vim9_assign.vim | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim index 4414f55..4296c37 100644 --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -1104,6 +1104,27 @@ def Test_assignment_partial() Ref(0) END v9.CheckScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got number') + + lines =<< trim END + var Fn1 = () => { + return 10 + } + assert_equal('func(): number', typename(Fn1)) + var Fn2 = () => { + return "a" + } + assert_equal('func(): string', typename(Fn2)) + var Fn3 = () => { + return {a: [1]} + } + assert_equal('func(): dict<list<number>>', typename(Fn3)) + var Fn4 = (...l: list<string>) => { + return [] + } + assert_equal('func(...list<string>): list<any>', typename(Fn4)) + END + v9.CheckSourceSuccess(['vim9script'] + lines) + v9.CheckSourceSuccess(['def Xfunc()'] + lines + ['enddef', 'defcompile']) enddef def Test_assignment_list_any_index() @@ -1997,6 +2018,31 @@ def Test_heredoc() END v9.CheckScriptSuccess(lines) + # commented out heredoc assignment without space after '#' + lines =<< trim END + vim9script + def Func() + #x =<< trim [CODE] + #[CODE] + enddef + Func() + END + v9.CheckScriptSuccess(lines) + + # heredoc start should not be recognized in string + lines =<< trim END + vim9script + def Func() + new + @" = 'bar' + ['foo', @"]->setline("]=<<"->count('=')) + assert_equal(['foo', 'bar'], getline(1, '$')) + bwipe! + enddef + Func() + END + v9.CheckScriptSuccess(lines) + v9.CheckDefFailure(['var lines =<< trim END X', 'END'], 'E488:') v9.CheckDefFailure(['var lines =<< trim END " comment', 'END'], 'E488:') @@ -2938,6 +2984,66 @@ def Test_heredoc_expr() CODE v9.CheckDefAndScriptSuccess(lines) + # Evaluate a dictionary + lines =<< trim CODE + var d1 = {'a': 10, 'b': [1, 2]} + var code =<< trim eval END + var d2 = {d1} + END + assert_equal(["var d2 = {'a': 10, 'b': [1, 2]}"], code) + CODE + v9.CheckDefAndScriptSuccess(lines) + + # Evaluate an empty dictionary + lines =<< trim CODE + var d1 = {} + var code =<< trim eval END + var d2 = {d1} + END + assert_equal(["var d2 = {}"], code) + CODE + v9.CheckDefAndScriptSuccess(lines) + + # Evaluate a null dictionary + lines =<< trim CODE + var d1 = test_null_dict() + var code =<< trim eval END + var d2 = {d1} + END + assert_equal(["var d2 = {}"], code) + CODE + v9.CheckDefAndScriptSuccess(lines) + + # Evaluate a List + lines =<< trim CODE + var l1 = ['a', 'b', 'c'] + var code =<< trim eval END + var l2 = {l1} + END + assert_equal(["var l2 = ['a', 'b', 'c']"], code) + CODE + v9.CheckDefAndScriptSuccess(lines) + + # Evaluate an empty List + lines =<< trim CODE + var l1 = [] + var code =<< trim eval END + var l2 = {l1} + END + assert_equal(["var l2 = []"], code) + CODE + v9.CheckDefAndScriptSuccess(lines) + + # Evaluate a null List + lines =<< trim CODE + var l1 = test_null_list() + var code =<< trim eval END + var l2 = {l1} + END + assert_equal(["var l2 = []"], code) + CODE + v9.CheckDefAndScriptSuccess(lines) + lines =<< trim CODE var code =<< eval trim END var s = "{$SOME_ENV_VAR}" |