Skip to content

Commit

Permalink
patch 8.2.2881: various pieces of code not covered by tests
Browse files Browse the repository at this point in the history
Problem:    Various pieces of code not covered by tests.
Solution:   Add a few more tests. (Yegappan Lakshmanan, closes #8245)
  • Loading branch information
yegappan authored and brammool committed May 24, 2021
1 parent ad5c178 commit 611728f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/testdir/test_const.vim
Expand Up @@ -223,8 +223,28 @@ func Test_lockvar()
call add(val, 4)
call assert_equal([9, 2, 3, 4], val)
call assert_fails('let val = [4, 5, 6]', 'E1122:')
endfunc

let l =<< trim END
let d = {}
lockvar d
func d.fn()
return 1
endfunc
END
let @a = l->join("\n")
call assert_fails('exe @a', 'E741:')

let l =<< trim END
let d = {}
let d.fn = function("min")
lockvar d.fn
func! d.fn()
return 1
endfunc
END
let @a = l->join("\n")
call assert_fails('exe @a', 'E741:')
endfunc

func Test_const_with_index_access()
let l = [1, 2, 3]
Expand Down
4 changes: 4 additions & 0 deletions src/testdir/test_functions.vim
Expand Up @@ -1843,6 +1843,10 @@ func Test_func_exists_on_reload()
call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists2')
call assert_fails('source Xfuncexists2', 'E122:')

" Defining a new function from the cmdline should fail if the function is
" already defined
call assert_fails('call feedkeys(":func ExistingFunction()\<CR>", "xt")', 'E122:')

delfunc ExistingFunction
call assert_equal(0, exists('*ExistingFunction'))
call writefile([
Expand Down
2 changes: 2 additions & 0 deletions src/testdir/test_python2.vim
Expand Up @@ -314,6 +314,8 @@ func Test_python_window()
10new
py vim.current.window.height = 5
call assert_equal(5, winheight(0))
py vim.current.window.height = 3.2
call assert_equal(3, winheight(0))

" Test for setting the window width
10vnew
Expand Down
2 changes: 2 additions & 0 deletions src/testdir/test_python3.vim
Expand Up @@ -511,6 +511,8 @@ func Test_python3_window()
10new
py3 vim.current.window.height = 5
call assert_equal(5, winheight(0))
py3 vim.current.window.height = 3.2
call assert_equal(3, winheight(0))

" Test for setting the window width
10vnew
Expand Down
9 changes: 8 additions & 1 deletion src/testdir/test_user_func.vim
Expand Up @@ -405,6 +405,7 @@ func Test_func_def_error()
let l = join(lines, "\n") . "\n"
exe l
call assert_fails('exe l', 'E717:')
call assert_fails('call feedkeys(":func d.F1()\<CR>", "xt")', 'E717:')

" Define an autoload function with an incorrect file name
call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript')
Expand All @@ -420,6 +421,11 @@ func Test_del_func()
call assert_fails('delfunction Xabc', 'E130:')
let d = {'a' : 10}
call assert_fails('delfunc d.a', 'E718:')
func d.fn()
return 1
endfunc
delfunc d.fn
call assert_equal({'a' : 10}, d)
endfunc

" Test for calling return outside of a function
Expand Down Expand Up @@ -451,11 +457,12 @@ func Test_func_dict()
return len(self)
endfunc

call assert_equal("{'a': 'b', 'somefunc': function('2')}", string(mydict))
call assert_equal("{'a': 'b', 'somefunc': function('3')}", string(mydict))
call assert_equal(2, mydict.somefunc())
call assert_match("^\n function \\d\\\+() dict"
\ .. "\n1 return len(self)"
\ .. "\n endfunction$", execute('func mydict.somefunc'))
call assert_fails('call mydict.nonexist()', 'E716:')
endfunc

func Test_func_range()
Expand Down
3 changes: 3 additions & 0 deletions src/testdir/test_vim9_expr.vim
Expand Up @@ -1941,6 +1941,9 @@ def Test_expr7_lambda()
CheckDefAndScriptFailure(["var Ref = (a)=>a + 1"], 'E1004:')
CheckDefAndScriptFailure(["var Ref = (a)=> a + 1"], 'E1004: White space required before and after ''=>'' at "=> a + 1"')
CheckDefAndScriptFailure(["var Ref = (a) =>a + 1"], 'E1004:')
CheckDefAndScriptFailure2(["var Ref = (a) =< a + 1"], 'E1001:', 'E121:')
CheckDefAndScriptFailure(["var Ref = (a: int) => a + 1"], 'E1010:')
CheckDefAndScriptFailure(["var Ref = (a): int => a + 1"], 'E1010:')

CheckDefAndScriptFailure(["filter([1, 2], (k,v) => 1)"], 'E1069:', 1)
# error is in first line of the lambda
Expand Down
7 changes: 7 additions & 0 deletions src/testdir/test_vim9_func.vim
Expand Up @@ -887,6 +887,12 @@ def Test_lambda_return_type()
END
CheckDefAndScriptFailure(lines, 'E1157:', 1)

# no space before the return type
lines =<< trim END
var Ref = (x):number => x + 1
END
CheckDefAndScriptFailure(lines, 'E1069:', 1)

# this works
for x in ['foo', 'boo']
echo FilterWithCond(x, (v) => v =~ '^b')
Expand Down Expand Up @@ -1318,6 +1324,7 @@ def Test_white_space_before_comma()
enddef
END
CheckScriptFailure(lines, 'E1068:')
call assert_fails('vim9cmd echo stridx("a" .. "b" , "a")', 'E1068:')
enddef

def Test_white_space_after_comma()
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2881,
/**/
2880,
/**/
Expand Down

0 comments on commit 611728f

Please sign in to comment.