From 8cbb2477cf70ea29105e3df17308e6d6a067c8e6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Aug 2023 09:43:00 +0800 Subject: vim-patch:8.2.1969: Vim9: map() may change the list or dict item type Problem: Vim9: map() may change the list or dict item type. Solution: Add mapnew(). https://github.com/vim/vim/commit/ea696852e7abcdebaf7f17a7f23dc90df1f5e2ed Co-authored-by: Bram Moolenaar --- test/old/testdir/test_filter_map.vim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/old/testdir/test_filter_map.vim b/test/old/testdir/test_filter_map.vim index e2216e4d68..880162c2b9 100644 --- a/test/old/testdir/test_filter_map.vim +++ b/test/old/testdir/test_filter_map.vim @@ -111,4 +111,25 @@ func Test_map_and_modify() call assert_fails('echo map(d, {k,v -> remove(d, k)})', 'E741:') endfunc +func Test_mapnew_dict() + let din = #{one: 1, two: 2} + let dout = mapnew(din, {k, v -> string(v)}) + call assert_equal(#{one: 1, two: 2}, din) + call assert_equal(#{one: '1', two: '2'}, dout) +endfunc + +func Test_mapnew_list() + let lin = [1, 2, 3] + let lout = mapnew(lin, {k, v -> string(v)}) + call assert_equal([1, 2, 3], lin) + call assert_equal(['1', '2', '3'], lout) +endfunc + +func Test_mapnew_blob() + let bin = 0z123456 + let bout = mapnew(bin, {k, v -> k == 1 ? 0x99 : v}) + call assert_equal(0z123456, bin) + call assert_equal(0z129956, bout) +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit