diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-08-17 11:47:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 11:47:40 +0800 |
commit | 8861f2af72481b1759a6935afa6dce2aae512359 (patch) | |
tree | 292843cc0ce14205b328fec6b75c1ad9a0ad7c9b /test | |
parent | 22d9338afceae5f8ef3845f152dea07a19d512d1 (diff) | |
parent | 3117dc70f1e60569f5c3cc0eee5f5005081722b5 (diff) | |
download | rneovim-8861f2af72481b1759a6935afa6dce2aae512359.tar.gz rneovim-8861f2af72481b1759a6935afa6dce2aae512359.tar.bz2 rneovim-8861f2af72481b1759a6935afa6dce2aae512359.zip |
Merge pull request #24747 from zeertzjq/vim-8.2.1969
vim-patch:8.2.{1969,1971,2075}: mapnew()
Diffstat (limited to 'test')
-rw-r--r-- | test/old/testdir/test_filter_map.vim | 27 | ||||
-rw-r--r-- | test/old/testdir/vim9.vim | 4 |
2 files changed, 29 insertions, 2 deletions
diff --git a/test/old/testdir/test_filter_map.vim b/test/old/testdir/test_filter_map.vim index e2216e4d68..b11ab93143 100644 --- a/test/old/testdir/test_filter_map.vim +++ b/test/old/testdir/test_filter_map.vim @@ -111,4 +111,31 @@ 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) + + const dconst = #{one: 1, two: 2, three: 3} + call assert_equal(#{one: 2, two: 3, three: 4}, mapnew(dconst, {_, v -> v + 1})) +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) + + const lconst = [1, 2, 3] + call assert_equal([2, 3, 4], mapnew(lconst, {_, v -> v + 1})) +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 diff --git a/test/old/testdir/vim9.vim b/test/old/testdir/vim9.vim index 1b436d7b3c..825f01c9d6 100644 --- a/test/old/testdir/vim9.vim +++ b/test/old/testdir/vim9.vim @@ -88,7 +88,7 @@ endfunc " Execute "lines" in a legacy function, translated as in " CheckLegacyAndVim9Success() func CheckTransLegacySuccess(lines) - let legacylines = a:lines->deepcopy()->map({_, v -> + let legacylines = a:lines->mapnew({_, v -> \ v->substitute('\<VAR\>', 'let', 'g') \ ->substitute('\<LET\>', 'let', 'g') \ ->substitute('\<LSTART\>', '{', 'g') @@ -131,7 +131,7 @@ func CheckLegacyAndVim9Failure(lines, error) let legacyError = a:error[0] endif - let legacylines = a:lines->deepcopy()->map({_, v -> + let legacylines = a:lines->mapnew({_, v -> \ v->substitute('\<VAR\>', 'let', 'g') \ ->substitute('\<LET\>', 'let', 'g') \ ->substitute('#"', ' "', 'g') |