Mercurial > vim
diff src/testdir/test_functions.vim @ 17221:a8fc7d97b54d v8.1.1610
patch 8.1.1610: there is no way to add or load a buffer without side effects
commit https://github.com/vim/vim/commit/15e248e37f3925d430f96e945d52d3dc423cdc83
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 30 20:21:37 2019 +0200
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 30 Jun 2019 20:30:05 +0200 |
parents | 6990c1160ea5 |
children | 07bbe73b8e74 |
line wrap: on
line diff
--- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -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