mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 20:08:17 +00:00
vim-patch:8.2.0522: several errors are not tested for (#19901)
Problem: Several errors are not tested for.
Solution: Add tests. (Yegappan Lakshmanan, closes vim/vim#5892)
ee4e0c1e9a
Omit Test_range() change: reverted in patch 8.2.0615.
Cherry-pick Test_z_no_space_before_xxx() from patch 8.2.0195.
Cherry-pick Test_reverse_sort_uniq() change from patch 8.2.0183.
Make uniq() error behavior consistent with sort().
Cherry-pick Test_set_ttytype() change from patch 8.1.1826.
Cherry-pick quickfix checks from patch 8.1.2373 to test_preview.vim.
Test_viminfo_error() is applicable.
Cherry-pick E1058 from patch 8.2.0149 and port Test_deep_nest() to Lua.
This commit is contained in:
@@ -1247,15 +1247,15 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort)
|
|||||||
; li != NULL;) {
|
; li != NULL;) {
|
||||||
listitem_T *const prev_li = TV_LIST_ITEM_PREV(l, li);
|
listitem_T *const prev_li = TV_LIST_ITEM_PREV(l, li);
|
||||||
if (item_compare_func_ptr(&prev_li, &li) == 0) {
|
if (item_compare_func_ptr(&prev_li, &li) == 0) {
|
||||||
if (info.item_compare_func_err) { // -V547
|
|
||||||
emsg(_("E882: Uniq compare function failed"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
li = tv_list_item_remove(l, li);
|
li = tv_list_item_remove(l, li);
|
||||||
} else {
|
} else {
|
||||||
idx++;
|
idx++;
|
||||||
li = TV_LIST_ITEM_NEXT(l, li);
|
li = TV_LIST_ITEM_NEXT(l, li);
|
||||||
}
|
}
|
||||||
|
if (info.item_compare_func_err) {
|
||||||
|
emsg(_("E882: Uniq compare function failed"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1885,6 +1885,8 @@ theend:
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_FUNC_NESTING 50
|
||||||
|
|
||||||
/// ":function"
|
/// ":function"
|
||||||
void ex_function(exarg_T *eap)
|
void ex_function(exarg_T *eap)
|
||||||
{
|
{
|
||||||
@@ -2304,8 +2306,12 @@ void ex_function(exarg_T *eap)
|
|||||||
p += eval_fname_script((const char *)p);
|
p += eval_fname_script((const char *)p);
|
||||||
xfree(trans_function_name((char **)&p, true, 0, NULL, NULL));
|
xfree(trans_function_name((char **)&p, true, 0, NULL, NULL));
|
||||||
if (*skipwhite((char *)p) == '(') {
|
if (*skipwhite((char *)p) == '(') {
|
||||||
nesting++;
|
if (nesting == MAX_FUNC_NESTING - 1) {
|
||||||
indent += 2;
|
emsg(_("E1058: function nesting too deep"));
|
||||||
|
} else {
|
||||||
|
nesting++;
|
||||||
|
indent += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2724,6 +2724,30 @@ func Test_autocmd_FileReadCmd()
|
|||||||
delfunc ReadFileCmd
|
delfunc ReadFileCmd
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for passing invalid arguments to autocmd
|
||||||
|
func Test_autocmd_invalid_args()
|
||||||
|
" Additional character after * for event
|
||||||
|
call assert_fails('autocmd *a Xfile set ff=unix', 'E215:')
|
||||||
|
augroup Test
|
||||||
|
augroup END
|
||||||
|
" Invalid autocmd event
|
||||||
|
call assert_fails('autocmd Bufabc Xfile set ft=vim', 'E216:')
|
||||||
|
" Invalid autocmd event in a autocmd group
|
||||||
|
call assert_fails('autocmd Test Bufabc Xfile set ft=vim', 'E216:')
|
||||||
|
augroup! Test
|
||||||
|
" Execute all autocmds
|
||||||
|
call assert_fails('doautocmd * BufEnter', 'E217:')
|
||||||
|
call assert_fails('augroup! x1a2b3', 'E367:')
|
||||||
|
call assert_fails('autocmd BufNew <buffer=999> pwd', 'E680:')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test for deep nesting of autocmds
|
||||||
|
func Test_autocmd_deep_nesting()
|
||||||
|
autocmd BufEnter Xfile doautocmd BufEnter Xfile
|
||||||
|
call assert_fails('doautocmd BufEnter Xfile', 'E218:')
|
||||||
|
autocmd! BufEnter Xfile
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Tests for SigUSR1 autocmd event, which is only available on posix systems.
|
" Tests for SigUSR1 autocmd event, which is only available on posix systems.
|
||||||
func Test_autocmd_sigusr1()
|
func Test_autocmd_sigusr1()
|
||||||
CheckUnix
|
CheckUnix
|
||||||
|
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
source check.vim
|
source check.vim
|
||||||
CheckFeature job
|
CheckFeature job
|
||||||
|
|
||||||
|
if !has('clientserver')
|
||||||
|
call assert_fails('call remote_startserver("local")', 'E942:')
|
||||||
|
endif
|
||||||
|
|
||||||
CheckFeature clientserver
|
CheckFeature clientserver
|
||||||
|
|
||||||
source shared.vim
|
source shared.vim
|
||||||
@@ -179,6 +184,7 @@ func Test_client_server()
|
|||||||
|
|
||||||
call assert_fails("let x = remote_peek([])", 'E730:')
|
call assert_fails("let x = remote_peek([])", 'E730:')
|
||||||
call assert_fails("let x = remote_read('vim10')", 'E277:')
|
call assert_fails("let x = remote_read('vim10')", 'E277:')
|
||||||
|
call assert_fails("call server2client('abc', 'xyz')", 'E258:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Uncomment this line to get a debugging log
|
" Uncomment this line to get a debugging log
|
||||||
|
@@ -211,6 +211,8 @@ func Test_digraphs()
|
|||||||
call Put_Dig("00")
|
call Put_Dig("00")
|
||||||
call Put_Dig("el")
|
call Put_Dig("el")
|
||||||
call assert_equal(['␀', 'ü', '∞', 'l'], getline(line('.')-3,line('.')))
|
call assert_equal(['␀', 'ü', '∞', 'l'], getline(line('.')-3,line('.')))
|
||||||
|
call assert_fails('exe "digraph a\<Esc> 100"', 'E104:')
|
||||||
|
call assert_fails('exe "digraph \<Esc>a 100"', 'E104:')
|
||||||
call assert_fails('digraph xy z', 'E39:')
|
call assert_fails('digraph xy z', 'E39:')
|
||||||
call assert_fails('digraph x', 'E1214:')
|
call assert_fails('digraph x', 'E1214:')
|
||||||
bw!
|
bw!
|
||||||
@@ -491,6 +493,17 @@ func Test_show_digraph_cp1251()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for error in a keymap file
|
||||||
|
func Test_loadkeymap_error()
|
||||||
|
if !has('keymap')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call assert_fails('loadkeymap', 'E105:')
|
||||||
|
call writefile(['loadkeymap', 'a'], 'Xkeymap')
|
||||||
|
call assert_fails('source Xkeymap', 'E791:')
|
||||||
|
call delete('Xkeymap')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for the characters displayed on the screen when entering a digraph
|
" Test for the characters displayed on the screen when entering a digraph
|
||||||
func Test_entering_digraph()
|
func Test_entering_digraph()
|
||||||
CheckRunVimInTerminal
|
CheckRunVimInTerminal
|
||||||
|
@@ -547,6 +547,7 @@ func Test_funcref()
|
|||||||
call assert_fails('echo funcref("{")', 'E475:')
|
call assert_fails('echo funcref("{")', 'E475:')
|
||||||
let OneByRef = funcref("One", repeat(["foo"], 20))
|
let OneByRef = funcref("One", repeat(["foo"], 20))
|
||||||
call assert_fails('let OneByRef = funcref("One", repeat(["foo"], 21))', 'E118:')
|
call assert_fails('let OneByRef = funcref("One", repeat(["foo"], 21))', 'E118:')
|
||||||
|
call assert_fails('echo function("min") =~ function("min")', 'E694:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_setmatches()
|
func Test_setmatches()
|
||||||
|
@@ -731,7 +731,8 @@ func Test_1_highlight_Normalgroup_exists()
|
|||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
function Test_no_space_before_xxx()
|
" Do this test last, sometimes restoring the columns doesn't work
|
||||||
|
func Test_z_no_space_before_xxx()
|
||||||
" Note: we need to create this highlight group in the test because it does not exist in Neovim
|
" Note: we need to create this highlight group in the test because it does not exist in Neovim
|
||||||
execute('hi StatusLineTermNC ctermfg=green')
|
execute('hi StatusLineTermNC ctermfg=green')
|
||||||
let l:org_columns = &columns
|
let l:org_columns = &columns
|
||||||
@@ -739,7 +740,7 @@ function Test_no_space_before_xxx()
|
|||||||
let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
|
let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
|
||||||
call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
|
call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
|
||||||
let &columns = l:org_columns
|
let &columns = l:org_columns
|
||||||
endfunction
|
endfunc
|
||||||
|
|
||||||
" Test for :highlight command errors
|
" Test for :highlight command errors
|
||||||
func Test_highlight_cmd_errors()
|
func Test_highlight_cmd_errors()
|
||||||
|
@@ -308,3 +308,21 @@ func Test_lambda_error()
|
|||||||
" This was causing a crash
|
" This was causing a crash
|
||||||
call assert_fails('ec{@{->{d->()()', 'E15')
|
call assert_fails('ec{@{->{d->()()', 'E15')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_closure_error()
|
||||||
|
let l =<< trim END
|
||||||
|
func F1() closure
|
||||||
|
return 1
|
||||||
|
endfunc
|
||||||
|
END
|
||||||
|
call writefile(l, 'Xscript')
|
||||||
|
let caught_932 = 0
|
||||||
|
try
|
||||||
|
source Xscript
|
||||||
|
catch /E932:/
|
||||||
|
let caught_932 = 1
|
||||||
|
endtry
|
||||||
|
call assert_equal(1, caught_932)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -604,20 +604,23 @@ func Test_reverse_sort_uniq()
|
|||||||
call assert_equal(['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5], uniq(copy(l)))
|
call assert_equal(['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5], uniq(copy(l)))
|
||||||
call assert_equal([1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'], reverse(l))
|
call assert_equal([1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'], reverse(l))
|
||||||
call assert_equal([1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'], reverse(reverse(l)))
|
call assert_equal([1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'], reverse(reverse(l)))
|
||||||
call assert_equal(['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]], sort(l))
|
if has('float')
|
||||||
call assert_equal([[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0'], reverse(sort(l)))
|
call assert_equal(['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]], sort(l))
|
||||||
call assert_equal(['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]], sort(reverse(sort(l))))
|
call assert_equal([[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0'], reverse(sort(l)))
|
||||||
call assert_equal(['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]], uniq(sort(l)))
|
call assert_equal(['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]], sort(reverse(sort(l))))
|
||||||
|
call assert_equal(['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]], uniq(sort(l)))
|
||||||
|
|
||||||
let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, 0.22, 'four']
|
let l = [7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, 0.22, 'four']
|
||||||
call assert_equal([-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255], sort(copy(l), 'n'))
|
call assert_equal([-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255], sort(copy(l), 'n'))
|
||||||
|
|
||||||
let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []]
|
let l = [7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []]
|
||||||
call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 1))
|
call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 1))
|
||||||
call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 'i'))
|
call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 'i'))
|
||||||
call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l)))
|
call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l)))
|
||||||
|
endif
|
||||||
|
|
||||||
call assert_fails('call reverse("")', 'E899:')
|
call assert_fails('call reverse("")', 'E899:')
|
||||||
|
call assert_fails('call uniq([1, 2], {x, y -> []})', 'E882:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" reduce a list or a blob
|
" reduce a list or a blob
|
||||||
|
@@ -234,6 +234,7 @@ func Test_complete()
|
|||||||
new
|
new
|
||||||
call feedkeys("i\<C-N>\<Esc>", 'xt')
|
call feedkeys("i\<C-N>\<Esc>", 'xt')
|
||||||
bwipe!
|
bwipe!
|
||||||
|
call assert_fails('set complete=ix', 'E535:')
|
||||||
set complete&
|
set complete&
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
@@ -431,32 +432,37 @@ func Test_copy_context()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_set_ttytype()
|
func Test_set_ttytype()
|
||||||
" Nvim does not support 'ttytype'.
|
throw "Skipped: Nvim does not support 'ttytype'"
|
||||||
if !has('nvim') && !has('gui_running') && has('unix')
|
CheckUnix
|
||||||
" Setting 'ttytype' used to cause a double-free when exiting vim and
|
CheckNotGui
|
||||||
" when vim is compiled with -DEXITFREE.
|
|
||||||
set ttytype=ansi
|
|
||||||
call assert_equal('ansi', &ttytype)
|
|
||||||
call assert_equal(&ttytype, &term)
|
|
||||||
set ttytype=xterm
|
|
||||||
call assert_equal('xterm', &ttytype)
|
|
||||||
call assert_equal(&ttytype, &term)
|
|
||||||
try
|
|
||||||
set ttytype=
|
|
||||||
call assert_report('set ttytype= did not fail')
|
|
||||||
catch /E529/
|
|
||||||
endtry
|
|
||||||
|
|
||||||
" Some systems accept any terminal name and return dumb settings,
|
" Setting 'ttytype' used to cause a double-free when exiting vim and
|
||||||
" check for failure of finding the entry and for missing 'cm' entry.
|
" when vim is compiled with -DEXITFREE.
|
||||||
try
|
set ttytype=ansi
|
||||||
set ttytype=xxx
|
call assert_equal('ansi', &ttytype)
|
||||||
call assert_report('set ttytype=xxx did not fail')
|
call assert_equal(&ttytype, &term)
|
||||||
catch /E522\|E437/
|
set ttytype=xterm
|
||||||
endtry
|
call assert_equal('xterm', &ttytype)
|
||||||
|
call assert_equal(&ttytype, &term)
|
||||||
|
try
|
||||||
|
set ttytype=
|
||||||
|
call assert_report('set ttytype= did not fail')
|
||||||
|
catch /E529/
|
||||||
|
endtry
|
||||||
|
|
||||||
set ttytype&
|
" Some systems accept any terminal name and return dumb settings,
|
||||||
call assert_equal(&ttytype, &term)
|
" check for failure of finding the entry and for missing 'cm' entry.
|
||||||
|
try
|
||||||
|
set ttytype=xxx
|
||||||
|
call assert_report('set ttytype=xxx did not fail')
|
||||||
|
catch /E522\|E437/
|
||||||
|
endtry
|
||||||
|
|
||||||
|
set ttytype&
|
||||||
|
call assert_equal(&ttytype, &term)
|
||||||
|
|
||||||
|
if has('gui') && !has('gui_running')
|
||||||
|
call assert_fails('set term=gui', 'E531:')
|
||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
" Tests for the preview window
|
" Tests for the preview window
|
||||||
|
|
||||||
|
source check.vim
|
||||||
|
CheckFeature quickfix
|
||||||
|
|
||||||
func Test_Psearch()
|
func Test_Psearch()
|
||||||
" this used to cause ml_get errors
|
" this used to cause ml_get errors
|
||||||
help
|
help
|
||||||
@@ -13,6 +16,8 @@ func Test_Psearch()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_window_preview()
|
func Test_window_preview()
|
||||||
|
CheckFeature quickfix
|
||||||
|
|
||||||
" Open a preview window
|
" Open a preview window
|
||||||
pedit Xa
|
pedit Xa
|
||||||
call assert_equal(2, winnr('$'))
|
call assert_equal(2, winnr('$'))
|
||||||
@@ -32,6 +37,8 @@ func Test_window_preview()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_window_preview_from_help()
|
func Test_window_preview_from_help()
|
||||||
|
CheckFeature quickfix
|
||||||
|
|
||||||
filetype on
|
filetype on
|
||||||
call writefile(['/* some C code */'], 'Xpreview.c')
|
call writefile(['/* some C code */'], 'Xpreview.c')
|
||||||
help
|
help
|
||||||
|
@@ -169,3 +169,10 @@ endfunc
|
|||||||
func Test_failed_call_in_try()
|
func Test_failed_call_in_try()
|
||||||
try | call UnknownFunc() | catch | endtry
|
try | call UnknownFunc() | catch | endtry
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for listing user-defined functions
|
||||||
|
func Test_function_list()
|
||||||
|
call assert_fails("function Xabc", 'E123:')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
21
src/nvim/testdir/test_viminfo.vim
Normal file
21
src/nvim/testdir/test_viminfo.vim
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
" Test for errors in setting 'viminfo'
|
||||||
|
func Test_viminfo_option_error()
|
||||||
|
" Missing number
|
||||||
|
call assert_fails('set viminfo=\"', 'E526:')
|
||||||
|
for c in split("'/:<@s", '\zs')
|
||||||
|
call assert_fails('set viminfo=' .. c, 'E526:')
|
||||||
|
endfor
|
||||||
|
|
||||||
|
" Missing comma
|
||||||
|
call assert_fails('set viminfo=%10!', 'E527:')
|
||||||
|
call assert_fails('set viminfo=!%10', 'E527:')
|
||||||
|
call assert_fails('set viminfo=h%10', 'E527:')
|
||||||
|
call assert_fails('set viminfo=c%10', 'E527:')
|
||||||
|
call assert_fails('set viminfo=:10%10', 'E527:')
|
||||||
|
|
||||||
|
" Missing ' setting
|
||||||
|
call assert_fails('set viminfo=%10', 'E528:')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" vim: shiftwidth=2 sts=2 expandtab
|
@@ -1829,6 +1829,9 @@ func Test_missing_end()
|
|||||||
endtry
|
endtry
|
||||||
call assert_equal(1, caught_e733)
|
call assert_equal(1, caught_e733)
|
||||||
|
|
||||||
|
" Using endfunc with :if
|
||||||
|
call assert_fails('exe "if 1 | endfunc | endif"', 'E193:')
|
||||||
|
|
||||||
" Missing 'in' in a :for statement
|
" Missing 'in' in a :for statement
|
||||||
call assert_fails('for i range(1) | endfor', 'E690:')
|
call assert_fails('for i range(1) | endfor', 'E690:')
|
||||||
endfunc
|
endfunc
|
||||||
@@ -1875,6 +1878,15 @@ func Test_deep_nest()
|
|||||||
@a
|
@a
|
||||||
let @a = ''
|
let @a = ''
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Deep nesting of function ... endfunction
|
||||||
|
func Test5()
|
||||||
|
let @a = join(repeat(['function X()'], 51), "\n")
|
||||||
|
let @a ..= "\necho v:true\n"
|
||||||
|
let @a ..= join(repeat(['endfunction'], 51), "\n")
|
||||||
|
@a
|
||||||
|
let @a = ''
|
||||||
|
endfunc
|
||||||
[SCRIPT]
|
[SCRIPT]
|
||||||
call writefile(lines, 'Xscript')
|
call writefile(lines, 'Xscript')
|
||||||
|
|
||||||
@@ -1882,20 +1894,31 @@ func Test_deep_nest()
|
|||||||
|
|
||||||
" Deep nesting of if ... endif
|
" Deep nesting of if ... endif
|
||||||
call term_sendkeys(buf, ":call Test1()\n")
|
call term_sendkeys(buf, ":call Test1()\n")
|
||||||
|
call term_wait(buf)
|
||||||
call WaitForAssert({-> assert_match('^E579:', term_getline(buf, 5))})
|
call WaitForAssert({-> assert_match('^E579:', term_getline(buf, 5))})
|
||||||
|
|
||||||
" Deep nesting of for ... endfor
|
" Deep nesting of for ... endfor
|
||||||
call term_sendkeys(buf, ":call Test2()\n")
|
call term_sendkeys(buf, ":call Test2()\n")
|
||||||
|
call term_wait(buf)
|
||||||
call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
|
call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
|
||||||
|
|
||||||
" Deep nesting of while ... endwhile
|
" Deep nesting of while ... endwhile
|
||||||
call term_sendkeys(buf, ":call Test3()\n")
|
call term_sendkeys(buf, ":call Test3()\n")
|
||||||
|
call term_wait(buf)
|
||||||
call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
|
call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
|
||||||
|
|
||||||
" Deep nesting of try ... endtry
|
" Deep nesting of try ... endtry
|
||||||
call term_sendkeys(buf, ":call Test4()\n")
|
call term_sendkeys(buf, ":call Test4()\n")
|
||||||
|
call term_wait(buf)
|
||||||
call WaitForAssert({-> assert_match('^E601:', term_getline(buf, 5))})
|
call WaitForAssert({-> assert_match('^E601:', term_getline(buf, 5))})
|
||||||
|
|
||||||
|
" Deep nesting of function ... endfunction
|
||||||
|
call term_sendkeys(buf, ":call Test5()\n")
|
||||||
|
call term_wait(buf)
|
||||||
|
call WaitForAssert({-> assert_match('^E1058:', term_getline(buf, 4))})
|
||||||
|
call term_sendkeys(buf, "\<C-C>\n")
|
||||||
|
call term_wait(buf)
|
||||||
|
|
||||||
"let l = ''
|
"let l = ''
|
||||||
"for i in range(1, 6)
|
"for i in range(1, 6)
|
||||||
" let l ..= term_getline(buf, i) . "\n"
|
" let l ..= term_getline(buf, i) . "\n"
|
||||||
|
@@ -10,11 +10,13 @@
|
|||||||
-- test/functional/vimscript/functions_spec.lua
|
-- test/functional/vimscript/functions_spec.lua
|
||||||
|
|
||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
local Screen = require('test.functional.ui.screen')
|
||||||
|
|
||||||
local lfs = require('lfs')
|
local lfs = require('lfs')
|
||||||
local clear = helpers.clear
|
local clear = helpers.clear
|
||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
local exc_exec = helpers.exc_exec
|
local exc_exec = helpers.exc_exec
|
||||||
|
local exec = helpers.exec
|
||||||
local eval = helpers.eval
|
local eval = helpers.eval
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
local write_file = helpers.write_file
|
local write_file = helpers.write_file
|
||||||
@@ -144,3 +146,76 @@ describe('List support code', function()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- oldtest: Test_deep_nest()
|
||||||
|
it('Error when if/for/while/try/function is nested too deep',function()
|
||||||
|
clear()
|
||||||
|
local screen = Screen.new(80, 24)
|
||||||
|
screen:attach()
|
||||||
|
meths.set_option('laststatus', 2)
|
||||||
|
exec([[
|
||||||
|
" Deep nesting of if ... endif
|
||||||
|
func Test1()
|
||||||
|
let @a = join(repeat(['if v:true'], 51), "\n")
|
||||||
|
let @a ..= "\n"
|
||||||
|
let @a ..= join(repeat(['endif'], 51), "\n")
|
||||||
|
@a
|
||||||
|
let @a = ''
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Deep nesting of for ... endfor
|
||||||
|
func Test2()
|
||||||
|
let @a = join(repeat(['for i in [1]'], 51), "\n")
|
||||||
|
let @a ..= "\n"
|
||||||
|
let @a ..= join(repeat(['endfor'], 51), "\n")
|
||||||
|
@a
|
||||||
|
let @a = ''
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Deep nesting of while ... endwhile
|
||||||
|
func Test3()
|
||||||
|
let @a = join(repeat(['while v:true'], 51), "\n")
|
||||||
|
let @a ..= "\n"
|
||||||
|
let @a ..= join(repeat(['endwhile'], 51), "\n")
|
||||||
|
@a
|
||||||
|
let @a = ''
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Deep nesting of try ... endtry
|
||||||
|
func Test4()
|
||||||
|
let @a = join(repeat(['try'], 51), "\n")
|
||||||
|
let @a ..= "\necho v:true\n"
|
||||||
|
let @a ..= join(repeat(['endtry'], 51), "\n")
|
||||||
|
@a
|
||||||
|
let @a = ''
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Deep nesting of function ... endfunction
|
||||||
|
func Test5()
|
||||||
|
let @a = join(repeat(['function X()'], 51), "\n")
|
||||||
|
let @a ..= "\necho v:true\n"
|
||||||
|
let @a ..= join(repeat(['endfunction'], 51), "\n")
|
||||||
|
@a
|
||||||
|
let @a = ''
|
||||||
|
endfunc
|
||||||
|
]])
|
||||||
|
screen:expect({any = '%[No Name%]'})
|
||||||
|
feed(':call Test1()<CR>')
|
||||||
|
screen:expect({any = 'E579: '})
|
||||||
|
feed('<C-C>')
|
||||||
|
screen:expect({any = '%[No Name%]'})
|
||||||
|
feed(':call Test2()<CR>')
|
||||||
|
screen:expect({any = 'E585: '})
|
||||||
|
feed('<C-C>')
|
||||||
|
screen:expect({any = '%[No Name%]'})
|
||||||
|
feed(':call Test3()<CR>')
|
||||||
|
screen:expect({any = 'E585: '})
|
||||||
|
feed('<C-C>')
|
||||||
|
screen:expect({any = '%[No Name%]'})
|
||||||
|
feed(':call Test4()<CR>')
|
||||||
|
screen:expect({any = 'E601: '})
|
||||||
|
feed('<C-C>')
|
||||||
|
screen:expect({any = '%[No Name%]'})
|
||||||
|
feed(':call Test5()<CR>')
|
||||||
|
screen:expect({any = 'E1058: '})
|
||||||
|
end)
|
||||||
|
@@ -455,24 +455,24 @@ describe('confirm()', function()
|
|||||||
meths.set_option('more', false) -- Avoid hit-enter prompt
|
meths.set_option('more', false) -- Avoid hit-enter prompt
|
||||||
meths.set_option('laststatus', 2)
|
meths.set_option('laststatus', 2)
|
||||||
-- screen:expect() calls are needed to avoid feeding input too early
|
-- screen:expect() calls are needed to avoid feeding input too early
|
||||||
screen:expect({any = 'No Name'})
|
screen:expect({any = '%[No Name%]'})
|
||||||
|
|
||||||
async_meths.command([[let a = confirm('Press O to proceed')]])
|
async_meths.command([[let a = confirm('Press O to proceed')]])
|
||||||
screen:expect({any = '{CONFIRM:.+: }'})
|
screen:expect({any = '{CONFIRM:.+: }'})
|
||||||
feed('o')
|
feed('o')
|
||||||
screen:expect({any = 'No Name'})
|
screen:expect({any = '%[No Name%]'})
|
||||||
eq(1, meths.get_var('a'))
|
eq(1, meths.get_var('a'))
|
||||||
|
|
||||||
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
|
async_meths.command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]])
|
||||||
screen:expect({any = '{CONFIRM:.+: }'})
|
screen:expect({any = '{CONFIRM:.+: }'})
|
||||||
feed('y')
|
feed('y')
|
||||||
screen:expect({any = 'No Name'})
|
screen:expect({any = '%[No Name%]'})
|
||||||
eq(1, meths.get_var('a'))
|
eq(1, meths.get_var('a'))
|
||||||
|
|
||||||
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
|
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
|
||||||
screen:expect({any = '{CONFIRM:.+: }'})
|
screen:expect({any = '{CONFIRM:.+: }'})
|
||||||
feed('n')
|
feed('n')
|
||||||
screen:expect({any = 'No Name'})
|
screen:expect({any = '%[No Name%]'})
|
||||||
eq(2, meths.get_var('a'))
|
eq(2, meths.get_var('a'))
|
||||||
|
|
||||||
-- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim.
|
-- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim.
|
||||||
@@ -481,26 +481,26 @@ describe('confirm()', function()
|
|||||||
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
|
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
|
||||||
screen:expect({any = '{CONFIRM:.+: }'})
|
screen:expect({any = '{CONFIRM:.+: }'})
|
||||||
feed('<Esc>')
|
feed('<Esc>')
|
||||||
screen:expect({any = 'No Name'})
|
screen:expect({any = '%[No Name%]'})
|
||||||
eq(0, meths.get_var('a'))
|
eq(0, meths.get_var('a'))
|
||||||
|
|
||||||
-- Default choice is returned when pressing <CR>.
|
-- Default choice is returned when pressing <CR>.
|
||||||
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
|
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
|
||||||
screen:expect({any = '{CONFIRM:.+: }'})
|
screen:expect({any = '{CONFIRM:.+: }'})
|
||||||
feed('<CR>')
|
feed('<CR>')
|
||||||
screen:expect({any = 'No Name'})
|
screen:expect({any = '%[No Name%]'})
|
||||||
eq(1, meths.get_var('a'))
|
eq(1, meths.get_var('a'))
|
||||||
|
|
||||||
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]])
|
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]])
|
||||||
screen:expect({any = '{CONFIRM:.+: }'})
|
screen:expect({any = '{CONFIRM:.+: }'})
|
||||||
feed('<CR>')
|
feed('<CR>')
|
||||||
screen:expect({any = 'No Name'})
|
screen:expect({any = '%[No Name%]'})
|
||||||
eq(2, meths.get_var('a'))
|
eq(2, meths.get_var('a'))
|
||||||
|
|
||||||
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]])
|
async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]])
|
||||||
screen:expect({any = '{CONFIRM:.+: }'})
|
screen:expect({any = '{CONFIRM:.+: }'})
|
||||||
feed('<CR>')
|
feed('<CR>')
|
||||||
screen:expect({any = 'No Name'})
|
screen:expect({any = '%[No Name%]'})
|
||||||
eq(0, meths.get_var('a'))
|
eq(0, meths.get_var('a'))
|
||||||
|
|
||||||
-- Test with the {type} 4th argument
|
-- Test with the {type} 4th argument
|
||||||
@@ -508,7 +508,7 @@ describe('confirm()', function()
|
|||||||
async_meths.command(([[let a = confirm('Are you sure?', "&Yes\n&No", 1, '%s')]]):format(type))
|
async_meths.command(([[let a = confirm('Are you sure?', "&Yes\n&No", 1, '%s')]]):format(type))
|
||||||
screen:expect({any = '{CONFIRM:.+: }'})
|
screen:expect({any = '{CONFIRM:.+: }'})
|
||||||
feed('y')
|
feed('y')
|
||||||
screen:expect({any = 'No Name'})
|
screen:expect({any = '%[No Name%]'})
|
||||||
eq(1, meths.get_var('a'))
|
eq(1, meths.get_var('a'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user