Mercurial > vim
comparison src/testdir/test_vim9_builtin.vim @ 26937:7045e9308ca3 v8.2.3997
patch 8.2.3997: Vim9: not enough testing for extend() and map()
Commit: https://github.com/vim/vim/commit/10d6f18b2f9090d19dd884827c4be59a20b446bf
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 4 15:54:38 2022 +0000
patch 8.2.3997: Vim9: not enough testing for extend() and map()
Problem: Vim9: not enough testing for extend() and map().
Solution: Add more test cases. Fix uncovered problems. Remove unused type
fields.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 04 Jan 2022 17:00:04 +0100 |
parents | ccb9be1cdd71 |
children | 95f202f77cbb |
comparison
equal
deleted
inserted
replaced
26936:6b6a26145714 | 26937:7045e9308ca3 |
---|---|
977 # mix of types is OK without a declaration | 977 # mix of types is OK without a declaration |
978 | 978 |
979 var res: list<dict<any>> | 979 var res: list<dict<any>> |
980 extend(res, mapnew([1, 2], (_, v) => ({}))) | 980 extend(res, mapnew([1, 2], (_, v) => ({}))) |
981 assert_equal([{}, {}], res) | 981 assert_equal([{}, {}], res) |
982 | |
983 var dany: dict<any> = {a: 0} | |
984 dany->extend({b: 'x'}) | |
985 assert_equal({a: 0, b: 'x'}, dany) | |
982 END | 986 END |
983 CheckDefAndScriptSuccess(lines) | 987 CheckDefAndScriptSuccess(lines) |
984 | 988 |
985 lines =<< trim END | 989 lines =<< trim END |
986 assert_equal([1, 2, "x"], extend([1, 2], ["x"])) | 990 assert_equal([1, 2, "x"], extend([1, 2], ["x"])) |
2149 CheckDefAndScriptFailure(['map(test_null_channel(), "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got channel', 'E1251: List, Dictionary, Blob or String required for argument 1']) | 2153 CheckDefAndScriptFailure(['map(test_null_channel(), "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got channel', 'E1251: List, Dictionary, Blob or String required for argument 1']) |
2150 endif | 2154 endif |
2151 CheckDefAndScriptFailure(['map(1, "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1251: List, Dictionary, Blob or String required for argument 1']) | 2155 CheckDefAndScriptFailure(['map(1, "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1251: List, Dictionary, Blob or String required for argument 1']) |
2152 | 2156 |
2153 # type of dict remains dict<any> even when type of values changes | 2157 # type of dict remains dict<any> even when type of values changes |
2154 var d: dict<any> = {a: 0} | 2158 # same for list |
2155 d->map((k, v) => true) | 2159 var lines =<< trim END |
2156 d->map((k, v) => 'x') | 2160 var d: dict<any> = {a: 0} |
2161 d->map((k, v) => true) | |
2162 d->map((k, v) => 'x') | |
2163 assert_equal({a: 'x'}, d) | |
2164 | |
2165 d = {a: 0} | |
2166 g:gd = d | |
2167 map(g:gd, (k, v) => true) | |
2168 assert_equal({a: true}, g:gd) | |
2169 | |
2170 var l: list<any> = [0] | |
2171 l->map((k, v) => true) | |
2172 l->map((k, v) => 'x') | |
2173 assert_equal(['x'], l) | |
2174 | |
2175 l = [1] | |
2176 g:gl = l | |
2177 map(g:gl, (k, v) => true) | |
2178 assert_equal([true], g:gl) | |
2179 END | |
2180 CheckDefAndScriptSuccess(lines) | |
2157 enddef | 2181 enddef |
2158 | 2182 |
2159 def Test_map_failure() | 2183 def Test_map_failure() |
2160 CheckFeature job | 2184 CheckFeature job |
2161 | 2185 |
2173 e | 2197 e |
2174 END | 2198 END |
2175 CheckScriptFailure(lines, 'E1013:') | 2199 CheckScriptFailure(lines, 'E1013:') |
2176 au! BufReadPost | 2200 au! BufReadPost |
2177 delete('Xtmpfile') | 2201 delete('Xtmpfile') |
2202 | |
2203 lines =<< trim END | |
2204 var d: dict<number> = {a: 1} | |
2205 g:gd = d | |
2206 map(g:gd, (k, v) => true) | |
2207 END | |
2208 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got bool') | |
2178 enddef | 2209 enddef |
2179 | 2210 |
2180 def Test_map_function_arg() | 2211 def Test_map_function_arg() |
2181 var lines =<< trim END | 2212 var lines =<< trim END |
2182 def MapOne(i: number, v: string): string | 2213 def MapOne(i: number, v: string): string |