summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-07-22 18:48:53 +0200
committerBram Moolenaar <Bram@vim.org>2021-07-22 18:48:53 +0200
commit5dd839ce20466eea52e59ecf86456f1ab370d2bd (patch)
treedebd1d499ef25c7d1541ea1045936c28ae30272e
parent2b59df00d80ea8d2c0fcf4f4ae9a018c1790206f (diff)
downloadvim-git-8.2.3202.tar.gz
patch 8.2.3202: Vim9: tests are only executed for legacy scriptv8.2.3202
Problem: Vim9: tests are only executed for legacy script. Solution: Run more tests also for Vim9 script. Fix uncovered problems.
-rw-r--r--src/ex_docmd.c3
-rw-r--r--src/testdir/test_listdict.vim154
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c7
4 files changed, 127 insertions, 39 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index c1d0295f4..2f1fdb604 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -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;
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim
index 32e376899..370b5c7f2 100644
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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)
@@ -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
@@ -564,7 +651,6 @@ 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:')
@@ -572,7 +658,6 @@ 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
@@ -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"')
@@ -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')
@@ -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:')
@@ -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:')
@@ -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]
diff --git a/src/version.c b/src/version.c
index 8d726e400..8eb758c0a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3202,
+/**/
3201,
/**/
3200,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 33ad788a2..16b1bdf38 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2712,6 +2712,13 @@ exec_instructions(ectx_T *ectx)
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)