vim-patch:8.1.1610: there is no way to add or load a buffer without side effects

Problem:    There is no way to add or load a buffer without side effects.
Solution:   Add the bufadd() and bufload() functions.
15e248e37f
This commit is contained in:
Shougo Matsushita
2019-07-06 17:02:26 +09:00
parent 3c860e25e9
commit 3f6346b732
4 changed files with 70 additions and 0 deletions

View File

@@ -1188,3 +1188,31 @@ func Test_libcall_libcallnr()
call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:')
call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:')
endfunc
func Test_bufadd_bufload()
call assert_equal(0, bufexists('someName'))
let buf = bufadd('someName')
call assert_notequal(0, buf)
call assert_equal(1, bufexists('someName'))
call assert_equal(0, getbufvar(buf, '&buflisted'))
call assert_equal(0, bufloaded(buf))
call bufload(buf)
call assert_equal(1, bufloaded(buf))
call assert_equal([''], getbufline(buf, 1, '$'))
let curbuf = bufnr('')
call writefile(['some', 'text'], 'otherName')
let buf = bufadd('otherName')
call assert_notequal(0, buf)
call assert_equal(1, bufexists('otherName'))
call assert_equal(0, getbufvar(buf, '&buflisted'))
call assert_equal(0, bufloaded(buf))
call bufload(buf)
call assert_equal(1, bufloaded(buf))
call assert_equal(['some', 'text'], getbufline(buf, 1, '$'))
call assert_equal(curbuf, bufnr(''))
bwipe someName
bwipe otherName
call assert_equal(0, bufexists('someName'))
endfunc