diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-08-30 14:34:52 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-08-30 14:34:52 +0100 |
commit | 976f859763b215050a03248dbc2bb62fa5d0d059 (patch) | |
tree | 36bc5a92c8eb8cf57c0116e21c9a36679993fba4 /src/testdir | |
parent | 0e412be00f8290e0575c7f72ec080725631eff38 (diff) |
patch 9.0.0327: items() does not work on a listv9.0.0327
Problem: items() does not work on a list. (Sergey Vlasov)
Solution: Make items() work on a list. (closes #11013)
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_listdict.vim | 11 | ||||
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim index bba4e3e1e1..c87d701a36 100644 --- a/src/testdir/test_listdict.vim +++ b/src/testdir/test_listdict.vim @@ -198,6 +198,17 @@ func Test_list_range_assign() call v9.CheckDefAndScriptFailure(lines, 'E1012:', 2) endfunc +func Test_list_items() + let r = [] + let l = ['a', 'b', 'c'] + for [idx, val] in items(l) + call extend(r, [[idx, val]]) + endfor + call assert_equal([[0, 'a'], [1, 'b'], [2, 'c']], r) + + call assert_fails('call items(3)', 'E1227:') +endfunc + " Test removing items in list func Test_list_func_remove() let lines =<< trim END diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index d68ddce7aa..5eb64adefa 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -2244,10 +2244,14 @@ def Test_islocked() enddef def Test_items() - v9.CheckDefFailure(['[]->items()'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') + v9.CheckDefFailure(['"x"->items()'], 'E1013: Argument 1: type mismatch, expected list<any> but got string') assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items()) assert_equal([], {}->items()) assert_equal(['x', 'x'], {'a': 10, 'b': 20}->items()->map((_, _) => 'x')) + + assert_equal([[0, 'a'], [1, 'b']], ['a', 'b']->items()) + assert_equal([], []->items()) + assert_equal([], test_null_list()->items()) enddef def Test_job_getchannel() |