mirror of
https://github.com/vim/vim.git
synced 2025-10-05 05:34:07 -04:00
patch 8.1.0742: not all Blob operations are tested
Problem: Not all Blob operations are tested. Solution: Add more testing for Blob.
This commit is contained in:
@@ -1258,8 +1258,14 @@ f_add(typval_T *argvars, typval_T *rettv)
|
|||||||
&& !tv_check_lock(b->bv_lock,
|
&& !tv_check_lock(b->bv_lock,
|
||||||
(char_u *)N_("add() argument"), TRUE))
|
(char_u *)N_("add() argument"), TRUE))
|
||||||
{
|
{
|
||||||
ga_append(&b->bv_ga, (char_u)tv_get_number(&argvars[1]));
|
int error = FALSE;
|
||||||
copy_tv(&argvars[0], rettv);
|
varnumber_T n = tv_get_number_chk(&argvars[1], &error);
|
||||||
|
|
||||||
|
if (!error)
|
||||||
|
{
|
||||||
|
ga_append(&b->bv_ga, (int)n);
|
||||||
|
copy_tv(&argvars[0], rettv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -3196,7 +3202,6 @@ f_empty(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
case VAR_BLOB:
|
case VAR_BLOB:
|
||||||
n = argvars[0].vval.v_blob == NULL
|
n = argvars[0].vval.v_blob == NULL
|
||||||
|| argvars[0].vval.v_blob->bv_ga.ga_data == NULL
|
|
||||||
|| argvars[0].vval.v_blob->bv_ga.ga_len == 0;
|
|| argvars[0].vval.v_blob->bv_ga.ga_len == 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -7029,6 +7034,13 @@ f_index(typval_T *argvars, typval_T *rettv)
|
|||||||
b = argvars[0].vval.v_blob;
|
b = argvars[0].vval.v_blob;
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
return;
|
return;
|
||||||
|
if (start < 0)
|
||||||
|
{
|
||||||
|
start = blob_len(b) + start;
|
||||||
|
if (start < 0)
|
||||||
|
start = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (idx = start; idx < blob_len(b); ++idx)
|
for (idx = start; idx < blob_len(b); ++idx)
|
||||||
{
|
{
|
||||||
tv.v_type = VAR_NUMBER;
|
tv.v_type = VAR_NUMBER;
|
||||||
|
@@ -96,6 +96,8 @@ func Test_blob_compare()
|
|||||||
call assert_true(b1 != b2)
|
call assert_true(b1 != b2)
|
||||||
call assert_true(b1 != b3)
|
call assert_true(b1 != b3)
|
||||||
call assert_true(b1 == 0z0011)
|
call assert_true(b1 == 0z0011)
|
||||||
|
call assert_fails('echo b1 == 9', 'E977:')
|
||||||
|
call assert_fails('echo b1 != 9', 'E977:')
|
||||||
|
|
||||||
call assert_false(b1 is b2)
|
call assert_false(b1 is b2)
|
||||||
let b2 = b1
|
let b2 = b1
|
||||||
@@ -145,6 +147,22 @@ func Test_blob_concatenate()
|
|||||||
call assert_equal(0zDEADBEEF, b)
|
call assert_equal(0zDEADBEEF, b)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_blob_add()
|
||||||
|
let b = 0z0011
|
||||||
|
call add(b, 0x22)
|
||||||
|
call assert_equal(0z001122, b)
|
||||||
|
call add(b, '51')
|
||||||
|
call assert_equal(0z00112233, b)
|
||||||
|
|
||||||
|
call assert_fails('call add(b, [9])', 'E745:')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_blob_empty()
|
||||||
|
call assert_false(empty(0z001122))
|
||||||
|
call assert_true(empty(0z))
|
||||||
|
call assert_true(empty(test_null_blob()))
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test removing items in blob
|
" Test removing items in blob
|
||||||
func Test_blob_func_remove()
|
func Test_blob_func_remove()
|
||||||
" Test removing 1 element
|
" Test removing 1 element
|
||||||
@@ -198,11 +216,19 @@ func Test_blob_map()
|
|||||||
let b = 0zDEADBEEF
|
let b = 0zDEADBEEF
|
||||||
call map(b, 'v:val + 1')
|
call map(b, 'v:val + 1')
|
||||||
call assert_equal(0zDFAEBFF0, b)
|
call assert_equal(0zDFAEBFF0, b)
|
||||||
|
|
||||||
|
call assert_fails("call map(b, '[9]')", 'E978:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_blob_index()
|
func Test_blob_index()
|
||||||
call assert_equal(2, index(0zDEADBEEF, 0xBE))
|
call assert_equal(2, index(0zDEADBEEF, 0xBE))
|
||||||
call assert_equal(-1, index(0zDEADBEEF, 0))
|
call assert_equal(-1, index(0zDEADBEEF, 0))
|
||||||
|
call assert_equal(2, index(0z11111111, 0x11, 2))
|
||||||
|
call assert_equal(3, index(0z11110111, 0x11, 2))
|
||||||
|
call assert_equal(2, index(0z11111111, 0x11, -2))
|
||||||
|
call assert_equal(3, index(0z11110111, 0x11, -2))
|
||||||
|
|
||||||
|
call assert_fails('call index("asdf", 0)', 'E714:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_blob_insert()
|
func Test_blob_insert()
|
||||||
@@ -213,6 +239,10 @@ func Test_blob_insert()
|
|||||||
let b = 0zDEADBEEF
|
let b = 0zDEADBEEF
|
||||||
call insert(b, 0x33, 2)
|
call insert(b, 0x33, 2)
|
||||||
call assert_equal(0zDEAD33BEEF, b)
|
call assert_equal(0zDEAD33BEEF, b)
|
||||||
|
|
||||||
|
call assert_fails('call insert(b, -1)', 'E475:')
|
||||||
|
call assert_fails('call insert(b, 257)', 'E475:')
|
||||||
|
call assert_fails('call insert(b, 0, [9])', 'E745:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_blob_reverse()
|
func Test_blob_reverse()
|
||||||
|
@@ -69,3 +69,21 @@ func Test_for_invalid()
|
|||||||
call assert_fails("for x in 'asdf'", 'E714:')
|
call assert_fails("for x in 'asdf'", 'E714:')
|
||||||
call assert_fails("for x in {'a': 9}", 'E714:')
|
call assert_fails("for x in {'a': 9}", 'E714:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_readfile_binary()
|
||||||
|
new
|
||||||
|
call setline(1, ['one', 'two', 'three'])
|
||||||
|
setlocal ff=dos
|
||||||
|
write XReadfile
|
||||||
|
let lines = readfile('XReadfile')
|
||||||
|
call assert_equal(['one', 'two', 'three'], lines)
|
||||||
|
let lines = readfile('XReadfile', '', 2)
|
||||||
|
call assert_equal(['one', 'two'], lines)
|
||||||
|
let lines = readfile('XReadfile', 'b')
|
||||||
|
call assert_equal(["one\r", "two\r", "three\r", ""], lines)
|
||||||
|
let lines = readfile('XReadfile', 'b', 2)
|
||||||
|
call assert_equal(["one\r", "two\r"], lines)
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
call delete('XReadfile')
|
||||||
|
endfunc
|
||||||
|
@@ -795,6 +795,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 */
|
||||||
|
/**/
|
||||||
|
742,
|
||||||
/**/
|
/**/
|
||||||
741,
|
741,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user