Mercurial > vim
diff src/testdir/test_filter_map.vim @ 22844:36fc73078bce v8.2.1969
patch 8.2.1969: Vim9: map() may change the list or dict item type
Commit: https://github.com/vim/vim/commit/ea696852e7abcdebaf7f17a7f23dc90df1f5e2ed
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Nov 9 18:31:39 2020 +0100
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().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 09 Nov 2020 18:45:04 +0100 |
parents | f140b9036aa5 |
children | 77f181975381 |
line wrap: on
line diff
--- a/src/testdir/test_filter_map.vim +++ b/src/testdir/test_filter_map.vim @@ -118,4 +118,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