Compare commits

...

4 Commits

Author SHA1 Message Date
Bram Moolenaar
2a1381c305 patch 8.2.0701: Vim9 test fails without job feature
Problem:    Vim9 test fails without job feature.
Solution:   Add feature check.
2020-05-05 23:32:58 +02:00
Bram Moolenaar
40ee466c36 patch 8.2.0700: Vim9: converting error message to exception not tested
Problem:    Vim9: converting error message to exception not tested.
Solution:   Test exception from error.  Do not continue after :echoerr.
2020-05-05 22:08:26 +02:00
Bram Moolenaar
015f4267f4 patch 8.2.0699: Vim9: not all errors tested
Problem:    Vim9: not all errors tested.
Solution:   Add test for deleted function.  Bail out on first error.
2020-05-05 21:25:22 +02:00
Bram Moolenaar
f9ab52e155 patch 8.2.0698: insert mode completion not fully tested
Problem:    Insert mode completion not fully tested.
Solution:   Add a few more tests. (Yegappan Lakshmanan, closes #6041)
2020-05-05 19:57:18 +02:00
9 changed files with 209 additions and 42 deletions

View File

@@ -328,8 +328,8 @@ func Test_edit_11_indentexpr()
bw!
endfunc
" Test changing indent in replace mode
func Test_edit_12()
" Test changing indent in replace mode
new
call setline(1, ["\tabc", "\tdef"])
call cursor(2, 4)
@@ -368,15 +368,15 @@ func Test_edit_12()
call feedkeys("R\<c-t>\<c-t>", 'tnix')
call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
call assert_equal([0, 2, 2, 0], getpos('.'))
set et
set sw& et&
set sw&
" In replace mode, after hitting enter in a line with tab characters,
" pressing backspace should restore the tab characters.
%d
call setline(1, ["\t/*"])
set formatoptions=croql
call cursor(1, 3)
call feedkeys("A\<cr>\<cr>/", 'tnix')
call assert_equal(["\t/*", " *", " */"], getline(1, '$'))
set formatoptions&
setlocal autoindent backspace=2
call setline(1, "\tone\t\ttwo")
exe "normal ggRred\<CR>six" .. repeat("\<BS>", 8)
call assert_equal(["\tone\t\ttwo"], getline(1, '$'))
bw!
endfunc

View File

@@ -493,12 +493,43 @@ func Test_completefunc_error()
call setline(1, ['', 'abcd', ''])
call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:')
" Jump to a different window from the complete function
" TODO: The following test causes an ASAN failure. Once this issue is
" addressed, enable the following test.
"func! CompleteFunc(findstart, base)
" if a:findstart == 1
" return col('.') - 1
" endif
" wincmd p
" return ['a', 'b']
"endfunc
"set completefunc=CompleteFunc
"new
"call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E839:')
"close!
set completefunc&
delfunc CompleteFunc
delfunc CompleteFunc2
close!
endfunc
" Test for returning non-string values from 'completefunc'
func Test_completefunc_invalid_data()
new
func! CompleteFunc(findstart, base)
if a:findstart == 1
return col('.') - 1
endif
return [{}, '', 'moon']
endfunc
set completefunc=CompleteFunc
exe "normal i\<C-X>\<C-U>"
call assert_equal('moon', getline(1))
set completefunc&
close!
endfunc
" Test for errors in using complete() function
func Test_complete_func_error()
call assert_fails('call complete(1, ["a"])', 'E785:')
@@ -513,6 +544,7 @@ func Test_complete_func_error()
delfunc ListColors
delfunc ListMonths
call assert_fails('call complete_info({})', 'E714:')
call assert_equal([], complete_info(['items']).items)
endfunc
" Test for completing words following a completed word in a line
@@ -535,4 +567,71 @@ func Test_complete_wrapscan()
close!
endfunc
" Test for completing special characters
func Test_complete_special_chars()
new
call setline(1, 'int .*[-\^$ func float')
call feedkeys("oin\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>", 'xt')
call assert_equal('int .*[-\^$ func float', getline(2))
close!
endfunc
" Test for completion when text is wrapped across lines.
func Test_complete_across_line()
new
call setline(1, ['red green blue', 'one two three'])
setlocal textwidth=20
exe "normal 2G$a re\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
call assert_equal(['one two three red', 'green blue one'], getline(2, '$'))
close!
endfunc
" Test for using CTRL-L to add one character when completing matching
func Test_complete_add_onechar()
new
call setline(1, ['wool', 'woodwork'])
call feedkeys("Gowoo\<C-P>\<C-P>\<C-P>\<C-L>f", 'xt')
call assert_equal('woof', getline(3))
" use 'ignorecase' and backspace to erase characters from the prefix string
" and then add letters using CTRL-L
%d
set ignorecase backspace=2
setlocal complete=.
call setline(1, ['workhorse', 'workload'])
normal Go
exe "normal aWOR\<C-P>\<bs>\<bs>\<bs>\<bs>\<bs>\<bs>\<C-L>r\<C-L>\<C-L>"
call assert_equal('workh', getline(3))
set ignorecase& backspace&
close!
endfunc
" Test insert completion with 'cindent' (adjust the indent)
func Test_complete_with_cindent()
new
setlocal cindent
call setline(1, ['if (i == 1)', " j = 2;"])
exe "normal Go{\<CR>i\<C-X>\<C-L>\<C-X>\<C-L>\<CR>}"
call assert_equal(['{', "\tif (i == 1)", "\t\tj = 2;", '}'], getline(3, '$'))
%d
call setline(1, ['when while', '{', ''])
setlocal cinkeys+==while
exe "normal Giwh\<C-P> "
call assert_equal("\twhile ", getline('$'))
close!
endfunc
" Test for <CTRL-X> <CTRL-V> completion. Complete commands and functions
func Test_complete_cmdline()
new
exe "normal icaddb\<C-X>\<C-V>"
call assert_equal('caddbuffer', getline(1))
exe "normal ocall getqf\<C-X>\<C-V>"
call assert_equal('call getqflist(', getline(2))
exe "normal oabcxyz(\<C-X>\<C-V>"
call assert_equal('abcxyz(', getline(3))
close!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -975,6 +975,30 @@ func Test_whichwrap_multi_byte()
bwipe!
endfunc
" Test for automatically adding comment leaders in insert mode
func Test_threepiece_comment()
new
setlocal expandtab
call setline(1, ["\t/*"])
setlocal formatoptions=croql
call cursor(1, 3)
call feedkeys("A\<cr>\<cr>/", 'tnix')
call assert_equal(["\t/*", " *", " */"], getline(1, '$'))
" If a comment ends in a single line, then don't add it in the next line
%d
call setline(1, '/* line1 */')
call feedkeys("A\<CR>next line", 'xt')
call assert_equal(['/* line1 */', 'next line'], getline(1, '$'))
%d
" Copy the trailing indentation from the leader comment to a new line
setlocal autoindent noexpandtab
call feedkeys("a\t/*\tone\ntwo\n/", 'xt')
call assert_equal(["\t/*\tone", "\t *\ttwo", "\t */"], getline(1, '$'))
close!
endfunc
" Test for the 'f' flag in 'comments' (only the first line has the comment
" string)
func Test_firstline_comment()

View File

@@ -759,11 +759,11 @@ def Test_expr7_list()
assert_equal(g:list_mixed, [1, 'b', false])
assert_equal('b', g:list_mixed[1])
call CheckDefExecFailure("let x = g:anint[3]", 'E714:')
call CheckDefExecFailure(["let x = g:anint[3]"], 'E714:')
call CheckDefFailure(["let x = g:list_mixed[xxx]"], 'E1001:')
call CheckDefExecFailure("let x = g:list_mixed['xx']", 'E39:')
call CheckDefExecFailure(["let x = g:list_mixed['xx']"], 'E39:')
call CheckDefFailure(["let x = g:list_mixed[0"], 'E111:')
call CheckDefExecFailure("let x = g:list_empty[3]", 'E684:')
call CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:')
enddef
def Test_expr7_lambda()
@@ -792,8 +792,8 @@ def Test_expr7_dict()
call CheckDefFailure(["let x = #"], 'E1015:')
call CheckDefFailure(["let x += 1"], 'E1020:')
call CheckDefFailure(["let x = x + 1"], 'E1001:')
call CheckDefExecFailure("let x = g:anint.member", 'E715:')
call CheckDefExecFailure("let x = g:dict_empty.member", 'E716:')
call CheckDefExecFailure(["let x = g:anint.member"], 'E715:')
call CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:')
enddef
def Test_expr_member()
@@ -899,8 +899,8 @@ func Test_expr7_fails()
call CheckDefFailure(["let x = -'xx'"], "E1030:")
call CheckDefFailure(["let x = +'xx'"], "E1030:")
call CheckDefFailure(["let x = -0z12"], "E974:")
call CheckDefExecFailure("let x = -[8]", "E39:")
call CheckDefExecFailure("let x = -{'a': 1}", "E39:")
call CheckDefExecFailure(["let x = -[8]"], "E39:")
call CheckDefExecFailure(["let x = -{'a': 1}"], "E39:")
call CheckDefFailure(["let x = @"], "E1002:")
call CheckDefFailure(["let x = @<"], "E354:")
@@ -914,23 +914,23 @@ func Test_expr7_fails()
call CheckDefFailure(["let x = &notexist"], 'E113:')
call CheckDefFailure(["&grepprg = [343]"], 'E1013:')
call CheckDefExecFailure("echo s:doesnt_exist", 'E121:')
call CheckDefExecFailure("echo g:doesnt_exist", 'E121:')
call CheckDefExecFailure(["echo s:doesnt_exist"], 'E121:')
call CheckDefExecFailure(["echo g:doesnt_exist"], 'E121:')
call CheckDefFailure(["echo a:somevar"], 'E1075:')
call CheckDefFailure(["echo l:somevar"], 'E1075:')
call CheckDefFailure(["echo x:somevar"], 'E1075:')
call CheckDefExecFailure("let x = +g:astring", 'E1030:')
call CheckDefExecFailure("let x = +g:ablob", 'E974:')
call CheckDefExecFailure("let x = +g:alist", 'E745:')
call CheckDefExecFailure("let x = +g:adict", 'E728:')
call CheckDefExecFailure(["let x = +g:astring"], 'E1030:')
call CheckDefExecFailure(["let x = +g:ablob"], 'E974:')
call CheckDefExecFailure(["let x = +g:alist"], 'E745:')
call CheckDefExecFailure(["let x = +g:adict"], 'E728:')
call CheckDefFailure(["let x = ''", "let y = x.memb"], 'E715:')
call CheckDefExecFailure("[1, 2->len()", 'E492:')
call CheckDefExecFailure("#{a: 1->len()", 'E488:')
call CheckDefExecFailure("{'a': 1->len()", 'E492:')
call CheckDefExecFailure(["[1, 2->len()"], 'E492:')
call CheckDefExecFailure(["#{a: 1->len()"], 'E488:')
call CheckDefExecFailure(["{'a': 1->len()"], 'E492:')
endfunc
let g:Funcrefs = [function('add')]
@@ -986,7 +986,7 @@ func Test_expr_fails()
call CheckDefFailure(["let x = '1'is2"], 'E488:')
call CheckDefFailure(["let x = '1'isnot2"], 'E488:')
call CheckDefExecFailure("CallMe ('yes')", 'E492:')
call CheckDefExecFailure(["CallMe ('yes')"], 'E492:')
call CheckDefFailure(["CallMe2('yes','no')"], 'E1069:')
call CheckDefFailure(["CallMe2('yes' , 'no')"], 'E1068:')

View File

@@ -642,6 +642,23 @@ func Test_E1056_1059()
call assert_equal(1, caught_1059)
endfunc
func DelMe()
echo 'DelMe'
endfunc
def Test_deleted_function()
CheckDefExecFailure([
'let RefMe: func = function("g:DelMe")',
'delfunc g:DelMe',
'echo RefMe()'], 'E117:')
enddef
def Test_unknown_function()
CheckDefExecFailure([
'let Ref: func = function("NotExist")',
'delfunc g:NotExist'], 'E700:')
enddef
def RefFunc(Ref: func(string): string): string
return Ref('more')
enddef

View File

@@ -466,6 +466,22 @@ def Test_try_catch_fails()
call CheckDefFailure(['throw xxx'], 'E1001:')
enddef
if has('channel')
let someJob = test_null_job()
def FuncWithError()
echomsg g:someJob
enddef
func Test_convert_emsg_to_exception()
try
call FuncWithError()
catch
call assert_match('Vim:E908:', v:exception)
endtry
endfunc
endif
let s:export_script_lines =<< trim END
vim9script
let name: string = 'bob'
@@ -1058,7 +1074,11 @@ def Test_echomsg_cmd()
enddef
def Test_echoerr_cmd()
# TODO: write this test
try
echoerr 'something' 'wrong' # comment
catch
assert_match('something wrong', v:exception)
endtry
enddef
def Test_for_outside_of_function()

View File

@@ -7,6 +7,14 @@ func CheckDefFailure(lines, error)
call delete('Xdef')
endfunc
" Check that "lines" inside ":def" results in an "error" message when executed.
func CheckDefExecFailure(lines, error)
call writefile(['def Func()'] + a:lines + ['enddef'], 'Xdef')
so Xdef
call assert_fails('call Func()', a:error, a:lines)
call delete('Xdef')
endfunc
def CheckScriptFailure(lines: list<string>, error: string)
writefile(lines, 'Xdef')
assert_fails('so Xdef', error, lines)
@@ -18,11 +26,3 @@ def CheckScriptSuccess(lines: list<string>)
so Xdef
delete('Xdef')
enddef
" Check that "line" inside ":def" results in an "error" message when executed.
func CheckDefExecFailure(line, error)
call writefile(['def! Func()', a:line, 'enddef'], 'Xdef')
so Xdef
call assert_fails('call Func()', a:error, a:line)
call delete('Xdef')
endfunc

View File

@@ -746,6 +746,14 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
701,
/**/
700,
/**/
699,
/**/
698,
/**/
697,
/**/

View File

@@ -432,6 +432,7 @@ call_bfunc(int func_idx, int argcount, ectx_T *ectx)
{
typval_T argvars[MAX_FUNC_ARGS];
int idx;
int called_emsg_before = called_emsg;
if (call_prepare(argcount, argvars, ectx) == FAIL)
return FAIL;
@@ -442,6 +443,9 @@ call_bfunc(int func_idx, int argcount, ectx_T *ectx)
// Clear the arguments.
for (idx = 0; idx < argcount; ++idx)
clear_tv(&argvars[idx]);
if (called_emsg != called_emsg_before)
return FAIL;
return OK;
}
@@ -549,7 +553,8 @@ call_partial(typval_T *tv, int argcount, ectx_T *ectx)
if (name == NULL || call_by_name(name, argcount, ectx, NULL) == FAIL)
{
if (called_emsg == called_emsg_before)
semsg(_(e_unknownfunc), name);
semsg(_(e_unknownfunc),
name == NULL ? (char_u *)"[unknown]" : name);
return FAIL;
}
return OK;
@@ -893,14 +898,8 @@ call_def_function(
}
else
{
int save_did_emsg = did_emsg;
SOURCING_LNUM = iptr->isn_lnum;
emsg(ga.ga_data);
if (!force_abort)
// We don't want to abort following
// commands, restore did_emsg.
did_emsg = save_did_emsg;
}
}
}