Patch 8.2.3202

6 views
Skip to first unread message

Bram Moolenaar

unread,
Jul 22, 2021, 12:49:31 PM7/22/21
to vim...@googlegroups.com

Patch 8.2.3202
Problem: Vim9: tests are only executed for legacy script.
Solution: Run more tests also for Vim9 script. Fix uncovered problems.
Files: src/vim9execute.c, src/ex_docmd.c, src/testdir/test_listdict.vim


*** ../vim-8.2.3201/src/vim9execute.c 2021-07-22 14:58:43.473967313 +0200
--- src/vim9execute.c 2021-07-22 17:00:39.945486644 +0200
***************
*** 2712,2717 ****
--- 2712,2724 ----
n2 = list_idx_of_item(l, li2);
}
if (status != FAIL
+ && tv_idx2->v_type != VAR_SPECIAL
+ && n2 < n1)
+ {
+ semsg(_(e_listidx), n2);
+ status = FAIL;
+ }
+ if (status != FAIL
&& list_unlet_range(l, li, NULL, n1,
tv_idx2->v_type != VAR_SPECIAL, n2)
== FAIL)
*** ../vim-8.2.3201/src/ex_docmd.c 2021-07-21 22:20:30.062401737 +0200
--- src/ex_docmd.c 2021-07-22 17:40:35.044861356 +0200
***************
*** 3451,3457 ****
// "varname[]" is an expression.
*p == '['
// "varname.key" is an expression.
! || (*p == '.' && ASCII_ISALPHA(p[1]))))
{
char_u *after = eap->cmd;

--- 3451,3458 ----
// "varname[]" is an expression.
*p == '['
// "varname.key" is an expression.
! || (*p == '.' && (ASCII_ISALPHA(p[1])
! || p[1] == '_'))))
{
char_u *after = eap->cmd;

*** ../vim-8.2.3201/src/testdir/test_listdict.vim 2021-07-20 22:21:54.329987712 +0200
--- src/testdir/test_listdict.vim 2021-07-22 18:39:55.493583022 +0200
***************
*** 109,118 ****
unlet l[2:3]
call assert_equal([0, 1], l)

! let l = [0, 1, 2, 3]
! call assert_fails('unlet l[2:1]', 'E684:')
! let l = [0, 1, 2, 3]
! call assert_fails('unlet l[-1:2]', 'E684:')
endfunc

" assignment to a list
--- 109,125 ----
unlet l[2:3]
call assert_equal([0, 1], l)

! let lines =<< trim END
! VAR l = [0, 1, 2, 3]
! unlet l[2 : 1]
! END
! call CheckLegacyAndVim9Failure(lines, 'E684:')
!
! let lines =<< trim END
! VAR l = [0, 1, 2, 3]
! unlet l[-1 : 2]
! END
! call CheckLegacyAndVim9Failure(lines, 'E684:')
endfunc

" assignment to a list
***************
*** 126,134 ****
END
call CheckLegacyAndVim9Success(lines)

! let l = [0, 1, 2, 3]
! call assert_fails('let [va, vb] = l', 'E687:')
! call assert_fails('let [va, vb] = l[1:1]', 'E688:')
endfunc

" test for range assign
--- 133,165 ----
END
call CheckLegacyAndVim9Success(lines)

! let lines =<< trim END
! let l = [0, 1, 2, 3]
! let [va, vb] = l
! END
! call CheckScriptFailure(lines, 'E687:')
! let lines =<< trim END
! var l = [0, 1, 2, 3]
! var va = 0
! var vb = 0
! [va, vb] = l
! END
! call CheckScriptFailure(['vim9script'] + lines, 'E687:')
! call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 4')
!
! let lines =<< trim END
! let l = [0, 1, 2, 3]
! let [va, vb] = l[1:1]
! END
! call CheckScriptFailure(lines, 'E688:')
! let lines =<< trim END
! var l = [0, 1, 2, 3]
! var va = 0
! var vb = 0
! [va, vb] = l[1 : 1]
! END
! call CheckScriptFailure(['vim9script'] + lines, 'E688:')
! call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 1')
endfunc

" test for range assign
***************
*** 248,270 ****

" Dictionary identity
func Test_dict_identity()
! let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
! let dd = d
! let dx = copy(d)
! call assert_true(d == dd)
! call assert_false(d isnot dd)
! call assert_true(d is dd)
! call assert_true(d == dx)
! call assert_false(d is dx)
! call assert_true(d isnot dx)
endfunc

" removing items with :unlet
func Test_dict_unlet()
! let d = {'b':'bbb', '1': 99, '3': 33, '-1': {'a': 1}}
! unlet d.b
! unlet d[-1]
! call assert_equal({'1': 99, '3': 33}, d)
endfunc

" manipulating a big Dictionary (hashtable.c has a border of 1000 entries)
--- 279,307 ----

" Dictionary identity
func Test_dict_identity()
! let lines =<< trim END
! VAR d = {'1': 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1}, }
! VAR dd = d
! VAR dx = copy(d)
! call assert_true(d == dd)
! call assert_false(d isnot dd)
! call assert_true(d is dd)
! call assert_true(d == dx)
! call assert_false(d is dx)
! call assert_true(d isnot dx)
! END
! call CheckLegacyAndVim9Success(lines)
endfunc

" removing items with :unlet
func Test_dict_unlet()
! let lines =<< trim END
! VAR d = {'b': 'bbb', '1': 99, '3': 33, '-1': {'a': 1}}
! unlet d.b
! unlet d[-1]
! call assert_equal({'1': 99, '3': 33}, d)
! END
! call CheckLegacyAndVim9Success(lines)
endfunc

" manipulating a big Dictionary (hashtable.c has a border of 1000 entries)
***************
*** 332,339 ****
let d._ = 2
call assert_equal({'1': 1, '_': 2}, d)

! let n = 0
! call assert_fails('let n.key = 3', 'E1203: Dot can only be used on a dictionary: n.key = 3')
endfunc

" Function in script-local List or Dict
--- 369,398 ----
let d._ = 2
call assert_equal({'1': 1, '_': 2}, d)

! let lines =<< trim END
! VAR d = {}
! LET d.a = 1
! LET d._ = 2
! call assert_equal({'a': 1, '_': 2}, d)
! END
! call CheckLegacyAndVim9Success(lines)
!
! let lines =<< trim END
! let n = 0
! let n.key = 3
! END
! call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
! let lines =<< trim END
! vim9script
! var n = 0
! n.key = 3
! END
! call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
! let lines =<< trim END
! var n = 0
! n.key = 3
! END
! call CheckDefFailure(lines, 'E1141:')
endfunc

" Function in script-local List or Dict
***************
*** 350,362 ****

" Test removing items in a dictionary
func Test_dict_func_remove()
! let d = {1:'a', 2:'b', 3:'c'}
! call assert_equal('b', remove(d, 2))
! call assert_equal({1:'a', 3:'c'}, d)
!
! call assert_fails("call remove(d, 1, 2)", 'E118:')
! call assert_fails("call remove(d, 'a')", 'E716:')
! call assert_fails("call remove(d, [])", 'E730:')
endfunc

" Nasty: remove func from Dict that's being called (works)
--- 409,449 ----

" Test removing items in a dictionary
func Test_dict_func_remove()
! let lines =<< trim END
! VAR d = {1: 'a', 2: 'b', 3: 'c'}
! call assert_equal('b', remove(d, 2))
! call assert_equal({1: 'a', 3: 'c'}, d)
! END
! call CheckLegacyAndVim9Success(lines)
!
! let lines =<< trim END
! VAR d = {1: 'a', 3: 'c'}
! call remove(d, 1, 2)
! END
! call CheckLegacyAndVim9Failure(lines, 'E118:')
!
! let lines =<< trim END
! VAR d = {1: 'a', 3: 'c'}
! call remove(d, 'a')
! END
! call CheckLegacyAndVim9Failure(lines, 'E716:')
!
! let lines =<< trim END
! let d = {1: 'a', 3: 'c'}
! call remove(d, [])
! END
! call CheckScriptFailure(lines, 'E730:')
! let lines =<< trim END
! vim9script
! var d = {1: 'a', 3: 'c'}
! call remove(d, [])
! END
! call CheckScriptFailure(lines, 'E1174: String required for argument 2')
! let lines =<< trim END
! var d = {1: 'a', 3: 'c'}
! call remove(d, [])
! END
! call CheckDefExecFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
endfunc

" Nasty: remove func from Dict that's being called (works)
***************
*** 372,378 ****
func Test_dict_literal_keys()
call assert_equal({'one': 1, 'two2': 2, '3three': 3, '44': 4}, #{one: 1, two2: 2, 3three: 3, 44: 4},)

! " why *{} cannot be used
let blue = 'blue'
call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue')))
endfunc
--- 459,465 ----
func Test_dict_literal_keys()
call assert_equal({'one': 1, 'two2': 2, '3three': 3, '44': 4}, #{one: 1, two2: 2, 3three: 3, 44: 4},)

! " why *{} cannot be used for a literal dictionary
let blue = 'blue'
call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue')))
endfunc
***************
*** 564,570 ****

" No :unlet after lock on dict:
func Test_dict_lock_unlet()
- unlet! d
let d = {'a': 99, 'b': 100}
lockvar 1 d
call assert_fails('unlet d.a', 'E741:')
--- 651,656 ----
***************
*** 572,578 ****

" unlet after lock on dict item
func Test_dict_item_lock_unlet()
- unlet! d
let d = {'a': 99, 'b': 100}
lockvar d.a
unlet d.a
--- 658,663 ----
***************
*** 581,587 ****

" filter() after lock on dict item
func Test_dict_lock_filter()
- unlet! d
let d = {'a': 99, 'b': 100}
lockvar d.a
call filter(d, 'v:key != "a"')
--- 666,671 ----
***************
*** 590,596 ****

" map() after lock on dict
func Test_dict_lock_map()
- unlet! d
let d = {'a': 99, 'b': 100}
lockvar 1 d
call map(d, 'v:val + 200')
--- 674,679 ----
***************
*** 599,605 ****

" No extend() after lock on dict item
func Test_dict_lock_extend()
- unlet! d
let d = {'a': 99, 'b': 100}
lockvar d.a
call assert_fails("call extend(d, {'a' : 123})", 'E741:')
--- 682,687 ----
***************
*** 608,614 ****

" Cannot use += with a locked dict
func Test_dict_lock_operator()
- unlet! d
let d = {}
lockvar d
call assert_fails("let d += {'k' : 10}", 'E741:')
--- 690,695 ----
***************
*** 711,719 ****
call s:arg_list_test(1, 2, [3, 4], {5: 6})
endfunc

- func Test_dict_item_locked()
- endfunc
-
" Tests for reverse(), sort(), uniq()
func Test_reverse_sort_uniq()
let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5]
--- 792,797 ----
*** ../vim-8.2.3201/src/version.c 2021-07-22 15:14:21.723834160 +0200
--- src/version.c 2021-07-22 16:50:35.762836907 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3202,
/**/

--
hundred-and-one symptoms of being an internet addict:
208. Your goals for the future are obtaining a second Gbit connection
and upgrade your NAS to all SSD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages