summaryrefslogtreecommitdiff
path: root/src/testdir/test_blob.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-01-13 15:16:13 +0100
committerBram Moolenaar <Bram@vim.org>2019-01-13 15:16:13 +0100
commitc0f5a78c15b194f23bedb82e6825e34f481e6532 (patch)
tree499198e36943d41843167eadc9e90efdad928369 /src/testdir/test_blob.vim
parent6e5ea8d2a995b32bbc5972edc4f827b959f2702f (diff)
downloadvim-git-c0f5a78c15b194f23bedb82e6825e34f481e6532.tar.gz
patch 8.1.0736: code for Blob not sufficiently testedv8.1.0736
Problem: Code for Blob not sufficiently tested. Solution: Add more tests. Fix uncovered crash. Add test_null_blob().
Diffstat (limited to 'src/testdir/test_blob.vim')
-rw-r--r--src/testdir/test_blob.vim63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/testdir/test_blob.vim b/src/testdir/test_blob.vim
index 4ab28eb4f..550b8f1b9 100644
--- a/src/testdir/test_blob.vim
+++ b/src/testdir/test_blob.vim
@@ -21,6 +21,12 @@ func Test_blob_create()
call assert_equal(0xDE, get(b, 0))
call assert_equal(0xEF, get(b, 3))
call assert_fails('let x = get(b, 4)')
+
+ call assert_fails('let b = 0z1', 'E973:')
+ call assert_fails('let b = 0z1x', 'E973:')
+ call assert_fails('let b = 0z12345', 'E973:')
+
+ call assert_equal(0z, test_null_blob())
endfunc
" assignment to a blob
@@ -32,6 +38,45 @@ func Test_blob_assign()
let bcopy = b[:]
call assert_equal(b, bcopy)
call assert_false(b is bcopy)
+
+ let b = 0zDEADBEEF
+ let b2 = b
+ call assert_true(b is b2)
+ let b[:] = 0z11223344
+ call assert_equal(0z11223344, b)
+ call assert_equal(0z11223344, b2)
+ call assert_true(b is b2)
+
+ let b = 0zDEADBEEF
+ let b[3:] = 0z66
+ call assert_equal(0zDEADBE66, b)
+ let b[:1] = 0z8899
+ call assert_equal(0z8899BE66, b)
+
+ call assert_fails('let b[2:3] = 0z112233', 'E972:')
+ call assert_fails('let b[2:3] = 0z11', 'E972:')
+ call assert_fails('let b[3:2] = 0z', 'E979:')
+
+ let b = 0zDEADBEEF
+ let b += 0z99
+ call assert_equal(0zDEADBEEF99, b)
+
+ call assert_fails('let b .= 0z33', 'E734:')
+ call assert_fails('let b .= "xx"', 'E734:')
+ call assert_fails('let b += "xx"', 'E734:')
+ call assert_fails('let b[1:1] .= 0z55', 'E734:')
+endfunc
+
+func Test_blob_get_range()
+ let b = 0z0011223344
+ call assert_equal(0z2233, b[2:3])
+ call assert_equal(0z223344, b[2:-1])
+ call assert_equal(0z00, b[0:-5])
+ call assert_equal(0z, b[0:-11])
+ call assert_equal(0z44, b[-1:])
+ call assert_equal(0z0011223344, b[:])
+ call assert_equal(0z0011223344, b[:-1])
+ call assert_equal(0z, b[5:6])
endfunc
func Test_blob_to_string()
@@ -44,8 +89,12 @@ endfunc
func Test_blob_compare()
let b1 = 0z0011
let b2 = 0z1100
+ let b3 = 0z001122
+ call assert_true(b1 == b1)
call assert_false(b1 == b2)
+ call assert_false(b1 == b3)
call assert_true(b1 != b2)
+ call assert_true(b1 != b3)
call assert_true(b1 == 0z0011)
call assert_false(b1 is b2)
@@ -65,7 +114,7 @@ func Test_blob_range_assign()
let b[1] = 0x11
let b[2] = 0x22
call assert_equal(0z001122, b)
- call assert_fails('let b[4] = 0x33')
+ call assert_fails('let b[4] = 0x33', 'E979:')
endfunc
func Test_blob_for_loop()
@@ -177,3 +226,15 @@ func Test_blob_json_encode()
call assert_equal('[222,173,190,239]', json_encode(0zDEADBEEF))
call assert_equal('[]', json_encode(0z))
endfunc
+
+func Test_blob_lock()
+ let b = 0z112233
+ lockvar b
+ call assert_fails('let b = 0z44', 'E741:')
+ unlockvar b
+ let b = 0z44
+endfunc
+
+func Test_blob_sort()
+ call assert_fails('call sort([1.0, 0z11], "f")', 'E975:')
+endfunc