comparison src/testdir/test_vim9_builtin.vim @ 23565:34aa2907082a v8.2.2325

patch 8.2.2325: Vim9: crash if map() changes the item type Commit: https://github.com/vim/vim/commit/75ab91ff3403e725a79ac9c7351b78e9aff71d67 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 10 22:42:50 2021 +0100 patch 8.2.2325: Vim9: crash if map() changes the item type Problem: Vim9: crash if map() changes the item type. Solution: Check that the item type is still OK. (closes https://github.com/vim/vim/issues/7652) Fix problem with mapnew() on range list.
author Bram Moolenaar <Bram@vim.org>
date Sun, 10 Jan 2021 22:45:06 +0100
parents 98185d3dd369
children 510088f8c66f
comparison
equal deleted inserted replaced
23564:469359887d3e 23565:34aa2907082a
229 assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4})) 229 assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
230 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep')) 230 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
231 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, s:string_keep)) 231 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, s:string_keep))
232 232
233 var res: list<dict<any>> 233 var res: list<dict<any>>
234 extend(res, map([1, 2], (_, v) => ({}))) 234 extend(res, mapnew([1, 2], (_, v) => ({})))
235 assert_equal([{}, {}], res) 235 assert_equal([{}, {}], res)
236 236
237 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') 237 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
238 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') 238 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
239 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string') 239 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
314 return i .. ':' .. v 314 return i .. ':' .. v
315 enddef 315 enddef
316 var l = ['a', 'b', 'c'] 316 var l = ['a', 'b', 'c']
317 map(l, MapOne) 317 map(l, MapOne)
318 assert_equal(['0:a', '1:b', '2:c'], l) 318 assert_equal(['0:a', '1:b', '2:c'], l)
319 END
320 CheckDefAndScriptSuccess(lines)
321 enddef
322
323 def Test_map_item_type()
324 var lines =<< trim END
325 var l = ['a', 'b', 'c']
326 map(l, (k, v) => k .. '/' .. v )
327 assert_equal(['0/a', '1/b', '2/c'], l)
319 END 328 END
320 CheckDefAndScriptSuccess(lines) 329 CheckDefAndScriptSuccess(lines)
321 enddef 330 enddef
322 331
323 def Test_filereadable() 332 def Test_filereadable()
726 strchars("A\u20dd", true)->assert_equal(1) 735 strchars("A\u20dd", true)->assert_equal(1)
727 enddef 736 enddef
728 737
729 def Test_submatch() 738 def Test_submatch()
730 var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)' 739 var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)'
731 var Rep = () => range(10)->map((_, v) => submatch(v, true))->string() 740 var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string()
732 var actual = substitute('A123456789', pat, Rep, '') 741 var actual = substitute('A123456789', pat, Rep, '')
733 var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]" 742 var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]"
734 actual->assert_equal(expected) 743 actual->assert_equal(expected)
735 enddef 744 enddef
736 745