2020-12-07 11:35:03 -07:00
|
|
|
" Tests for Vim buffer
|
|
|
|
|
2022-01-23 22:01:35 -07:00
|
|
|
source check.vim
|
|
|
|
|
2022-07-01 18:52:05 -07:00
|
|
|
" Test for the :bunload command with an offset
|
|
|
|
func Test_bunload_with_offset()
|
|
|
|
%bwipe!
|
2023-08-22 02:44:04 -07:00
|
|
|
call writefile(['B1'], 'Xb1', 'D')
|
|
|
|
call writefile(['B2'], 'Xb2', 'D')
|
|
|
|
call writefile(['B3'], 'Xb3', 'D')
|
|
|
|
call writefile(['B4'], 'Xb4', 'D')
|
2022-07-01 18:52:05 -07:00
|
|
|
|
|
|
|
" Load four buffers. Unload the second and third buffers and then
|
|
|
|
" execute .+3bunload to unload the last buffer.
|
2023-08-22 02:44:04 -07:00
|
|
|
edit Xb1
|
|
|
|
new Xb2
|
|
|
|
new Xb3
|
|
|
|
new Xb4
|
|
|
|
|
|
|
|
bunload Xb2
|
|
|
|
bunload Xb3
|
|
|
|
exe bufwinnr('Xb1') . 'wincmd w'
|
2022-07-01 18:52:05 -07:00
|
|
|
.+3bunload
|
2023-08-22 02:44:04 -07:00
|
|
|
call assert_equal(0, getbufinfo('Xb4')[0].loaded)
|
|
|
|
call assert_equal('Xb1',
|
2022-07-01 18:52:05 -07:00
|
|
|
\ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
|
|
|
|
|
|
|
|
" Load four buffers. Unload the third and fourth buffers. Execute .+3bunload
|
|
|
|
" and check whether the second buffer is unloaded.
|
|
|
|
ball
|
2023-08-22 02:44:04 -07:00
|
|
|
bunload Xb3
|
|
|
|
bunload Xb4
|
|
|
|
exe bufwinnr('Xb1') . 'wincmd w'
|
2022-07-01 18:52:05 -07:00
|
|
|
.+3bunload
|
2023-08-22 02:44:04 -07:00
|
|
|
call assert_equal(0, getbufinfo('Xb2')[0].loaded)
|
|
|
|
call assert_equal('Xb1',
|
2022-07-01 18:52:05 -07:00
|
|
|
\ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
|
|
|
|
|
|
|
|
" Load four buffers. Unload the second and third buffers and from the last
|
|
|
|
" buffer execute .-3bunload to unload the first buffer.
|
|
|
|
ball
|
2023-08-22 02:44:04 -07:00
|
|
|
bunload Xb2
|
|
|
|
bunload Xb3
|
|
|
|
exe bufwinnr('Xb4') . 'wincmd w'
|
2022-07-01 18:52:05 -07:00
|
|
|
.-3bunload
|
2023-08-22 02:44:04 -07:00
|
|
|
call assert_equal(0, getbufinfo('Xb1')[0].loaded)
|
|
|
|
call assert_equal('Xb4',
|
2022-07-01 18:52:05 -07:00
|
|
|
\ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
|
|
|
|
|
|
|
|
" Load four buffers. Unload the first and second buffers. Execute .-3bunload
|
|
|
|
" from the last buffer and check whether the third buffer is unloaded.
|
|
|
|
ball
|
2023-08-22 02:44:04 -07:00
|
|
|
bunload Xb1
|
|
|
|
bunload Xb2
|
|
|
|
exe bufwinnr('Xb4') . 'wincmd w'
|
2022-07-01 18:52:05 -07:00
|
|
|
.-3bunload
|
2023-08-22 02:44:04 -07:00
|
|
|
call assert_equal(0, getbufinfo('Xb3')[0].loaded)
|
|
|
|
call assert_equal('Xb4',
|
2022-07-01 18:52:05 -07:00
|
|
|
\ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
|
|
|
|
|
|
|
|
%bwipe!
|
|
|
|
|
|
|
|
call assert_fails('1,4bunload', 'E16:')
|
|
|
|
call assert_fails(',100bunload', 'E16:')
|
|
|
|
|
2022-11-04 16:24:06 -07:00
|
|
|
call assert_fails('$bunload', 'E90:')
|
2022-07-01 18:52:05 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test for :buffer, :bnext, :bprevious, :brewind, :blast and :bmodified
|
|
|
|
" commands
|
|
|
|
func Test_buflist_browse()
|
|
|
|
%bwipe!
|
|
|
|
call assert_fails('buffer 1000', 'E86:')
|
|
|
|
|
2023-08-22 02:44:04 -07:00
|
|
|
call writefile(['foo1', 'foo2', 'foo3', 'foo4'], 'Xbrowse1', 'D')
|
|
|
|
call writefile(['bar1', 'bar2', 'bar3', 'bar4'], 'Xbrowse2', 'D')
|
|
|
|
call writefile(['baz1', 'baz2', 'baz3', 'baz4'], 'Xbrowse3', 'D')
|
2023-08-21 01:27:14 -07:00
|
|
|
edit Xbrowse1
|
2022-07-01 18:52:05 -07:00
|
|
|
let b1 = bufnr()
|
2023-08-21 01:27:14 -07:00
|
|
|
edit Xbrowse2
|
2022-07-01 18:52:05 -07:00
|
|
|
let b2 = bufnr()
|
2023-08-21 01:27:14 -07:00
|
|
|
edit +/baz4 Xbrowse3
|
2022-07-01 18:52:05 -07:00
|
|
|
let b3 = bufnr()
|
|
|
|
|
|
|
|
call assert_fails('buffer ' .. b1 .. ' abc', 'E488:')
|
|
|
|
call assert_equal(b3, bufnr())
|
|
|
|
call assert_equal(4, line('.'))
|
|
|
|
exe 'buffer +/bar2 ' .. b2
|
|
|
|
call assert_equal(b2, bufnr())
|
|
|
|
call assert_equal(2, line('.'))
|
|
|
|
exe 'buffer +/bar1'
|
|
|
|
call assert_equal(b2, bufnr())
|
|
|
|
call assert_equal(1, line('.'))
|
|
|
|
|
2022-07-11 17:28:56 -07:00
|
|
|
brewind +
|
2022-07-01 18:52:05 -07:00
|
|
|
call assert_equal(b1, bufnr())
|
2022-07-11 17:28:56 -07:00
|
|
|
call assert_equal(4, line('.'))
|
2022-07-01 18:52:05 -07:00
|
|
|
|
|
|
|
blast +/baz2
|
|
|
|
call assert_equal(b3, bufnr())
|
|
|
|
call assert_equal(2, line('.'))
|
|
|
|
|
|
|
|
bprevious +/bar4
|
|
|
|
call assert_equal(b2, bufnr())
|
|
|
|
call assert_equal(4, line('.'))
|
|
|
|
|
|
|
|
bnext +/baz3
|
|
|
|
call assert_equal(b3, bufnr())
|
|
|
|
call assert_equal(3, line('.'))
|
|
|
|
|
|
|
|
call assert_fails('bmodified', 'E84:')
|
|
|
|
call setbufvar(b2, '&modified', 1)
|
|
|
|
exe 'bmodified +/bar3'
|
|
|
|
call assert_equal(b2, bufnr())
|
|
|
|
call assert_equal(3, line('.'))
|
|
|
|
|
|
|
|
" With no listed buffers in the list, :bnext and :bprev should fail
|
|
|
|
%bwipe!
|
|
|
|
set nobuflisted
|
|
|
|
call assert_fails('bnext', 'E85:')
|
|
|
|
call assert_fails('bprev', 'E85:')
|
|
|
|
set buflisted
|
|
|
|
|
|
|
|
call assert_fails('sandbox bnext', 'E48:')
|
|
|
|
|
|
|
|
%bwipe!
|
|
|
|
endfunc
|
|
|
|
|
2024-07-10 17:02:59 -07:00
|
|
|
" Test for :bnext and :bprev when called from help and non-help buffers.
|
|
|
|
func Test_bnext_bprev_help()
|
|
|
|
%bwipe!
|
|
|
|
|
|
|
|
e XHelp1 | set bt=help
|
|
|
|
let b1 = bufnr()
|
|
|
|
e Xbuf1
|
|
|
|
let b2 = bufnr()
|
|
|
|
|
|
|
|
" There's only one buffer of each type.
|
|
|
|
b XHelp1
|
|
|
|
bnext | call assert_equal(b1, bufnr())
|
|
|
|
bprev | call assert_equal(b1, bufnr())
|
|
|
|
b Xbuf1
|
|
|
|
bnext | call assert_equal(b2, bufnr())
|
|
|
|
bprev | call assert_equal(b2, bufnr())
|
|
|
|
|
|
|
|
" Add one more buffer of each type.
|
|
|
|
e XHelp2 | set bt=help
|
|
|
|
let b3 = bufnr()
|
|
|
|
e Xbuf2
|
|
|
|
let b4 = bufnr()
|
|
|
|
|
|
|
|
" Help buffer jumps to help buffer.
|
|
|
|
b XHelp1
|
|
|
|
bnext | call assert_equal(b3, bufnr())
|
|
|
|
bnext | call assert_equal(b1, bufnr())
|
|
|
|
bprev | call assert_equal(b3, bufnr())
|
|
|
|
bprev | call assert_equal(b1, bufnr())
|
|
|
|
|
|
|
|
" Regular buffer jumps to regular buffer.
|
|
|
|
b Xbuf1
|
|
|
|
bnext | call assert_equal(b4, bufnr())
|
|
|
|
bnext | call assert_equal(b2, bufnr())
|
|
|
|
bprev | call assert_equal(b4, bufnr())
|
|
|
|
bprev | call assert_equal(b2, bufnr())
|
|
|
|
|
|
|
|
" :brewind and :blast are not affected by the buffer type.
|
|
|
|
b Xbuf2
|
|
|
|
brewind | call assert_equal(b1, bufnr())
|
|
|
|
b XHelp1
|
|
|
|
blast | call assert_equal(b4, bufnr())
|
|
|
|
|
|
|
|
%bwipe!
|
|
|
|
endfunc
|
|
|
|
|
2022-07-01 18:52:05 -07:00
|
|
|
" Test for :bdelete
|
|
|
|
func Test_bdelete_cmd()
|
|
|
|
%bwipe!
|
|
|
|
call assert_fails('bdelete 5', 'E516:')
|
2022-07-14 20:43:42 -07:00
|
|
|
call assert_fails('1,1bdelete 1 2', 'E488:')
|
2022-11-06 00:52:42 -07:00
|
|
|
call assert_fails('bdelete \)', 'E55:')
|
2022-07-01 18:52:05 -07:00
|
|
|
|
2024-03-28 04:03:27 -07:00
|
|
|
" Deleting an unlisted and unloaded buffer
|
2023-11-12 18:08:02 -07:00
|
|
|
edit Xbdelfile1
|
2022-07-01 18:52:05 -07:00
|
|
|
let bnr = bufnr()
|
|
|
|
set nobuflisted
|
|
|
|
enew
|
|
|
|
call assert_fails('bdelete ' .. bnr, 'E516:')
|
2022-08-22 20:24:46 -07:00
|
|
|
|
|
|
|
" Deleting more than one buffer
|
|
|
|
new Xbuf1
|
|
|
|
new Xbuf2
|
|
|
|
exe 'bdel ' .. bufnr('Xbuf2') .. ' ' .. bufnr('Xbuf1')
|
|
|
|
call assert_equal(1, winnr('$'))
|
|
|
|
call assert_equal(0, getbufinfo('Xbuf1')[0].loaded)
|
|
|
|
call assert_equal(0, getbufinfo('Xbuf2')[0].loaded)
|
|
|
|
|
|
|
|
" Deleting more than one buffer and an invalid buffer
|
|
|
|
new Xbuf1
|
|
|
|
new Xbuf2
|
|
|
|
let cmd = "exe 'bdel ' .. bufnr('Xbuf2') .. ' xxx ' .. bufnr('Xbuf1')"
|
|
|
|
call assert_fails(cmd, 'E94:')
|
|
|
|
call assert_equal(2, winnr('$'))
|
|
|
|
call assert_equal(1, getbufinfo('Xbuf1')[0].loaded)
|
|
|
|
call assert_equal(0, getbufinfo('Xbuf2')[0].loaded)
|
|
|
|
|
2022-07-01 18:52:05 -07:00
|
|
|
%bwipe!
|
|
|
|
endfunc
|
|
|
|
|
2021-02-13 11:41:30 -07:00
|
|
|
func Test_buffer_error()
|
|
|
|
new foo1
|
|
|
|
new foo2
|
|
|
|
|
|
|
|
call assert_fails('buffer foo', 'E93:')
|
|
|
|
call assert_fails('buffer bar', 'E94:')
|
|
|
|
call assert_fails('buffer 0', 'E939:')
|
|
|
|
|
|
|
|
%bwipe
|
|
|
|
endfunc
|
|
|
|
|
2022-08-22 20:24:46 -07:00
|
|
|
" Test for the status messages displayed when unloading, deleting or wiping
|
|
|
|
" out buffers
|
|
|
|
func Test_buffer_statusmsg()
|
|
|
|
CheckEnglish
|
|
|
|
set report=1
|
|
|
|
new Xbuf1
|
|
|
|
new Xbuf2
|
|
|
|
let bnr = bufnr()
|
|
|
|
exe "normal 2\<C-G>"
|
|
|
|
call assert_match('buf ' .. bnr .. ':', v:statusmsg)
|
|
|
|
bunload Xbuf1 Xbuf2
|
|
|
|
call assert_equal('2 buffers unloaded', v:statusmsg)
|
|
|
|
bdel Xbuf1 Xbuf2
|
|
|
|
call assert_equal('2 buffers deleted', v:statusmsg)
|
|
|
|
bwipe Xbuf1 Xbuf2
|
|
|
|
call assert_equal('2 buffers wiped out', v:statusmsg)
|
|
|
|
set report&
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test for quitting the 'swapfile exists' dialog with the split buffer
|
|
|
|
" command.
|
|
|
|
func Test_buffer_sbuf_cleanup()
|
2023-08-22 02:44:04 -07:00
|
|
|
call writefile([], 'XsplitCleanup', 'D')
|
2022-08-22 20:24:46 -07:00
|
|
|
" first open the file in a buffer
|
2023-08-21 01:27:14 -07:00
|
|
|
new XsplitCleanup
|
2022-08-22 20:24:46 -07:00
|
|
|
let bnr = bufnr()
|
|
|
|
close
|
|
|
|
" create the swap file
|
2023-08-22 02:44:04 -07:00
|
|
|
call writefile([], '.XsplitCleanup.swp', 'D')
|
2022-08-22 20:24:46 -07:00
|
|
|
" Remove the catch-all that runtest.vim adds
|
|
|
|
au! SwapExists
|
|
|
|
augroup BufTest
|
|
|
|
au!
|
2023-08-21 01:27:14 -07:00
|
|
|
autocmd SwapExists XsplitCleanup let v:swapchoice='q'
|
2022-08-22 20:24:46 -07:00
|
|
|
augroup END
|
|
|
|
exe 'sbuf ' . bnr
|
|
|
|
call assert_equal(1, winnr('$'))
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
|
2022-08-22 20:24:46 -07:00
|
|
|
|
|
|
|
" test for :sball
|
|
|
|
sball
|
|
|
|
call assert_equal(1, winnr('$'))
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
|
2022-08-22 20:24:46 -07:00
|
|
|
|
|
|
|
%bw!
|
|
|
|
set shortmess+=F
|
|
|
|
let v:statusmsg = ''
|
2023-08-21 01:27:14 -07:00
|
|
|
edit XsplitCleanup
|
2022-08-22 20:24:46 -07:00
|
|
|
call assert_equal('', v:statusmsg)
|
|
|
|
call assert_equal(1, winnr('$'))
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
|
2022-08-22 20:24:46 -07:00
|
|
|
set shortmess&
|
|
|
|
|
|
|
|
augroup BufTest
|
|
|
|
au!
|
|
|
|
augroup END
|
|
|
|
augroup! BufTest
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test for deleting a modified buffer with :confirm
|
|
|
|
func Test_bdel_with_confirm()
|
|
|
|
CheckUnix
|
|
|
|
CheckNotGui
|
|
|
|
CheckFeature dialog_con
|
|
|
|
new
|
|
|
|
call setline(1, 'test')
|
|
|
|
call assert_fails('bdel', 'E89:')
|
|
|
|
call feedkeys('c', 'L')
|
|
|
|
confirm bdel
|
|
|
|
call assert_equal(2, winnr('$'))
|
|
|
|
call assert_equal(1, &modified)
|
|
|
|
call feedkeys('n', 'L')
|
|
|
|
confirm bdel
|
|
|
|
call assert_equal(1, winnr('$'))
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test for editing another buffer from a modified buffer with :confirm
|
|
|
|
func Test_goto_buf_with_confirm()
|
|
|
|
CheckUnix
|
|
|
|
CheckNotGui
|
|
|
|
CheckFeature dialog_con
|
2024-04-05 03:32:04 -07:00
|
|
|
" When dialog_con_gui is defined, Vim is compiled with GUI support
|
|
|
|
" and FEAT_BROWSE will be defined, which causes :confirm :b to
|
|
|
|
" call do_browse(), which will try to use a GUI file browser,
|
|
|
|
" which aborts if a GUI is not available.
|
|
|
|
CheckNotFeature dialog_con_gui
|
2023-08-21 01:27:14 -07:00
|
|
|
new XgotoConf
|
2022-08-22 20:24:46 -07:00
|
|
|
enew
|
|
|
|
call setline(1, 'test')
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_fails('b XgotoConf', 'E37:')
|
2022-08-22 20:24:46 -07:00
|
|
|
call feedkeys('c', 'L')
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_fails('confirm b XgotoConf', 'E37:')
|
2024-04-05 03:32:04 -07:00
|
|
|
call assert_true(&modified)
|
|
|
|
call assert_true(empty(bufname('%')))
|
2022-08-22 20:24:46 -07:00
|
|
|
call feedkeys('y', 'L')
|
2024-04-05 03:32:04 -07:00
|
|
|
confirm b XgotoConf
|
|
|
|
call assert_equal('XgotoConf', bufname('%'))
|
|
|
|
call assert_equal(['test'], readfile('Untitled'))
|
|
|
|
e Untitled
|
|
|
|
call setline(2, 'test2')
|
2022-08-22 20:24:46 -07:00
|
|
|
call feedkeys('n', 'L')
|
2023-08-21 01:27:14 -07:00
|
|
|
confirm b XgotoConf
|
2024-04-05 03:32:04 -07:00
|
|
|
call assert_equal('XgotoConf', bufname('%'))
|
|
|
|
call assert_equal(['test'], readfile('Untitled'))
|
|
|
|
call delete('Untitled')
|
2022-08-22 20:24:46 -07:00
|
|
|
close!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test for splitting buffer with 'switchbuf'
|
|
|
|
func Test_buffer_switchbuf()
|
2023-08-21 01:27:14 -07:00
|
|
|
new Xswitchbuf
|
2022-08-22 20:24:46 -07:00
|
|
|
wincmd w
|
|
|
|
set switchbuf=useopen
|
2023-08-21 01:27:14 -07:00
|
|
|
sbuf Xswitchbuf
|
2022-08-22 20:24:46 -07:00
|
|
|
call assert_equal(1, winnr())
|
|
|
|
call assert_equal(2, winnr('$'))
|
|
|
|
set switchbuf=usetab
|
|
|
|
tabnew
|
2023-08-21 01:27:14 -07:00
|
|
|
sbuf Xswitchbuf
|
2022-08-22 20:24:46 -07:00
|
|
|
call assert_equal(1, tabpagenr())
|
|
|
|
call assert_equal(2, tabpagenr('$'))
|
|
|
|
set switchbuf&
|
|
|
|
%bw
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test for BufAdd autocommand wiping out the buffer
|
|
|
|
func Test_bufadd_autocmd_bwipe()
|
|
|
|
%bw!
|
|
|
|
augroup BufAdd_Wipe
|
|
|
|
au!
|
2023-08-21 01:27:14 -07:00
|
|
|
autocmd BufAdd Xbwipe %bw!
|
2022-08-22 20:24:46 -07:00
|
|
|
augroup END
|
2023-08-21 01:27:14 -07:00
|
|
|
edit Xbwipe
|
2022-08-22 20:24:46 -07:00
|
|
|
call assert_equal('', @%)
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_equal(0, bufexists('Xbwipe'))
|
2022-08-22 20:24:46 -07:00
|
|
|
augroup BufAdd_Wipe
|
|
|
|
au!
|
|
|
|
augroup END
|
|
|
|
augroup! BufAdd_Wipe
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test for trying to load a buffer with text locked
|
|
|
|
" <C-\>e in the command line is used to lock the text
|
|
|
|
func Test_load_buf_with_text_locked()
|
2023-11-12 18:08:02 -07:00
|
|
|
new Xlockfile1
|
|
|
|
edit Xlockfile2
|
2022-08-22 20:24:46 -07:00
|
|
|
let cmd = ":\<C-\>eexecute(\"normal \<C-O>\")\<CR>\<C-C>"
|
|
|
|
call assert_fails("call feedkeys(cmd, 'xt')", 'E565:')
|
|
|
|
%bw!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test for using CTRL-^ to edit the alternative file keeping the cursor
|
|
|
|
" position with 'nostartofline'. Also test using the 'buf' command.
|
|
|
|
func Test_buffer_edit_altfile()
|
2023-08-22 02:44:04 -07:00
|
|
|
call writefile(repeat(['one two'], 50), 'Xaltfile1', 'D')
|
|
|
|
call writefile(repeat(['five six'], 50), 'Xaltfile2', 'D')
|
2022-08-22 20:24:46 -07:00
|
|
|
set nosol
|
2023-08-21 01:27:14 -07:00
|
|
|
edit Xaltfile1
|
2022-08-22 20:24:46 -07:00
|
|
|
call cursor(25, 5)
|
2023-08-21 01:27:14 -07:00
|
|
|
edit Xaltfile2
|
2022-08-22 20:24:46 -07:00
|
|
|
call cursor(30, 4)
|
|
|
|
exe "normal \<C-^>"
|
|
|
|
call assert_equal([0, 25, 5, 0], getpos('.'))
|
|
|
|
exe "normal \<C-^>"
|
|
|
|
call assert_equal([0, 30, 4, 0], getpos('.'))
|
2023-08-21 01:27:14 -07:00
|
|
|
buf Xaltfile1
|
2022-08-22 20:24:46 -07:00
|
|
|
call assert_equal([0, 25, 5, 0], getpos('.'))
|
2023-08-21 01:27:14 -07:00
|
|
|
buf Xaltfile2
|
2022-08-22 20:24:46 -07:00
|
|
|
call assert_equal([0, 30, 4, 0], getpos('.'))
|
|
|
|
set sol&
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test for running the :sball command with a maximum window count and a
|
|
|
|
" modified buffer
|
|
|
|
func Test_sball_with_count()
|
|
|
|
%bw!
|
2023-08-21 01:27:14 -07:00
|
|
|
edit Xcountfile1
|
2022-08-22 20:24:46 -07:00
|
|
|
call setline(1, ['abc'])
|
2023-08-21 01:27:14 -07:00
|
|
|
new Xcountfile2
|
|
|
|
new Xcountfile3
|
|
|
|
new Xcountfile4
|
2022-08-22 20:24:46 -07:00
|
|
|
2sball
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_equal(bufnr('Xcountfile4'), winbufnr(1))
|
|
|
|
call assert_equal(bufnr('Xcountfile1'), winbufnr(2))
|
|
|
|
call assert_equal(0, getbufinfo('Xcountfile2')[0].loaded)
|
|
|
|
call assert_equal(0, getbufinfo('Xcountfile3')[0].loaded)
|
2022-08-22 20:24:46 -07:00
|
|
|
%bw!
|
|
|
|
endfunc
|
|
|
|
|
2021-02-13 11:34:43 -07:00
|
|
|
func Test_badd_options()
|
|
|
|
new SomeNewBuffer
|
2021-02-13 11:49:42 -07:00
|
|
|
setlocal numberwidth=3
|
2021-02-13 11:34:43 -07:00
|
|
|
wincmd p
|
2021-02-13 12:05:26 -07:00
|
|
|
badd +1 SomeNewBuffer
|
2021-02-13 11:34:43 -07:00
|
|
|
new SomeNewBuffer
|
2021-02-13 11:49:42 -07:00
|
|
|
call assert_equal(3, &numberwidth)
|
2021-02-13 11:34:43 -07:00
|
|
|
close
|
|
|
|
close
|
|
|
|
bwipe! SomeNewBuffer
|
|
|
|
endfunc
|
|
|
|
|
2020-12-07 11:35:03 -07:00
|
|
|
func Test_balt()
|
|
|
|
new SomeNewBuffer
|
|
|
|
balt +3 OtherBuffer
|
|
|
|
e #
|
|
|
|
call assert_equal('OtherBuffer', bufname())
|
|
|
|
endfunc
|
|
|
|
|
2022-01-23 22:01:35 -07:00
|
|
|
" Test for buffer match URL(scheme) check
|
|
|
|
" scheme is alpha and inner hyphen only.
|
|
|
|
func Test_buffer_scheme()
|
|
|
|
CheckMSWindows
|
|
|
|
|
2023-08-22 02:45:44 -07:00
|
|
|
set noswapfile
|
2022-01-23 22:01:35 -07:00
|
|
|
set noshellslash
|
|
|
|
%bwipe!
|
|
|
|
let bufnames = [
|
2022-11-06 01:31:33 -07:00
|
|
|
\ #{id: 'ssb0', name: 'test://xyz/foo/ssb0' , match: 1},
|
|
|
|
\ #{id: 'ssb1', name: 'test+abc://xyz/foo/ssb1', match: 0},
|
|
|
|
\ #{id: 'ssb2', name: 'test_abc://xyz/foo/ssb2', match: 0},
|
|
|
|
\ #{id: 'ssb3', name: 'test-abc://xyz/foo/ssb3', match: 1},
|
|
|
|
\ #{id: 'ssb4', name: '-test://xyz/foo/ssb4' , match: 0},
|
|
|
|
\ #{id: 'ssb5', name: 'test-://xyz/foo/ssb5' , match: 0},
|
2022-01-23 22:01:35 -07:00
|
|
|
\]
|
|
|
|
for buf in bufnames
|
|
|
|
new `=buf.name`
|
|
|
|
if buf.match
|
|
|
|
call assert_equal(buf.name, getbufinfo(buf.id)[0].name)
|
|
|
|
else
|
|
|
|
" slashes will have become backslashes
|
|
|
|
call assert_notequal(buf.name, getbufinfo(buf.id)[0].name)
|
|
|
|
endif
|
|
|
|
bwipe
|
|
|
|
endfor
|
|
|
|
|
|
|
|
set shellslash&
|
2023-08-22 02:45:44 -07:00
|
|
|
set swapfile&
|
2022-01-23 22:01:35 -07:00
|
|
|
endfunc
|
|
|
|
|
2022-05-11 04:07:31 -07:00
|
|
|
" this was using a NULL pointer after failing to use the pattern
|
|
|
|
func Test_buf_pattern_invalid()
|
|
|
|
vsplit 0000000
|
|
|
|
silent! buf [0--]\&\zs*\zs*e
|
|
|
|
bwipe!
|
2022-05-11 04:10:18 -07:00
|
|
|
|
|
|
|
vsplit 00000000000000000000000000
|
|
|
|
silent! buf [0--]\&\zs*\zs*e
|
|
|
|
bwipe!
|
2023-01-17 02:02:25 -07:00
|
|
|
|
|
|
|
" similar case with different code path
|
|
|
|
split 0
|
|
|
|
edit ÿ
|
|
|
|
silent! buf [0--]\&\zs*\zs*0
|
|
|
|
bwipe!
|
2022-05-11 04:07:31 -07:00
|
|
|
endfunc
|
|
|
|
|
2022-11-06 16:21:46 -07:00
|
|
|
" Test for the 'maxmem' and 'maxmemtot' options
|
|
|
|
func Test_buffer_maxmem()
|
|
|
|
" use 1KB per buffer and 2KB for all the buffers
|
|
|
|
" set maxmem=1 maxmemtot=2
|
|
|
|
new
|
|
|
|
let v:errmsg = ''
|
|
|
|
" try opening some files
|
|
|
|
edit test_arglist.vim
|
|
|
|
call assert_equal('test_arglist.vim', bufname())
|
|
|
|
edit test_eval_stuff.vim
|
|
|
|
call assert_equal('test_eval_stuff.vim', bufname())
|
|
|
|
b test_arglist.vim
|
|
|
|
call assert_equal('test_arglist.vim', bufname())
|
|
|
|
b test_eval_stuff.vim
|
|
|
|
call assert_equal('test_eval_stuff.vim', bufname())
|
|
|
|
close
|
|
|
|
call assert_equal('', v:errmsg)
|
|
|
|
" set maxmem& maxmemtot&
|
|
|
|
endfunc
|
|
|
|
|
2023-02-28 06:01:36 -07:00
|
|
|
" Test for buffer allocation failure
|
2023-02-28 05:59:59 -07:00
|
|
|
func Test_buflist_alloc_failure()
|
|
|
|
CheckFunction test_alloc_fail
|
|
|
|
%bw!
|
|
|
|
|
2023-08-21 01:27:14 -07:00
|
|
|
edit XallocFail1
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_fails('edit XallocFail2', 'E342:')
|
2023-02-28 05:59:59 -07:00
|
|
|
|
|
|
|
" test for bufadd()
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-02-28 05:59:59 -07:00
|
|
|
call assert_fails('call bufadd("Xbuffer")', 'E342:')
|
|
|
|
|
|
|
|
" test for setting the arglist
|
2023-08-21 01:27:14 -07:00
|
|
|
edit XallocFail2
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_fails('next XallocFail3', 'E342:')
|
2023-02-28 05:59:59 -07:00
|
|
|
|
|
|
|
" test for setting the alternate buffer name when writing a file
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-02-28 05:59:59 -07:00
|
|
|
call assert_fails('write Xother', 'E342:')
|
|
|
|
call delete('Xother')
|
|
|
|
|
|
|
|
" test for creating a buffer using bufnr()
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-02-28 05:59:59 -07:00
|
|
|
call assert_fails("call bufnr('Xnewbuf', v:true)", 'E342:')
|
|
|
|
|
|
|
|
" test for renaming buffer using :file
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-02-28 05:59:59 -07:00
|
|
|
call assert_fails('file Xnewfile', 'E342:')
|
|
|
|
|
|
|
|
" test for creating a buffer for a popup window
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-02-28 05:59:59 -07:00
|
|
|
call assert_fails('call popup_create("mypop", {})', 'E342:')
|
|
|
|
|
|
|
|
if has('terminal')
|
|
|
|
" test for creating a buffer for a terminal window
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-02-28 05:59:59 -07:00
|
|
|
call assert_fails('call term_start(&shell)', 'E342:')
|
|
|
|
%bw!
|
|
|
|
endif
|
|
|
|
|
|
|
|
" test for loading a new buffer after wiping out all the buffers
|
2023-08-21 01:27:14 -07:00
|
|
|
edit XallocFail4
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-02-28 05:59:59 -07:00
|
|
|
call assert_fails('%bw!', 'E342:')
|
|
|
|
|
|
|
|
" test for :checktime loading the buffer
|
2023-08-22 02:44:04 -07:00
|
|
|
call writefile(['one'], 'XallocFail5', 'D')
|
2023-02-28 05:59:59 -07:00
|
|
|
if has('unix')
|
2023-08-21 01:27:14 -07:00
|
|
|
edit XallocFail5
|
2023-02-28 05:59:59 -07:00
|
|
|
" sleep for some time to make sure the timestamp is different
|
|
|
|
sleep 200m
|
2023-08-21 01:27:14 -07:00
|
|
|
call writefile(['two'], 'XallocFail5')
|
2023-02-28 05:59:59 -07:00
|
|
|
set autoread
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-02-28 05:59:59 -07:00
|
|
|
call assert_fails('checktime', 'E342:')
|
|
|
|
set autoread&
|
|
|
|
bw!
|
|
|
|
endif
|
|
|
|
|
|
|
|
" test for :vimgrep loading a dummy buffer
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_fails('vimgrep two XallocFail5', 'E342:')
|
2023-02-28 05:59:59 -07:00
|
|
|
|
|
|
|
" test for quickfix command loading a buffer
|
2023-02-28 06:01:36 -07:00
|
|
|
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
|
2023-08-21 01:27:14 -07:00
|
|
|
call assert_fails('cexpr "XallocFail6:10:Line10"', 'E342:')
|
2023-02-28 05:59:59 -07:00
|
|
|
endfunc
|
|
|
|
|
2020-12-07 11:35:03 -07:00
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|