Problem: Insufficient testing for invalid function arguments.
Solution: Add more tests. (Yegappan Lakshmanan, closes #5988)
GetLoclist()->setloclist(winnr)
setmatches({list} [, {win}]) *setmatches()*
- Restores a list of matches saved by |getmatches() for the
- current window|. Returns 0 if successful, otherwise -1. All
+ Restores a list of matches saved by |getmatches()| for the
+ current window. Returns 0 if successful, otherwise -1. All
current matches are cleared before the list is restored. See
example for |getmatches()|.
If {win} is specified, use the window with this number or
call assert_equal(['d'], getbufline(b, 4))
call assert_equal(['e'], getbufline(b, 5))
call assert_equal([], getbufline(b, 6))
+ call assert_equal([], getbufline(b, 2, 1))
exe "bwipe! " . b
endfunc
let job = job_start(s:python . " test_channel_pipe.py",
\ {'out_io': 'buffer', 'out_name': 'pipe-err', 'err_io': 'out'})
call assert_equal("run", job_status(job))
+ let handle = job_getchannel(job)
+ call assert_equal(bufnr('pipe-err'), ch_getbufnr(handle, 'out'))
+ call assert_equal(bufnr('pipe-err'), ch_getbufnr(handle, 'err'))
try
- let handle = job_getchannel(job)
call ch_sendraw(handle, "echo line one\n")
call ch_sendraw(handle, "echoerr line two\n")
call ch_sendraw(handle, "double this\n")
let job = job_start(s:python . " test_channel_pipe.py", options)
call assert_equal("run", job_status(job))
+ if has('unix') && !a:use_name
+ call assert_equal(bufnr('%'), ch_getbufnr(job, 'in'))
+ endif
try
let handle = job_getchannel(job)
call assert_equal('one', ch_read(handle))
endif
endtry
+ call assert_fails('call remote_startserver([])', 'E730:')
call assert_fails("let x = remote_peek([])", 'E730:')
call assert_fails("let x = remote_read('vim10')", 'E277:')
call assert_fails("call server2client('abc', 'xyz')", 'E258:')
endif
eval set->setmatches()
call assert_equal(exp, getmatches())
+ call assert_fails('let m = setmatches([], [])', 'E957:')
endfunc
func Test_empty_concatenate()
call assert_equal(0, and(has('ttyout'), 0))
call assert_equal(1, has('multi_byte_encoding'))
endif
+ call assert_equal(1, has('vcon', 1))
+ call assert_equal(1, has('mouse_gpm_enabled', 1))
call assert_equal(0, has('nonexistent'))
call assert_equal(0, has('nonexistent', 1))
" Test for the inputdialog() function
func Test_inputdialog()
- CheckNotGui
-
- call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<CR>", 'xt')
- call assert_equal('xx', v)
- call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<Esc>", 'xt')
- call assert_equal('yy', v)
+ if has('gui_running')
+ call assert_fails('let v=inputdialog([], "xx")', 'E730:')
+ call assert_fails('let v=inputdialog("Q", [])', 'E730:')
+ else
+ call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<CR>", 'xt')
+ call assert_equal('xx', v)
+ call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<Esc>", 'xt')
+ call assert_equal('yy', v)
+ endif
endfunc
" Test for inputlist()
call balloon_show('hi!')
if !has('gui_running')
call balloon_show(range(3))
+ call balloon_show([])
endif
endif
endfunc
call assert_fails('let x=range(2, 8, 0)', 'E726:')
call assert_fails('let x=range(3, 1)', 'E727:')
call assert_fails('let x=range(1, 3, -2)', 'E727:')
+ call assert_fails('let x=range([])', 'E745:')
+ call assert_fails('let x=range(1, [])', 'E745:')
+ call assert_fails('let x=range(1, 4, [])', 'E745:')
endfunc
func Test_echoraw()
call listener_remove(id)
bwipe!
+
+ " Invalid arguments
+ call assert_fails('call listener_add([])', 'E921:')
+ call assert_fails('call listener_add("s:StoreListArgs", [])', 'E158:')
+ call assert_fails('call listener_flush([])', 'E158:')
endfunc
func s:StoreBufList(buf, start, end, added, list)
call assert_fails("call matchadd('Search', 'XXX', 1, 123, 1)", 'E715:')
call assert_fails("call matchadd('Error', 'XXX', 1, 3)", 'E798:')
call assert_fails("call matchadd('Error', 'XXX', 1, 0)", 'E799:')
+ call assert_fails("call matchadd('Error', 'XXX', [], 0)", 'E745:')
endfunc
func Test_matchaddpos()
call assert_fails("call matchaddpos('Error', [1], 1, 5, {'window':12345})", 'E957:')
" Why doesn't the following error have an error code E...?
call assert_fails("call matchaddpos('Error', [{}])", 'E290:')
+ call assert_equal(-1, matchaddpos('Error', test_null_list()))
+ call assert_fails("call matchaddpos('Error', [1], [], 1)", 'E745:')
endfunc
func OtherWindowCommon()
call delete('XscriptMatchCommon')
endfunc
-
" vim: shiftwidth=2 sts=2 expandtab
nmenu Test.abc <Nop>
call assert_equal('<Nop>', menu_info('Test.abc').rhs)
call assert_fails('call menu_info([])', 'E730:')
+ call assert_fails('call menu_info("", [])', 'E730:')
nunmenu Test
" Test for defining menus in different modes
\ " {'bufnr':999, 'lnum':5}])", 'E92:')
call g:Xsetlist([[1, 2,3]])
call assert_equal(0, len(g:Xgetlist()))
+ call assert_fails('call g:Xsetlist([], [])', 'E928:')
endfunc
func Test_setqflist()
call feedkeys(":\<C-R>r\<Esc>", 'xt')
call assert_equal("a\rb\r", histget(':', -1))
+ call assert_fails('let r = getreg("=", [])', 'E745:')
+ call assert_fails('let r = getreg("=", 1, [])', 'E745:')
enew!
endfunc
call assert_true(reltimestr(differs) != '0.0')
call assert_true(reltimefloat(differs) < 0.1)
call assert_true(reltimefloat(differs) > 0.0)
+
+ call assert_equal(0, reltime({}))
+ call assert_equal(0, reltime({}, {}))
endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
call delete('XTest_startinsert')
endfunc
+" Test for passing invalid arguments to terminal functions
+func Test_term_func_invalid_arg()
+ call assert_fails('let b = term_getaltscreen([])', 'E745:')
+ call assert_fails('let p = term_getansicolors([])', 'E745:')
+ call assert_fails('let a = term_getattr(1, [])', 'E730:')
+ call assert_fails('let c = term_getcursor([])', 'E745:')
+ call assert_fails('let l = term_getline([], 1)', 'E745:')
+ call assert_fails('let l = term_getscrolled([])', 'E745:')
+ call assert_fails('let s = term_getsize([])', 'E745:')
+ call assert_fails('let s = term_getstatus([])', 'E745:')
+ call assert_fails('let s = term_scrape([], 1)', 'E745:')
+ call assert_fails('call term_sendkeys([], "a")', 'E745:')
+ call assert_fails('call term_setansicolors([], [])', 'E745:')
+ call assert_fails('call term_setapi([], "")', 'E745:')
+ call assert_fails('call term_setrestore([], "")', 'E745:')
+ call assert_fails('call term_setkill([], "")', 'E745:')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
bwipe!
call prop_type_delete('test')
endfunc
+
+" Test for passing invalid arguments to prop_xxx() functions
+func Test_prop_func_invalid_args()
+ call assert_fails('call prop_clear(1, 2, [])', 'E715:')
+ call assert_fails('call prop_clear(-1, 2)', 'E16:')
+ call assert_fails('call prop_find(test_null_dict())', 'E474:')
+ call assert_fails('call prop_find({"bufnr" : []})', 'E158:')
+ call assert_fails('call prop_find({})', 'E968:')
+ call assert_fails('call prop_find({}, "x")', 'E474:')
+ call assert_fails('call prop_find({"lnum" : -2})', 'E16:')
+ call assert_fails('call prop_list(1, [])', 'E715:')
+ call assert_fails('call prop_list(-1 , {})', 'E16:')
+ call assert_fails('call prop_remove([])', 'E474:')
+ call assert_fails('call prop_remove({}, -2)', 'E16:')
+ call assert_fails('call prop_remove({})', 'E968:')
+ call assert_fails('call prop_type_add([], {})', 'E474:')
+ call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:')
+ call assert_fails("call prop_type_delete([])", 'E474:')
+ call assert_fails("call prop_type_delete('xyz', [])", 'E715:')
+ call assert_fails("call prop_type_get([])", 'E474:')
+ call assert_fails("call prop_type_get('', [])", 'E474:')
+ call assert_fails("call prop_type_list([])", 'E715:')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
call assert_equal([1, 32], win_screenpos(2))
call assert_equal([12, 1], win_screenpos(3))
call assert_equal([0, 0], win_screenpos(4))
+ call assert_fails('let l = win_screenpos([])', 'E745:')
only
endfunc
only!
bwipe!
+ call assert_fails('call winrestview(test_null_dict())', 'E474:')
endfunc
func Test_relative_cursor_position_after_move_and_resize()
call assert_fails("echo winnr('ll')", 'E15:')
call assert_fails("echo winnr('5')", 'E15:')
call assert_equal(4, winnr('0h'))
+ call assert_fails("let w = winnr([])", 'E730:')
+ call assert_equal('unknown', win_gettype(-1))
+ call assert_equal(-1, winheight(-1))
+ call assert_equal(-1, winwidth(-1))
tabnew
call assert_equal(8, tabpagewinnr(1, 'j'))
call assert_equal(view, winsaveview())
bwipe!
+ call assert_fails('call winrestview(test_null_dict())', 'E474:')
endfunc
func Test_win_splitmove()
call assert_equal(bufname(winbufnr(2)), 'b')
call assert_equal(bufname(winbufnr(3)), 'a')
call assert_equal(bufname(winbufnr(4)), 'd')
+ call assert_fails('call win_splitmove(winnr(), winnr("k"), test_null_dict())', 'E474:')
only | bd
call assert_fails('call win_splitmove(winnr(), 123)', 'E957:')
split
call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
+ call assert_fails('let w = win_getid([])', 'E745:')
+ call assert_equal(0, win_getid(-1))
+ call assert_equal(-1, win_getid(1, -1))
+
only!
endfunc
let w2 = win_getid()
call assert_equal(['leaf', w2], 2->winlayout())
tabclose
+
+ call assert_equal([], winlayout(-1))
endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
close!
enew | only
call delete('Xfile')
+
+ call writefile(test_null_list(), 'Xfile')
+ call assert_false(filereadable('Xfile'))
+ call writefile(test_null_blob(), 'Xfile')
+ call assert_false(filereadable('Xfile'))
+ call assert_fails('call writefile([], "")', 'E482:')
endfunc
func Test_write_errors()
close
call delete('Xfile')
+
+ call writefile(test_null_list(), 'Xfile')
+ call assert_false(filereadable('Xfile'))
+ call writefile(test_null_blob(), 'Xfile')
+ call assert_false(filereadable('Xfile'))
+ call assert_fails('call writefile([], "")', 'E482:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 644,
/**/
643,
/**/