Mercurial > vim
diff src/testdir/test_vim9_assign.vim @ 24357:108a6e2497f6 v8.2.2719
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Commit: https://github.com/vim/vim/commit/e42939af87be3adad8c08ceb454e3a31114d7165
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Apr 5 17:11:17 2021 +0200
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Problem: Vim9: appending to dict item doesn't work in a :def function.
Solution: Implement assignment with operator on indexed item.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 05 Apr 2021 17:15:06 +0200 |
parents | cd9f77409393 |
children | 1a145eb83a28 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -1116,7 +1116,6 @@ enddef def Test_assign_dict_with_op() var lines =<< trim END - vim9script var ds: dict<string> = {a: 'x'} ds['a'] ..= 'y' ds.a ..= 'z' @@ -1148,8 +1147,46 @@ def Test_assign_dict_with_op() dn.a %= 6 assert_equal(2, dn.a) END - # TODO: this should also work with a :def function - CheckScriptSuccess(lines) + CheckDefAndScriptSuccess(lines) +enddef + +def Test_assign_list_with_op() + var lines =<< trim END + var ls: list<string> = ['x'] + ls[0] ..= 'y' + assert_equal('xy', ls[0]) + + var ln: list<number> = [9] + ln[0] += 2 + assert_equal(11, ln[0]) + + ln[0] -= 3 + assert_equal(8, ln[0]) + + ln[0] *= 2 + assert_equal(16, ln[0]) + + ln[0] /= 3 + assert_equal(5, ln[0]) + + ln[0] %= 3 + assert_equal(2, ln[0]) + END + CheckDefAndScriptSuccess(lines) +enddef + +def Test_assign_with_op_fails() + var lines =<< trim END + var s = 'abc' + s[1] += 'x' + END + CheckDefAndScriptFailure2(lines, 'E1141:', 'E689:', 2) + + lines =<< trim END + var s = 'abc' + s[1] ..= 'x' + END + CheckDefAndScriptFailure2(lines, 'E1141:', 'E689:', 2) enddef def Test_assign_lambda()