summaryrefslogtreecommitdiff
path: root/src/testdir/test_vim9_script.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-12-01 16:30:44 +0100
committerBram Moolenaar <Bram@vim.org>2020-12-01 16:30:44 +0100
commit4b8a065145bb53762b869cd6b8e55b7ad7341761 (patch)
tree1f6c24ef8a54f067d9fc77aa7651e155e5899f48 /src/testdir/test_vim9_script.vim
parent004d9b00ba600a167746ad7af88e0baa77c95d8f (diff)
downloadvim-git-4b8a065145bb53762b869cd6b8e55b7ad7341761.tar.gz
patch 8.2.2073: Vim9: for with unpack only works for local variablesv8.2.2073
Problem: Vim9: for with unpack only works for local variables. Solution: Recognize different destinations.
Diffstat (limited to 'src/testdir/test_vim9_script.vim')
-rw-r--r--src/testdir/test_vim9_script.vim55
1 files changed, 41 insertions, 14 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index a99560f4f..b58e566ca 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1863,22 +1863,49 @@ def Test_for_loop_fails()
enddef
def Test_for_loop_unpack()
- var result = []
- for [v1, v2] in [[1, 2], [3, 4]]
- result->add(v1)
- result->add(v2)
- endfor
- assert_equal([1, 2, 3, 4], result)
+ var lines =<< trim END
+ var result = []
+ for [v1, v2] in [[1, 2], [3, 4]]
+ result->add(v1)
+ result->add(v2)
+ endfor
+ assert_equal([1, 2, 3, 4], result)
- result = []
- for [v1, v2; v3] in [[1, 2], [3, 4, 5, 6]]
- result->add(v1)
- result->add(v2)
- result->add(v3)
- endfor
- assert_equal([1, 2, [], 3, 4, [5, 6]], result)
+ result = []
+ for [v1, v2; v3] in [[1, 2], [3, 4, 5, 6]]
+ result->add(v1)
+ result->add(v2)
+ result->add(v3)
+ endfor
+ assert_equal([1, 2, [], 3, 4, [5, 6]], result)
- var lines =<< trim END
+ result = []
+ for [&ts, &sw] in [[1, 2], [3, 4]]
+ result->add(&ts)
+ result->add(&sw)
+ endfor
+ assert_equal([1, 2, 3, 4], result)
+
+ var slist: list<string>
+ for [$LOOPVAR, @r, v:errmsg] in [['a', 'b', 'c'], ['d', 'e', 'f']]
+ slist->add($LOOPVAR)
+ slist->add(@r)
+ slist->add(v:errmsg)
+ endfor
+ assert_equal(['a', 'b', 'c', 'd', 'e', 'f'], slist)
+
+ slist = []
+ for [g:globalvar, b:bufvar, w:winvar, t:tabvar] in [['global', 'buf', 'win', 'tab'], ['1', '2', '3', '4']]
+ slist->add(g:globalvar)
+ slist->add(b:bufvar)
+ slist->add(w:winvar)
+ slist->add(t:tabvar)
+ endfor
+ assert_equal(['global', 'buf', 'win', 'tab', '1', '2', '3', '4'], slist)
+ END
+ CheckDefAndScriptSuccess(lines)
+
+ lines =<< trim END
for [v1, v2] in [[1, 2, 3], [3, 4]]
echo v1 v2
endfor