diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-01-10 22:42:50 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-01-10 22:42:50 +0100 |
commit | 75ab91ff3403e725a79ac9c7351b78e9aff71d67 (patch) | |
tree | 624dae1f8aaeff2cfcd5aea7ac6aad5573835072 /src/testdir/test_vim9_builtin.vim | |
parent | 6f02b00bb0958f70bc15534e115b4c6dadff0e06 (diff) |
patch 8.2.2325: Vim9: crash if map() changes the item typev8.2.2325
Problem: Vim9: crash if map() changes the item type.
Solution: Check that the item type is still OK. (closes #7652)
Fix problem with mapnew() on range list.
Diffstat (limited to 'src/testdir/test_vim9_builtin.vim')
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index 7aef315dc8..673f0c0562 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -231,7 +231,7 @@ def Test_extend_arg_types() assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, s:string_keep)) var res: list<dict<any>> - extend(res, map([1, 2], (_, v) => ({}))) + extend(res, mapnew([1, 2], (_, v) => ({}))) assert_equal([{}, {}], res) CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') @@ -320,6 +320,15 @@ def Test_map_function_arg() CheckDefAndScriptSuccess(lines) enddef +def Test_map_item_type() + var lines =<< trim END + var l = ['a', 'b', 'c'] + map(l, (k, v) => k .. '/' .. v ) + assert_equal(['0/a', '1/b', '2/c'], l) + END + CheckDefAndScriptSuccess(lines) +enddef + def Test_filereadable() assert_false(filereadable("")) assert_false(filereadable(test_null_string())) @@ -728,7 +737,7 @@ enddef def Test_submatch() var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)' - var Rep = () => range(10)->map((_, v) => submatch(v, true))->string() + var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string() var actual = substitute('A123456789', pat, Rep, '') var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]" actual->assert_equal(expected) |