Skip to content

Commit

Permalink
patch 8.2.3202: Vim9: tests are only executed for legacy script
Browse files Browse the repository at this point in the history
Problem:    Vim9: tests are only executed for legacy script.
Solution:   Run more tests also for Vim9 script.  Fix uncovered problems.
  • Loading branch information
brammool committed Jul 22, 2021
1 parent 2b59df0 commit 5dd839c
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/ex_docmd.c
Expand Up @@ -3451,7 +3451,8 @@ find_ex_command(
// "varname[]" is an expression.
*p == '['
// "varname.key" is an expression.
|| (*p == '.' && ASCII_ISALPHA(p[1]))))
|| (*p == '.' && (ASCII_ISALPHA(p[1])
|| p[1] == '_'))))
{
char_u *after = eap->cmd;

Expand Down
154 changes: 116 additions & 38 deletions src/testdir/test_listdict.vim
Expand Up @@ -109,10 +109,17 @@ func Test_list_unlet()
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:')
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
Expand All @@ -126,9 +133,33 @@ func Test_list_assign()
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:')
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
Expand Down Expand Up @@ -248,23 +279,29 @@ let s:dict_with_spaces_lit = #{one : 1 , two : 2 , three : 3}

" 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)
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 d = {'b':'bbb', '1': 99, '3': 33, '-1': {'a': 1}}
unlet d.b
unlet d[-1]
call assert_equal({'1': 99, '3': 33}, d)
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)
Expand Down Expand Up @@ -332,8 +369,30 @@ func Test_dict_assign()
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')
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
Expand All @@ -350,13 +409,41 @@ endfunc

" 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)
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:')

call assert_fails("call remove(d, 1, 2)", 'E118:')
call assert_fails("call remove(d, 'a')", 'E716:')
call assert_fails("call remove(d, [])", 'E730:')
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)
Expand All @@ -372,7 +459,7 @@ endfunc
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
" why *{} cannot be used for a literal dictionary
let blue = 'blue'
call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue')))
endfunc
Expand Down Expand Up @@ -564,15 +651,13 @@ endfunc

" 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:')
endfunc

" 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
Expand All @@ -581,7 +666,6 @@ endfunc

" 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"')
Expand All @@ -590,7 +674,6 @@ endfunc

" 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')
Expand All @@ -599,7 +682,6 @@ endfunc

" 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:')
Expand All @@ -608,7 +690,6 @@ endfunc

" 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:')
Expand Down Expand Up @@ -711,9 +792,6 @@ func Test_func_arg_list()
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]
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -755,6 +755,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3202,
/**/
3201,
/**/
Expand Down
7 changes: 7 additions & 0 deletions src/vim9execute.c
Expand Up @@ -2711,6 +2711,13 @@ exec_instructions(ectx_T *ectx)
else
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)
Expand Down

0 comments on commit 5dd839c

Please sign in to comment.