1
0
forked from aniani/vim

patch 9.0.0795: readblob() always reads the whole file

Problem:    readblob() always reads the whole file.
Solution:   Add arguments to read part of the file. (Ken Takata,
            closes #11402)
This commit is contained in:
K.Takata
2022-10-19 14:02:40 +01:00
committed by Bram Moolenaar
parent 9f62ea01a0
commit 11df3aeee5
7 changed files with 98 additions and 23 deletions

View File

@@ -488,10 +488,29 @@ func Test_blob_read_write()
call writefile(b, 'Xblob')
VAR br = readfile('Xblob', 'B')
call assert_equal(b, br)
VAR br2 = readblob('Xblob')
call assert_equal(b, br2)
VAR br3 = readblob('Xblob', 1)
call assert_equal(b[1 :], br3)
VAR br4 = readblob('Xblob', 1, 2)
call assert_equal(b[1 : 2], br4)
VAR br5 = readblob('Xblob', -3)
call assert_equal(b[-3 :], br5)
VAR br6 = readblob('Xblob', -3, 2)
call assert_equal(b[-3 : -2], br6)
VAR br1e = readblob('Xblob', 10000)
call assert_equal(0z, br1e)
VAR br2e = readblob('Xblob', -10000)
call assert_equal(0z, br2e)
call delete('Xblob')
END
call v9.CheckLegacyAndVim9Success(lines)
call assert_fails("call readblob('notexist')", 'E484:')
" TODO: How do we test for the E485 error?
" This was crashing when calling readfile() with a directory.
call assert_fails("call readfile('.', 'B')", 'E17: "." is a directory')
endfunc