Mercurial > vim
comparison src/testdir/test_listdict.vim @ 15762:dff66c4670b1 v8.1.0888
patch 8.1.0888: the a: dict is not immutable as documented
commit https://github.com/vim/vim/commit/31b816042fca879b11965ddd75287732563ba698
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 10 22:14:27 2019 +0100
patch 8.1.0888: the a: dict is not immutable as documented
Problem: The a: dict is not immutable as documented.
Solution: Make the a:dict immutable, add a test. (Ozaki Kiichi, Yasuhiro
Matsumoto, closes #3929)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 10 Feb 2019 22:15:05 +0100 |
parents | 391ac26c9412 |
children | d8ab4fa99341 |
comparison
equal
deleted
inserted
replaced
15761:e2d967c0caf5 | 15762:dff66c4670b1 |
---|---|
498 call assert_equal({'a': 99, 'b': 100}, d) | 498 call assert_equal({'a': 99, 'b': 100}, d) |
499 endfunc | 499 endfunc |
500 | 500 |
501 " No remove() of write-protected scope-level variable | 501 " No remove() of write-protected scope-level variable |
502 func Tfunc1(this_is_a_long_parameter_name) | 502 func Tfunc1(this_is_a_long_parameter_name) |
503 call assert_fails("call remove(a:, 'this_is_a_long_parameter_name')", 'E795') | 503 call assert_fails("call remove(a:, 'this_is_a_long_parameter_name')", 'E742') |
504 endfunc | 504 endfunc |
505 func Test_dict_scope_var_remove() | 505 func Test_dict_scope_var_remove() |
506 call Tfunc1('testval') | 506 call Tfunc1('testval') |
507 endfunc | 507 endfunc |
508 | 508 |
509 " No extend() of write-protected scope-level variable | 509 " No extend() of write-protected scope-level variable |
510 func Test_dict_scope_var_extend() | |
511 call assert_fails("call extend(a:, {'this_is_a_long_parameter_name': 1234})", 'E742') | |
512 endfunc | |
513 | |
510 func Tfunc2(this_is_a_long_parameter_name) | 514 func Tfunc2(this_is_a_long_parameter_name) |
511 call assert_fails("call extend(a:, {'this_is_a_long_parameter_name': 1234})", 'E742') | 515 call assert_fails("call extend(a:, {'this_is_a_long_parameter_name': 1234})", 'E742') |
512 endfunc | 516 endfunc |
513 func Test_dict_scope_var_extend() | 517 func Test_dict_scope_var_extend_overwrite() |
514 call Tfunc2('testval') | 518 call Tfunc2('testval') |
515 endfunc | 519 endfunc |
516 | 520 |
517 " No :unlet of variable in locked scope | 521 " No :unlet of variable in locked scope |
518 func Test_lock_var_unlet() | 522 func Test_lock_var_unlet() |
649 | 653 |
650 " Pass the same Dict to extend() with "error" | 654 " Pass the same Dict to extend() with "error" |
651 call assert_fails("call extend(d, d, 'error')", 'E737:') | 655 call assert_fails("call extend(d, d, 'error')", 'E737:') |
652 call assert_equal({'a': {'b': 'B'}}, d) | 656 call assert_equal({'a': {'b': 'B'}}, d) |
653 endfunc | 657 endfunc |
658 | |
659 func s:check_scope_dict(x, fixed) | |
660 func s:gen_cmd(cmd, x) | |
661 return substitute(a:cmd, '\<x\ze:', a:x, 'g') | |
662 endfunc | |
663 | |
664 let cmd = s:gen_cmd('let x:foo = 1', a:x) | |
665 if a:fixed | |
666 call assert_fails(cmd, 'E461') | |
667 else | |
668 exe cmd | |
669 exe s:gen_cmd('call assert_equal(1, x:foo)', a:x) | |
670 endif | |
671 | |
672 let cmd = s:gen_cmd('let x:["bar"] = 2', a:x) | |
673 if a:fixed | |
674 call assert_fails(cmd, 'E461') | |
675 else | |
676 exe cmd | |
677 exe s:gen_cmd('call assert_equal(2, x:bar)', a:x) | |
678 endif | |
679 | |
680 let cmd = s:gen_cmd('call extend(x:, {"baz": 3})', a:x) | |
681 if a:fixed | |
682 call assert_fails(cmd, 'E742') | |
683 else | |
684 exe cmd | |
685 exe s:gen_cmd('call assert_equal(3, x:baz)', a:x) | |
686 endif | |
687 | |
688 if a:fixed | |
689 if a:x ==# 'a' | |
690 call assert_fails('unlet a:x', 'E795') | |
691 call assert_fails('call remove(a:, "x")', 'E742') | |
692 elseif a:x ==# 'v' | |
693 call assert_fails('unlet v:count', 'E795') | |
694 call assert_fails('call remove(v:, "count")', 'E742') | |
695 endif | |
696 else | |
697 exe s:gen_cmd('unlet x:foo', a:x) | |
698 exe s:gen_cmd('unlet x:bar', a:x) | |
699 exe s:gen_cmd('call remove(x:, "baz")', a:x) | |
700 endif | |
701 | |
702 delfunc s:gen_cmd | |
703 endfunc | |
704 | |
705 func Test_scope_dict() | |
706 " Test for g: | |
707 call s:check_scope_dict('g', v:false) | |
708 | |
709 " Test for s: | |
710 call s:check_scope_dict('s', v:false) | |
711 | |
712 " Test for l: | |
713 call s:check_scope_dict('l', v:false) | |
714 | |
715 " Test for a: | |
716 call s:check_scope_dict('a', v:true) | |
717 | |
718 " Test for b: | |
719 call s:check_scope_dict('b', v:false) | |
720 | |
721 " Test for w: | |
722 call s:check_scope_dict('w', v:false) | |
723 | |
724 " Test for t: | |
725 call s:check_scope_dict('t', v:false) | |
726 | |
727 " Test for v: | |
728 call s:check_scope_dict('v', v:true) | |
729 endfunc |