1
0
forked from aniani/vim

patch 8.2.2886: various pieces of code not covered by tests

Problem:    Various pieces of code not covered by tests.
Solution:   Add a few more tests. (Yegappan Lakshmanan, closes #8255)
This commit is contained in:
Yegappan Lakshmanan
2021-05-25 20:14:00 +02:00
committed by Bram Moolenaar
parent 872bee557e
commit 34fcb69724
9 changed files with 53 additions and 0 deletions

View File

@@ -127,6 +127,7 @@ func Test_getreg_empty_list()
let y = x let y = x
call add(x, 'foo') call add(x, 'foo')
call assert_equal(['foo'], y) call assert_equal(['foo'], y)
call assert_fails('call getreg([])', 'E730:')
endfunc endfunc
func Test_loop_over_null_list() func Test_loop_over_null_list()

View File

@@ -141,6 +141,7 @@ func Test_min()
call assert_fails('call min(1)', 'E712:') call assert_fails('call min(1)', 'E712:')
call assert_fails('call min(v:none)', 'E712:') call assert_fails('call min(v:none)', 'E712:')
call assert_fails('call min([1, {}])', 'E728:')
" check we only get one error " check we only get one error
call assert_fails('call min([[1], #{}])', ['E745:', 'E745:']) call assert_fails('call min([[1], #{}])', ['E745:', 'E745:'])
@@ -715,6 +716,7 @@ func Test_tr()
call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:') call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:')
call assert_equal('hEllO', tr('hello', 'eo', 'EO')) call assert_equal('hEllO', tr('hello', 'eo', 'EO'))
call assert_equal('hello', tr('hello', 'xy', 'ab')) call assert_equal('hello', tr('hello', 'xy', 'ab'))
call assert_fails('call tr("abc", "123", "₁₂")', 'E475:')
set encoding=utf8 set encoding=utf8
endfunc endfunc
@@ -2674,4 +2676,9 @@ func Test_default_arg_value()
call assert_equal('msg', HasDefault()) call assert_equal('msg', HasDefault())
endfunc endfunc
" Test for gettext()
func Test_gettext()
call assert_fails('call gettext(1)', 'E475:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -513,6 +513,11 @@ func Test_list_locked_var_unlet()
call assert_equal(expected[depth][u][1], ps) call assert_equal(expected[depth][u][1], ps)
endfor endfor
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 endfunc
" Locked variables and :unlet or list / dict functions " Locked variables and :unlet or list / dict functions

View File

@@ -281,6 +281,7 @@ endfunc
func Test_set_register() func Test_set_register()
call assert_fails("call setreg('#', 200)", 'E86:') call assert_fails("call setreg('#', 200)", 'E86:')
call assert_fails("call setreg('a', test_unknown())", 'E908:')
edit Xfile_alt_1 edit Xfile_alt_1
let b1 = bufnr('') let b1 = bufnr('')
@@ -470,6 +471,14 @@ func Test_get_reginfo()
let info = getreginfo('"') let info = getreginfo('"')
call assert_equal('z', info.points_to) 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! bwipe!
endfunc endfunc

View File

@@ -160,6 +160,16 @@ func Test_default_arg()
\ .. "1 return deepcopy(a:)\n" \ .. "1 return deepcopy(a:)\n"
\ .. " endfunction", \ .. " endfunction",
\ execute('func Args2')) \ 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 endfunc
func s:addFoo(lead) func s:addFoo(lead)

View File

@@ -363,6 +363,7 @@ def Test_extend_arg_types()
END END
CheckDefAndScriptSuccess(lines) 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], 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], ["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') CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
@@ -726,6 +727,12 @@ def Test_insert()
endfor endfor
res->assert_equal(6) 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 var lines =<< trim END
insert(test_null_list(), 123) insert(test_null_list(), 123)
END END
@@ -743,6 +750,7 @@ def Test_insert()
assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a')) assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
assert_equal(0z1234, insert(0z34, 0x12)) 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], "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) CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1)
enddef enddef

View File

@@ -1580,6 +1580,8 @@ def Test_expr7t()
var ln: list<number> = [<number>g:anint, <number>g:thefour] var ln: list<number> = [<number>g:anint, <number>g:thefour]
var nr = <number>234 var nr = <number>234
assert_equal(234, nr) assert_equal(234, nr)
var b: bool = <bool>1
assert_equal(true, b)
var text = var text =
<string> <string>
'text' 'text'
@@ -1591,6 +1593,7 @@ def Test_expr7t()
CheckDefAndScriptFailure(["var x = <nr>123"], 'E1010:', 1) CheckDefAndScriptFailure(["var x = <nr>123"], 'E1010:', 1)
CheckDefFailure(["var x = <number>"], 'E1097:', 3) CheckDefFailure(["var x = <number>"], 'E1097:', 3)
CheckDefFailure(["var x = <number>string(1)"], 'E1012:', 1)
CheckScriptFailure(['vim9script', "var x = <number>"], 'E15:', 2) CheckScriptFailure(['vim9script', "var x = <number>"], 'E15:', 2)
CheckDefAndScriptFailure(["var x = <number >123"], 'E1068:', 1) CheckDefAndScriptFailure(["var x = <number >123"], 'E1068:', 1)
CheckDefAndScriptFailure(["var x = <number 123"], 'E1104:', 1) CheckDefAndScriptFailure(["var x = <number 123"], 'E1104:', 1)

View File

@@ -397,6 +397,7 @@ def Test_call_default_args()
delfunc g:Func delfunc g:Func
CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string') CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string')
delfunc g:Func delfunc g:Func
CheckDefFailure(['def Func(x: number = )', 'enddef'], 'E15:')
lines =<< trim END lines =<< trim END
vim9script vim9script
@@ -1315,6 +1316,8 @@ def Test_arg_type_wrong()
CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...') CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...')
CheckScriptFailure(['def Func5(items:string)', 'echo "a"'], 'E1069:') CheckScriptFailure(['def Func5(items:string)', 'echo "a"'], 'E1069:')
CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:') 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 enddef
def Test_white_space_before_comma() def Test_white_space_before_comma()
@@ -2717,6 +2720,11 @@ def Test_ignored_argument()
var _ = 1 var _ = 1
END END
CheckDefAndScriptFailure(lines, 'E1181:', 1) CheckDefAndScriptFailure(lines, 'E1181:', 1)
lines =<< trim END
var x = _
END
CheckDefAndScriptFailure(lines, 'E1181:', 1)
enddef enddef
def Test_too_many_arguments() def Test_too_many_arguments()

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2886,
/**/ /**/
2885, 2885,
/**/ /**/