Problem: Crash with null partial and blob.
Solution: Check for NULL pointer. Add more tests. (Yegappan Lakshmanan,
closes #5984)
{
if (pt->pt_name != NULL)
return pt->pt_name;
- return pt->pt_func->uf_name;
+ if (pt->pt_func != NULL)
+ return pt->pt_func->uf_name;
+ return (char_u *)"";
}
static void
int val, len;
char_u *p;
+ if (argvars[0].vval.v_blob == NULL)
+ return;
+
len = blob_len(argvars[0].vval.v_blob);
if (argvars[2].v_type != VAR_UNKNOWN)
{
call assert_fails('let b = 0z.')
call assert_fails('let b = 0z001122.')
call assert_fails('call get("", 1)', 'E896:')
+ call assert_equal(0, len(test_null_blob()))
endfunc
" assignment to a blob
call assert_equal(999, get(b, 5, 999))
call assert_equal(-1, get(b, -8))
call assert_equal(999, get(b, -8, 999))
+ call assert_equal(10, get(test_null_blob(), 2, 10))
call assert_equal(0x00, b[0])
call assert_equal(0x22, b[2])
call assert_equal('0z00112233', string(b))
call remove(b, 0, 3)
call assert_equal('0z', string(b))
+ call assert_equal('0z', string(test_null_blob()))
endfunc
func Test_blob_compare()
call assert_fails("call remove(b, 3, 2)", 'E979:')
call assert_fails("call remove(1, 0)", 'E896:')
call assert_fails("call remove(b, b)", 'E974:')
+ call assert_fails("call remove(test_null_blob(), 1, 2)", 'E979:')
endfunc
func Test_blob_read_write()
call assert_fails('call insert(b, 0, -20)', 'E475:')
call assert_fails('call insert(b, 0, 20)', 'E475:')
call assert_fails('call insert(b, [])', 'E745:')
+ call assert_equal(0, insert(test_null_blob(), 0x33))
endfunc
func Test_blob_reverse()
call assert_equal(0zBEADDE, reverse(0zDEADBE))
call assert_equal(0zADDE, reverse(0zDEAD))
call assert_equal(0zDE, reverse(0zDE))
+ call assert_equal(0z, reverse(test_null_blob()))
endfunc
func Test_blob_json_encode()
sign undefine Mark
enew!
endif
+ call assert_notequal([], getbufinfo(test_null_dict()))
only
let w1_id = win_getid()
call assert_equal("", d)
" Should not crash
call chdir(d)
+ call assert_equal('', chdir([]))
only | tabonly
call chdir(topdir)
call assert_equal("run", job_status(job))
call assert_equal('channel fail', string(job_getchannel(job)))
call assert_equal('fail', ch_status(job))
+ call assert_equal('no process', string(test_null_job()))
+ call assert_equal('channel fail', string(test_null_channel()))
call job_stop(job)
endfunc
let d.a = function('string', [d])
try
let d.b = ch_open('nowhere:123', {'close_cb': d.a})
+ call test_garbagecollect_now()
catch
call assert_exception('E901:')
endtry
endif
let g:Ch_close_ret = ''
call ch_setoptions(handle, {'close_cb': {ch -> execute("let g:Ch_close_ret = 'closed'")}})
+ call test_garbagecollect_now()
call assert_equal('', ch_evalexpr(handle, 'close me'))
call WaitForAssert({-> assert_equal('closed', g:Ch_close_ret)})
func Test_wrong_arguments()
call assert_fails('call cursor(1. 3)', 'E474:')
+ call assert_fails('call cursor(test_null_list())', 'E474:')
endfunc
func Test_move_cursor()
call assert_fails('call mkdir("Xfile", "p")', 'E739')
call delete('Xfile')
call delete('Xmkdir', 'rf')
+ call assert_equal(0, mkdir(test_null_string()))
+ call assert_fails('call mkdir([])', 'E730')
+ call assert_fails('call mkdir("abc", [], [])', 'E745')
endfunc
func Test_line_continuation()
call assert_fails('execute test_null_blob()', 'E976:')
execute test_null_string()
call assert_fails('execute test_null_partial()', 'E729:')
+ call assert_fails('execute test_unknown()', 'E908:')
if has('job')
call assert_fails('execute test_null_job()', 'E908:')
call assert_fails('execute test_null_channel()', 'E908:')
call assert_fails('echo base.method > instance.method')
call assert_equal(0, test_null_function() == function('min'))
call assert_equal(1, test_null_function() == test_null_function())
+ call assert_fails('eval 10 == test_unknown()', 'E685:')
endfunc
func Test_version()
endfor
endfunc
-func Test_set_reg_null_list()
+func Test_setreg_null_list()
call setreg('x', test_null_list())
endfunc
call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:')
call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:')
call assert_fails("let l = filter([1, 2], {})", 'E731:')
+ call assert_equal(0, filter(test_null_list(), 0))
+ call assert_equal(0, filter(test_null_dict(), 0))
call assert_equal(0, map(test_null_list(), '"> " .. v:val'))
call assert_equal(0, map(test_null_dict(), '"> " .. v:val'))
call assert_equal([1, 2, 3], filter([1, 2, 3], test_null_function()))
" :e never includes the whole filename, so "a.b":e:e:e --> "b"
call assert_equal('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e'))
call assert_equal('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e:e'))
+
+ call assert_equal('', fnamemodify(test_null_string(), test_null_string()))
endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
call assert_equal('~.f/bar', pathshorten('~.foo/bar'))
call assert_equal('.~f/bar', pathshorten('.~foo/bar'))
call assert_equal('~/f/bar', pathshorten('~/foo/bar'))
+ call assert_fails('call pathshorten([])', 'E730:')
endfunc
func Test_strpart()
call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8))
call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))
call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
+ call assert_equal(['', -1, -1], matchstrpos(test_null_list(), '\a'))
endfunc
func Test_nextnonblank_prevnonblank()
syntax off
endfunc
+" Test for the col() function
func Test_col()
new
call setline(1, 'abcdef')
call assert_equal(-2, c)
call assert_fails('call inputlist("")', 'E686:')
+ call assert_fails('call inputlist(test_null_list())', 'E686:')
endfunc
func Test_balloon_show()
call delete('XTest_echoraw')
endfunc
+" Test for echo highlighting
+func Test_echohl()
+ echohl Search
+ echo 'Vim'
+ call assert_equal('Vim', Screenline(&lines))
+ " TODO: How to check the highlight group used by echohl?
+ " ScreenAttrs() returns all zeros.
+ echohl None
+endfunc
+
" Test for the eval() function
func Test_eval()
call assert_fails("call eval('5 a')", 'E488:')
call setpos('.', sp)
normal jyl
call assert_equal('6', @")
+ call assert_equal(-1, setpos('.', test_null_list()))
+ call assert_equal(-1, setpos('.', {}))
close!
endfunc
+" Test for glob()
+func Test_glob()
+ call assert_equal('', glob(test_null_string()))
+ call assert_equal('', globpath(test_null_string(), test_null_string()))
+endfunc
+
+" Test for browse()
+func Test_browse()
+ CheckFeature browse
+ call assert_fails('call browse([], "open", "x", "a.c")', 'E745:')
+endfunc
+
+" Test for browsedir()
+func Test_browsedir()
+ CheckFeature browse
+ call assert_fails('call browsedir("open", [])', 'E730:')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
call assert_equal({'func has': 'no dict'}, get(l:F, 'dict', {'func has': 'no dict'}))
call assert_equal(0, get(l:F, 'dict'))
call assert_equal([], get(l:F, 'args'))
+ let NF = test_null_function()
+ call assert_equal('', get(NF, 'name'))
+ call assert_equal(NF, get(NF, 'func'))
+ call assert_equal(0, get(NF, 'dict'))
+ call assert_equal([], get(NF, 'args'))
endfunc
" get({partial}, {what} [, {default}]) - in test_partial.vim
call assert_true(dict4 == dict4copy)
endfunc
+" Test for extending lists and dictionaries
func Test_listdict_extend()
" Test extend() with lists
call assert_fails("let l[1.1] = 4", 'E806:')
call assert_fails("let l[:i] = [4, 5]", 'E121:')
call assert_fails("let l[:3.2] = [4, 5]", 'E806:')
+ let t = test_unknown()
+ call assert_fails("echo t[0]", 'E685:')
endfunc
" Test for a null list
call assert_equal(0, uniq(l))
call assert_fails("let k = [] + l", 'E15:')
call assert_fails("let k = l + []", 'E15:')
- call assert_equal(0, len(copy(test_null_list())))
+ call assert_equal(0, len(copy(l)))
+ call assert_equal(0, count(l, 5))
+ call assert_equal([], deepcopy(l))
+ call assert_equal(5, get(l, 2, 5))
+ call assert_equal(-1, index(l, 2, 5))
+ call assert_equal(0, insert(l, 2, -1))
+ call assert_equal(0, min(l))
+ call assert_equal(0, max(l))
+ call assert_equal(0, remove(l, 0, 2))
+ call assert_equal([], repeat(l, 2))
+ call assert_equal(0, reverse(l))
+ call assert_equal(0, sort(l))
+ call assert_equal('[]', string(l))
+ call assert_equal(0, extend(l, l, 0))
+ lockvar l
+ call assert_equal(1, islocked('l'))
+ unlockvar l
endfunc
" Test for a null dict
call assert_equal(0, values(d))
call assert_false(has_key(d, 'k'))
call assert_equal('{}', string(d))
- call assert_fails('let x = test_null_dict()[10]')
+ call assert_fails('let x = d[10]')
call assert_equal({}, {})
- call assert_equal(0, len(copy(test_null_dict())))
+ call assert_equal(0, len(copy(d)))
+ call assert_equal(0, count(d, 'k'))
+ call assert_equal({}, deepcopy(d))
+ call assert_equal(20, get(d, 'k', 20))
+ call assert_equal(0, min(d))
+ call assert_equal(0, max(d))
+ call assert_equal(0, remove(d, 'k'))
+ call assert_equal('{}', string(d))
+ call assert_equal(0, extend(d, d, 0))
+ lockvar d
+ call assert_equal(1, islocked('d'))
+ unlockvar d
endfunc
" vim: shiftwidth=2 sts=2 expandtab
echom test_null_dict()
echom test_null_blob()
echom test_null_string()
+ echom test_null_function()
echom test_null_partial()
if has('job')
echom test_null_job()
echom test_null_channel()
endif
endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
call assert_equal("function('MyFunc', {'one': 1})", string(F))
let F = function('MyFunc', ['foo'], d)
call assert_equal("function('MyFunc', ['foo'], {'one': 1})", string(F))
+ call assert_equal("function('')", string(test_null_function()))
+ call assert_equal("function('')", string(test_null_partial()))
endfunc
func Test_func_unref()
call g:Xsetlist([], 'a', {'context':246})
let d = g:Xgetlist({'context':1})
call assert_equal(246, d.context)
+ " set other Vim data types as context
+ call g:Xsetlist([], 'a', {'context' : test_null_blob()})
+ if has('channel')
+ call g:Xsetlist([], 'a', {'context' : test_null_channel()})
+ endif
+ if has('job')
+ call g:Xsetlist([], 'a', {'context' : test_null_job()})
+ endif
+ call g:Xsetlist([], 'a', {'context' : test_null_function()})
+ call g:Xsetlist([], 'a', {'context' : test_null_partial()})
+ call g:Xsetlist([], 'a', {'context' : ''})
+ call test_garbagecollect_now()
if a:cchar == 'l'
" Test for copying context across two different location lists
new | only
1tabmove
call assert_equal(2, tabpagenr())
+ call assert_fails('let t = tabpagenr("#")', 'E15:')
+ call assert_equal(0, tabpagewinnr(-1))
call assert_fails("99tabmove", 'E16:')
call assert_fails("+99tabmove", 'E16:')
call assert_fails("-99tabmove", 'E16:')
call assert_equal(v:t_bool, type(v:true))
call assert_equal(v:t_none, type(v:none))
call assert_equal(v:t_none, type(v:null))
+ call assert_equal(v:t_string, type(test_null_string()))
+ call assert_equal(v:t_func, type(test_null_function()))
+ call assert_equal(v:t_func, type(test_null_partial()))
+ call assert_equal(v:t_list, type(test_null_list()))
+ call assert_equal(v:t_dict, type(test_null_dict()))
+ if has('job')
+ call assert_equal(v:t_job, type(test_null_job()))
+ endif
+ if has('channel')
+ call assert_equal(v:t_channel, type(test_null_channel()))
+ endif
+ call assert_equal(v:t_blob, type(test_null_blob()))
call assert_fails("call type(test_void())", 'E685:')
call assert_fails("call type(test_unknown())", 'E685:')
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 634,
/**/
633,
/**/