Mercurial > vim
comparison src/testdir/test_vim9_builtin.vim @ 22898:a8bccb0634bc v8.2.1996
patch 8.2.1996: Vim9: invalid error for argument of extend()
Commit: https://github.com/vim/vim/commit/193f6201b4d5c76f8dc1faa1dcf369575d93fe3a
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Nov 16 20:08:35 2020 +0100
patch 8.2.1996: Vim9: invalid error for argument of extend()
Problem: Vim9: invalid error for argument of extend().
Solution: Check if the type could match. (closes https://github.com/vim/vim/issues/7299)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 16 Nov 2020 20:15:04 +0100 |
parents | a7082e865ffd |
children | 00b0275ffe7f |
comparison
equal
deleted
inserted
replaced
22897:09b160140ca3 | 22898:a8bccb0634bc |
---|---|
193 | 193 |
194 def Test_extend_arg_types() | 194 def Test_extend_arg_types() |
195 assert_equal([1, 2, 3], extend([1, 2], [3])) | 195 assert_equal([1, 2, 3], extend([1, 2], [3])) |
196 assert_equal([3, 1, 2], extend([1, 2], [3], 0)) | 196 assert_equal([3, 1, 2], extend([1, 2], [3], 0)) |
197 assert_equal([1, 3, 2], extend([1, 2], [3], 1)) | 197 assert_equal([1, 3, 2], extend([1, 2], [3], 1)) |
198 assert_equal([1, 3, 2], extend([1, 2], [3], s:number_one)) | |
198 | 199 |
199 assert_equal(#{a: 1, b: 2, c: 3}, extend(#{a: 1, b: 2}, #{c: 3})) | 200 assert_equal(#{a: 1, b: 2, c: 3}, extend(#{a: 1, b: 2}, #{c: 3})) |
200 assert_equal(#{a: 1, b: 4}, extend(#{a: 1, b: 2}, #{b: 4})) | 201 assert_equal(#{a: 1, b: 4}, extend(#{a: 1, b: 2}, #{b: 4})) |
201 assert_equal(#{a: 1, b: 2}, extend(#{a: 1, b: 2}, #{b: 4}, 'keep')) | 202 assert_equal(#{a: 1, b: 2}, extend(#{a: 1, b: 2}, #{b: 4}, 'keep')) |
203 assert_equal(#{a: 1, b: 2}, extend(#{a: 1, b: 2}, #{b: 4}, s:string_keep)) | |
204 | |
205 var res: list<dict<any>> | |
206 extend(res, map([1, 2], {_, v -> {}})) | |
207 assert_equal([{}, {}], res) | |
202 | 208 |
203 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') | 209 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') |
204 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') | 210 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
205 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string') | 211 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string') |
206 | 212 |
336 | 342 |
337 def Test_index() | 343 def Test_index() |
338 index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3) | 344 index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3) |
339 enddef | 345 enddef |
340 | 346 |
347 let s:number_one = 1 | |
348 let s:number_two = 2 | |
349 let s:string_keep = 'keep' | |
350 | |
341 def Test_insert() | 351 def Test_insert() |
342 var l = insert([2, 1], 3) | 352 var l = insert([2, 1], 3) |
343 var res = 0 | 353 var res = 0 |
344 for n in l | 354 for n in l |
345 res += n | 355 res += n |
346 endfor | 356 endfor |
347 res->assert_equal(6) | 357 res->assert_equal(6) |
348 | 358 |
349 assert_equal([1, 2, 3], insert([2, 3], 1)) | 359 assert_equal([1, 2, 3], insert([2, 3], 1)) |
360 assert_equal([1, 2, 3], insert([2, 3], s:number_one)) | |
350 assert_equal([1, 2, 3], insert([1, 2], 3, 2)) | 361 assert_equal([1, 2, 3], insert([1, 2], 3, 2)) |
362 assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two)) | |
351 assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a')) | 363 assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a')) |
352 assert_equal(0z1234, insert(0z34, 0x12)) | 364 assert_equal(0z1234, insert(0z34, 0x12)) |
365 | |
353 CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1) | 366 CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1) |
354 CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1) | 367 CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1) |
355 enddef | 368 enddef |
356 | 369 |
357 def Test_keys_return_type() | 370 def Test_keys_return_type() |