aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2020-11-24 21:37:52 +0000
committerSean Dewar <seandewar@users.noreply.github.com>2021-09-15 21:53:38 +0100
commitd346ac536fbb7716e6a0d0f5ca7af9c39ec95de0 (patch)
tree566855950bd233db27f33f4518fb2f6ed19fa2f0 /src
parent7200454ee6f500bb851bea992707c019d9982cb9 (diff)
downloadrneovim-d346ac536fbb7716e6a0d0f5ca7af9c39ec95de0.tar.gz
rneovim-d346ac536fbb7716e6a0d0f5ca7af9c39ec95de0.tar.bz2
rneovim-d346ac536fbb7716e6a0d0f5ca7af9c39ec95de0.zip
vim-patch:8.1.0742: not all Blob operations are tested
Problem: Not all Blob operations are tested. Solution: Add more testing for Blob. https://github.com/vim/vim/commit/05500ece6282407f9f7227aaf564e24147326863 Test_readfile_binary is already ported.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval/funcs.c15
-rw-r--r--src/nvim/testdir/test_blob.vim30
2 files changed, 43 insertions, 2 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index dbb00da911..3c25d76866 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -325,8 +325,13 @@ static void f_add(typval_T *argvars, typval_T *rettv, FunPtr fptr)
blob_T *const b = argvars[0].vval.v_blob;
if (b != NULL
&& !var_check_lock(b->bv_lock, N_("add() argument"), TV_TRANSLATE)) {
- ga_append(&b->bv_ga, (char_u)tv_get_number(&argvars[1]));
- tv_copy(&argvars[0], rettv);
+ bool error = false;
+ const varnumber_T n = tv_get_number_chk(&argvars[1], &error);
+
+ if (!error) {
+ ga_append(&b->bv_ga, (int)n);
+ tv_copy(&argvars[0], rettv);
+ }
}
} else {
EMSG(_(e_listreq));
@@ -4827,6 +4832,12 @@ static void f_index(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (b == NULL) {
return;
}
+ if (start < 0) {
+ start = tv_blob_len(b) + start;
+ if (start < 0) {
+ start = 0;
+ }
+ }
for (idx = start; idx < tv_blob_len(b); idx++) {
typval_T tv;
tv.v_type = VAR_NUMBER;
diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim
index df8efbb149..87448e4fba 100644
--- a/src/nvim/testdir/test_blob.vim
+++ b/src/nvim/testdir/test_blob.vim
@@ -96,6 +96,8 @@ func Test_blob_compare()
call assert_true(b1 != b2)
call assert_true(b1 != b3)
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)
let b2 = b1
@@ -145,6 +147,22 @@ func Test_blob_concatenate()
call assert_equal(0zDEADBEEF, b)
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(v:_null_blob))
+endfunc
+
" Test removing items in blob
func Test_blob_func_remove()
" Test removing 1 element
@@ -198,11 +216,19 @@ func Test_blob_map()
let b = 0zDEADBEEF
call map(b, 'v:val + 1')
call assert_equal(0zDFAEBFF0, b)
+
+ call assert_fails("call map(b, '[9]')", 'E978:')
endfunc
func Test_blob_index()
call assert_equal(2, index(0zDEADBEEF, 0xBE))
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
func Test_blob_insert()
@@ -213,6 +239,10 @@ func Test_blob_insert()
let b = 0zDEADBEEF
call insert(b, 0x33, 2)
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
func Test_blob_reverse()