Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
22843:b80694c9bb40 | 22844:36fc73078bce |
---|---|
116 let d = #{a: 1, b: 2, c: 3} | 116 let d = #{a: 1, b: 2, c: 3} |
117 call assert_fails('call map(d, "remove(d, v:key)[0]")', 'E741:') | 117 call assert_fails('call map(d, "remove(d, v:key)[0]")', 'E741:') |
118 call assert_fails('echo map(d, {k,v -> remove(d, k)})', 'E741:') | 118 call assert_fails('echo map(d, {k,v -> remove(d, k)})', 'E741:') |
119 endfunc | 119 endfunc |
120 | 120 |
121 func Test_mapnew_dict() | |
122 let din = #{one: 1, two: 2} | |
123 let dout = mapnew(din, {k, v -> string(v)}) | |
124 call assert_equal(#{one: 1, two: 2}, din) | |
125 call assert_equal(#{one: '1', two: '2'}, dout) | |
126 endfunc | |
127 | |
128 func Test_mapnew_list() | |
129 let lin = [1, 2, 3] | |
130 let lout = mapnew(lin, {k, v -> string(v)}) | |
131 call assert_equal([1, 2, 3], lin) | |
132 call assert_equal(['1', '2', '3'], lout) | |
133 endfunc | |
134 | |
135 func Test_mapnew_blob() | |
136 let bin = 0z123456 | |
137 let bout = mapnew(bin, {k, v -> k == 1 ? 0x99 : v}) | |
138 call assert_equal(0z123456, bin) | |
139 call assert_equal(0z129956, bout) | |
140 endfunc | |
141 | |
121 " vim: shiftwidth=2 sts=2 expandtab | 142 " vim: shiftwidth=2 sts=2 expandtab |