0
0
mirror of https://github.com/vim/vim.git synced 2025-10-04 05:25:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2019-06-30 20:21:37 +02:00
parent 2e62b568e9
commit 15e248e37f
4 changed files with 81 additions and 0 deletions

View File

@@ -1515,3 +1515,31 @@ endfunc
func Test_eventhandler()
call assert_equal(0, eventhandler())
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