summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_blob.vim
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2022-04-03 11:22:38 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-03 11:22:38 +0100
commit72bb47e38f6805050ed6d969f17591bed71f83d4 (patch)
tree2a129b54c7d20524362720c8385128d5a7c7fc41 /src/testdir/test_blob.vim
parent58f331a05f5b7bdddf04e68b6e51a827fd0c43f0 (diff)
patch 8.2.4670: memory allocation failures for new tab page not testedv8.2.4670
Problem: Memory allocation failures for new tab page not tested. Solution: Add tests with failing memory allocation. (Yegappan Lakshmanan, closes #10067)
Diffstat (limited to 'src/testdir/test_blob.vim')
-rw-r--r--src/testdir/test_blob.vim39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/testdir/test_blob.vim b/src/testdir/test_blob.vim
index e8bc2c9dad..b249bc60c6 100644
--- a/src/testdir/test_blob.vim
+++ b/src/testdir/test_blob.vim
@@ -702,4 +702,43 @@ func Test_blob2string()
call assert_equal(v, string(b))
endfunc
+" Test for blob allocation failure
+func Test_blob_alloc_failure()
+ " blob variable
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let v = 0z10', 'E342:')
+
+ " blob slice
+ let v = 0z1020
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = v[0:0]', 'E342:')
+ call assert_equal(0z1020, x)
+
+ " blob remove()
+ let v = 0z10203040
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = remove(v, 1, 2)', 'E342:')
+ call assert_equal(0, x)
+
+ " list2blob()
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let a = list2blob([1, 2, 4])', 'E342:')
+ call assert_equal(0, a)
+
+ " mapnew()
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = mapnew(0z1234, {_, v -> 1})', 'E342:')
+ call assert_equal(0, x)
+
+ " copy()
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = copy(v)', 'E342:')
+ call assert_equal(0z, x)
+
+ " readblob()
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = readblob("test_blob.vim")', 'E342:')
+ call assert_equal(0, x)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab