]> granicus.if.org Git - vim/commitdiff
patch 9.0.0276: 'buftype' values not sufficiently tested v9.0.0276
authorzeertzjq <zeertzjq@outlook.com>
Fri, 26 Aug 2022 14:34:52 +0000 (15:34 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 26 Aug 2022 14:34:52 +0000 (15:34 +0100)
Problem:    'buftype' values not sufficiently tested.
Solution:   Add and extend tests with 'buftype' values. (closes #10988)

src/testdir/test_autocmd.vim
src/testdir/test_bufline.vim
src/testdir/test_functions.vim
src/version.c

index 4b0928517a734b93527eb4defc9937b0bf95c5d3..189a2bc4642020f3688f7c597fd9a102915fc318 100644 (file)
@@ -576,16 +576,26 @@ func Test_BufReadCmdHelpJump()
   au! BufReadCmd
 endfunc
 
-" BufReadCmd is triggered for a "nofile" buffer
+" BufReadCmd is triggered for a "nofile" buffer. Check all values.
 func Test_BufReadCmdNofile()
-  new somefile
-  set buftype=nofile
-  au BufReadCmd somefile call setline(1, 'triggered')
-  edit
-  call assert_equal('triggered', getline(1))
-
-  au! BufReadCmd
-  bwipe!
+  for val in ['nofile',
+            \ 'nowrite',
+            \ 'acwrite',
+            \ 'quickfix',
+            \ 'help',
+            \ 'terminal',
+            \ 'prompt',
+            \ 'popup',
+            \ ]
+    new somefile
+    exe 'set buftype=' .. val
+    au BufReadCmd somefile call setline(1, 'triggered')
+    edit
+    call assert_equal('triggered', getline(1))
+
+    au! BufReadCmd
+    bwipe!
+  endfor
 endfunc
 
 func Test_augroup_deleted()
@@ -685,15 +695,24 @@ func Test_BufEnter()
   au! BufEnter
 
   " Editing a "nofile" buffer doesn't read the file but does trigger BufEnter
-  " for historic reasons.
-  new somefile
-  set buftype=nofile
-  au BufEnter somefile call setline(1, 'some text')
-  edit
-  call assert_equal('some text', getline(1))
-
-  bwipe!
-  au! BufEnter
+  " for historic reasons.  Also test other 'buftype' values.
+  for val in ['nofile',
+            \ 'nowrite',
+            \ 'acwrite',
+            \ 'quickfix',
+            \ 'help',
+            \ 'terminal',
+            \ 'prompt',
+            \ 'popup',
+            \ ]
+    new somefile
+    exe 'set buftype=' .. val
+    au BufEnter somefile call setline(1, 'some text')
+    edit
+    call assert_equal('some text', getline(1))
+    bwipe!
+    au! BufEnter
+  endfor
 endfunc
 
 " Closing a window might cause an endless loop
index 5a062166de065815ca3458b98f346f9197ba6f9e..caf6aa7d30745adff493c24ceb97bdd490e60edb 100644 (file)
@@ -255,4 +255,24 @@ func Test_deletebufline_select_mode()
   bwipe!
 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
index 03778f8ae02cae93bddd8284b15a3c0aef7670c5..d483b740f79610e5a57786e54431b2d7014cfe86 100644 (file)
@@ -2368,19 +2368,23 @@ func Test_bufadd_bufload()
   exe 'bwipe ' .. buf2
   call assert_equal(0, bufexists(buf2))
 
-  " when 'buftype' is "nofile" then bufload() does not read the file
-  bwipe! XotherName
-  let buf = bufadd('XotherName')
-  call setbufvar(buf, '&bt', 'nofile')
-  call bufload(buf)
-  call assert_equal([''], getbufline(buf, 1, '$'))
-
-  " 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, '$'))
+  " 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],
+            \ ['terminal', 0],
+            \ ['prompt', 0],
+            \ ['popup', 0],
+            \ ]
+    bwipe! XotherName
+    let buf = bufadd('XotherName')
+    call setbufvar(buf, '&bt', val[0])
+    call bufload(buf)
+    call assert_equal(val[1] ? ['some', 'text'] : [''], getbufline(buf, 1, '$'), val[0])
+  endfor
 
   bwipe someName
   bwipe XotherName
index e32f990bcb797f6140b695a7c67165c3bf0ae5bb..a0a72104649ba0215e2561c07c62e3e0808e37c7 100644 (file)
@@ -723,6 +723,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    276,
 /**/
     275,
 /**/