Skip to content

Commit

Permalink
patch 8.2.2886: 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 #8255)
  • Loading branch information
yegappan authored and brammool committed May 25, 2021
1 parent 872bee5 commit 34fcb69
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/testdir/test_expr.vim
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func Test_getreg_empty_list()
let y = x
call add(x, 'foo')
call assert_equal(['foo'], y)
call assert_fails('call getreg([])', 'E730:')
endfunc

func Test_loop_over_null_list()
Expand Down
7 changes: 7 additions & 0 deletions src/testdir/test_functions.vim
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func Test_min()

call assert_fails('call min(1)', 'E712:')
call assert_fails('call min(v:none)', 'E712:')
call assert_fails('call min([1, {}])', 'E728:')

" check we only get one error
call assert_fails('call min([[1], #{}])', ['E745:', 'E745:'])
Expand Down Expand Up @@ -715,6 +716,7 @@ func Test_tr()
call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:')
call assert_equal('hEllO', tr('hello', 'eo', 'EO'))
call assert_equal('hello', tr('hello', 'xy', 'ab'))
call assert_fails('call tr("abc", "123", "₁₂")', 'E475:')
set encoding=utf8
endfunc

Expand Down Expand Up @@ -2674,4 +2676,9 @@ func Test_default_arg_value()
call assert_equal('msg', HasDefault())
endfunc

" Test for gettext()
func Test_gettext()
call assert_fails('call gettext(1)', 'E475:')
endfunc

" vim: shiftwidth=2 sts=2 expandtab
5 changes: 5 additions & 0 deletions src/testdir/test_listdict.vim
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ func Test_list_locked_var_unlet()
call assert_equal(expected[depth][u][1], ps)
endfor
endfor
" Deleting a list range should fail if the range is locked
let l = [1, 2, 3, 4]
lockvar l[1:2]
call assert_fails('unlet l[1:2]', 'E741:')
unlet l
endfunc

" Locked variables and :unlet or list / dict functions
Expand Down
9 changes: 9 additions & 0 deletions src/testdir/test_registers.vim
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ endfunc

func Test_set_register()
call assert_fails("call setreg('#', 200)", 'E86:')
call assert_fails("call setreg('a', test_unknown())", 'E908:')

edit Xfile_alt_1
let b1 = bufnr('')
Expand Down Expand Up @@ -470,6 +471,14 @@ func Test_get_reginfo()
let info = getreginfo('"')
call assert_equal('z', info.points_to)

let @a="a1b2"
nnoremap <F2> <Cmd>let g:RegInfo = getreginfo()<CR>
exe "normal \"a\<F2>"
call assert_equal({'regcontents': ['a1b2'], 'isunnamed': v:false,
\ 'regtype': 'v'}, g:RegInfo)
nunmap <F2>
unlet g:RegInfo

bwipe!
endfunc

Expand Down
10 changes: 10 additions & 0 deletions src/testdir/test_user_func.vim
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ func Test_default_arg()
\ .. "1 return deepcopy(a:)\n"
\ .. " endfunction",
\ execute('func Args2'))

" Error in default argument expression
let l =<< trim END
func F1(x = y)
return a:x * 2
endfunc
echo F1()
END
let @a = l->join("\n")
call assert_fails("exe @a", 'E121:')
endfunc

func s:addFoo(lead)
Expand Down
8 changes: 8 additions & 0 deletions src/testdir/test_vim9_builtin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def Test_extend_arg_types()
END
CheckDefAndScriptSuccess(lines)

CheckDefFailure(['extend("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string')
CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
Expand Down Expand Up @@ -726,6 +727,12 @@ def Test_insert()
endfor
res->assert_equal(6)

var m: any = []
insert(m, 4)
call assert_equal([4], m)
extend(m, [6], 0)
call assert_equal([6, 4], m)

var lines =<< trim END
insert(test_null_list(), 123)
END
Expand All @@ -743,6 +750,7 @@ def Test_insert()
assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
assert_equal(0z1234, insert(0z34, 0x12))

CheckDefFailure(['insert("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 1)
CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1)
CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1)
enddef
Expand Down
3 changes: 3 additions & 0 deletions src/testdir/test_vim9_expr.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,8 @@ def Test_expr7t()
var ln: list<number> = [<number>g:anint, <number>g:thefour]
var nr = <number>234
assert_equal(234, nr)
var b: bool = <bool>1
assert_equal(true, b)
var text =
<string>
'text'
Expand All @@ -1591,6 +1593,7 @@ def Test_expr7t()

CheckDefAndScriptFailure(["var x = <nr>123"], 'E1010:', 1)
CheckDefFailure(["var x = <number>"], 'E1097:', 3)
CheckDefFailure(["var x = <number>string(1)"], 'E1012:', 1)
CheckScriptFailure(['vim9script', "var x = <number>"], 'E15:', 2)
CheckDefAndScriptFailure(["var x = <number >123"], 'E1068:', 1)
CheckDefAndScriptFailure(["var x = <number 123"], 'E1104:', 1)
Expand Down
8 changes: 8 additions & 0 deletions src/testdir/test_vim9_func.vim
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def Test_call_default_args()
delfunc g:Func
CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string')
delfunc g:Func
CheckDefFailure(['def Func(x: number = )', 'enddef'], 'E15:')

lines =<< trim END
vim9script
Expand Down Expand Up @@ -1315,6 +1316,8 @@ def Test_arg_type_wrong()
CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...')
CheckScriptFailure(['def Func5(items:string)', 'echo "a"'], 'E1069:')
CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:')
CheckScriptFailure(['def Func6(...x:list<number>)', 'echo "a"', 'enddef'], 'E1069:')
CheckScriptFailure(['def Func7(...x: int)', 'echo "a"', 'enddef'], 'E1010:')
enddef

def Test_white_space_before_comma()
Expand Down Expand Up @@ -2717,6 +2720,11 @@ def Test_ignored_argument()
var _ = 1
END
CheckDefAndScriptFailure(lines, 'E1181:', 1)

lines =<< trim END
var x = _
END
CheckDefAndScriptFailure(lines, 'E1181:', 1)
enddef

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

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

0 comments on commit 34fcb69

Please sign in to comment.