Mercurial > vim
diff src/testdir/test_vim9_builtin.vim @ 23646:5d77a7587927 v8.2.2365
patch 8.2.2365: Vim9: no check for map() changing item type at script level
Commit: https://github.com/vim/vim/commit/70250fb4d2ffc2e92db224c6374db418f70691fd
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 16 19:01:53 2021 +0100
patch 8.2.2365: Vim9: no check for map() changing item type at script level
Problem: Vim9: no check for map() changing item type at script level.
Solution: Check the new value type.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 16 Jan 2021 19:15:04 +0100 |
parents | 8dcb2255ff9a |
children | 1974c5122506 |
line wrap: on
line diff
--- 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<numb 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