diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-01-16 19:01:53 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-01-16 19:01:53 +0100 |
commit | 70250fb4d2ffc2e92db224c6374db418f70691fd (patch) | |
tree | b39c86e166ecabd7f9d9ad17d8afa47377f1bd60 /src/testdir/test_vim9_builtin.vim | |
parent | f898f7c68dc06def1a5ae02ce82a52a82af37cc4 (diff) |
patch 8.2.2365: Vim9: no check for map() changing item type at script levelv8.2.2365
Problem: Vim9: no check for map() changing item type at script level.
Solution: Check the new value type.
Diffstat (limited to 'src/testdir/test_vim9_builtin.vim')
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index 180070e0aa..61d129ec23 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -331,27 +331,6 @@ def Wrong_dict_key_type(items: list<number>): list<number> return filter(items, (_, val) => get({[val]: 1}, 'x')) enddef -def Test_map_function_arg() - var lines =<< trim END - def MapOne(i: number, v: string): string - return i .. ':' .. v - enddef - var l = ['a', 'b', 'c'] - map(l, MapOne) - assert_equal(['0:a', '1:b', '2:c'], l) - END - 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())) @@ -584,6 +563,45 @@ def SID(): number ->str2nr() enddef +def Test_map_function_arg() + var lines =<< trim END + def MapOne(i: number, v: string): string + return i .. ':' .. v + enddef + var l = ['a', 'b', 'c'] + map(l, MapOne) + assert_equal(['0:a', '1:b', '2:c'], l) + END + 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) + + lines =<< trim END + var l: list<number> = [0] + echo map(l, (_, v) => []) + END + CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2) + + lines =<< trim END + var l: list<number> = range(2) + echo map(l, (_, v) => []) + END + CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2) + + lines =<< trim END + var d: dict<number> = {key: 0} + echo map(d, (_, v) => []) + END + CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2) +enddef + def Test_maparg() var lnum = str2nr(expand('<sflnum>')) map foo bar |