vim-patch:9.0.0276: 'buftype' values not sufficiently tested

Problem:    'buftype' values not sufficiently tested.
Solution:   Add and extend tests with 'buftype' values. (closes vim/vim#10988)
93f72cc119

"terminal" and "popup" buffer types cannot be tested, and commenting
them out causes an error, so just remove them.
This commit is contained in:
zeertzjq
2022-08-26 22:39:13 +08:00
parent 45c23a757c
commit d813ef0097
3 changed files with 67 additions and 30 deletions

View File

@@ -493,16 +493,24 @@ func Test_BufReadCmdHelpJump()
au! BufReadCmd au! BufReadCmd
endfunc endfunc
" BufReadCmd is triggered for a "nofile" buffer " BufReadCmd is triggered for a "nofile" buffer. Check all values.
func Test_BufReadCmdNofile() func Test_BufReadCmdNofile()
for val in ['nofile',
\ 'nowrite',
\ 'acwrite',
\ 'quickfix',
\ 'help',
\ 'prompt',
\ ]
new somefile new somefile
set buftype=nofile exe 'set buftype=' .. val
au BufReadCmd somefile call setline(1, 'triggered') au BufReadCmd somefile call setline(1, 'triggered')
edit edit
call assert_equal('triggered', getline(1)) call assert_equal('triggered', getline(1))
au! BufReadCmd au! BufReadCmd
bwipe! bwipe!
endfor
endfunc endfunc
func Test_augroup_deleted() func Test_augroup_deleted()
@@ -603,15 +611,22 @@ func Test_BufEnter()
au! BufEnter au! BufEnter
" Editing a "nofile" buffer doesn't read the file but does trigger BufEnter " Editing a "nofile" buffer doesn't read the file but does trigger BufEnter
" for historic reasons. " for historic reasons. Also test other 'buftype' values.
for val in ['nofile',
\ 'nowrite',
\ 'acwrite',
\ 'quickfix',
\ 'help',
\ 'prompt',
\ ]
new somefile new somefile
set buftype=nofile exe 'set buftype=' .. val
au BufEnter somefile call setline(1, 'some text') au BufEnter somefile call setline(1, 'some text')
edit edit
call assert_equal('some text', getline(1)) call assert_equal('some text', getline(1))
bwipe! bwipe!
au! BufEnter au! BufEnter
endfor
endfunc endfunc
" Closing a window might cause an endless loop " Closing a window might cause an endless loop

View File

@@ -187,4 +187,24 @@ func Test_deletebufline_select_mode()
bwipe! bwipe!
endfunc endfunc
func Test_setbufline_startup_nofile()
let before =<< trim [CODE]
set shortmess+=F
file Xresult
set buftype=nofile
call setbufline('', 1, 'success')
[CODE]
let after =<< trim [CODE]
set buftype=
write
quit
[CODE]
if !RunVim(before, after, '--clean')
return
endif
call assert_equal(['success'], readfile('Xresult'))
call delete('Xresult')
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -1880,19 +1880,21 @@ func Test_bufadd_bufload()
exe 'bwipe ' .. buf2 exe 'bwipe ' .. buf2
call assert_equal(0, bufexists(buf2)) call assert_equal(0, bufexists(buf2))
" when 'buftype' is "nofile" then bufload() does not read the file " When 'buftype' is "nofile" then bufload() does not read the file.
" Other values too.
for val in [['nofile', 0],
\ ['nowrite', 1],
\ ['acwrite', 1],
\ ['quickfix', 0],
\ ['help', 1],
\ ['prompt', 0],
\ ]
bwipe! XotherName bwipe! XotherName
let buf = bufadd('XotherName') let buf = bufadd('XotherName')
call setbufvar(buf, '&bt', 'nofile') call setbufvar(buf, '&bt', val[0])
call bufload(buf) call bufload(buf)
call assert_equal([''], getbufline(buf, 1, '$')) call assert_equal(val[1] ? ['some', 'text'] : [''], getbufline(buf, 1, '$'), val[0])
endfor
" when 'buftype' is "acwrite" then bufload() DOES read the file
bwipe! XotherName
let buf = bufadd('XotherName')
call setbufvar(buf, '&bt', 'acwrite')
call bufload(buf)
call assert_equal(['some', 'text'], getbufline(buf, 1, '$'))
bwipe someName bwipe someName
bwipe XotherName bwipe XotherName