Mercurial > vim
comparison src/testdir/test_listdict.vim @ 23588:510088f8c66f v8.2.2336
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Commit: https://github.com/vim/vim/commit/b0e6b513648db7035046613431a4aa9d71ef4653
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 12 20:23:40 2021 +0100
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Problem: Vim9: it is not possible to extend a dictionary with different
item types.
Solution: Add extendnew(). (closes #7666)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 12 Jan 2021 20:30:07 +0100 |
parents | 690b84a6a7ce |
children | d406858354a6 |
comparison
equal
deleted
inserted
replaced
23587:901fb2bf09d1 | 23588:510088f8c66f |
---|---|
860 call assert_fails("call extend([1, 2], 1)", 'E712:') | 860 call assert_fails("call extend([1, 2], 1)", 'E712:') |
861 call assert_fails("call extend([1, 2], {})", 'E712:') | 861 call assert_fails("call extend([1, 2], {})", 'E712:') |
862 | 862 |
863 " Extend g: dictionary with an invalid variable name | 863 " Extend g: dictionary with an invalid variable name |
864 call assert_fails("call extend(g:, {'-!' : 10})", 'E461:') | 864 call assert_fails("call extend(g:, {'-!' : 10})", 'E461:') |
865 endfunc | |
866 | |
867 func Test_listdict_extendnew() | |
868 " Test extendnew() with lists | |
869 let l = [1, 2, 3] | |
870 call assert_equal([1, 2, 3, 4, 5], extendnew(l, [4, 5])) | |
871 call assert_equal([1, 2, 3], l) | |
872 | |
873 " Test extend() with dictionaries. | |
874 let d = {'a': {'b': 'B'}} | |
875 call assert_equal({'a': {'b': 'B'}, 'c': 'cc'}, extendnew(d, {'c': 'cc'})) | |
876 call assert_equal({'a': {'b': 'B'}}, d) | |
865 endfunc | 877 endfunc |
866 | 878 |
867 func s:check_scope_dict(x, fixed) | 879 func s:check_scope_dict(x, fixed) |
868 func s:gen_cmd(cmd, x) | 880 func s:gen_cmd(cmd, x) |
869 return substitute(a:cmd, '\<x\ze:', a:x, 'g') | 881 return substitute(a:cmd, '\<x\ze:', a:x, 'g') |