]> granicus.if.org Git - vim/commitdiff
patch 8.2.0275: some Ex code not covered by tests v8.2.0275
authorBram Moolenaar <Bram@vim.org>
Tue, 18 Feb 2020 20:54:41 +0000 (21:54 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 18 Feb 2020 20:54:41 +0000 (21:54 +0100)
Problem:    Some Ex code not covered by tests.
Solution:   Add test cases. (Yegappan Lakshmanan, closes #5659)

src/testdir/test_arglist.vim
src/testdir/test_autocmd.vim
src/testdir/test_excmd.vim
src/testdir/test_quickfix.vim
src/testdir/test_search.vim
src/testdir/test_swap.vim
src/testdir/test_window_cmd.vim
src/version.c

index 9513ad334c9c02e7294a18a511a102a92b67144c..af90ddc7926e206da2f217004dafba322aa14ff7 100644 (file)
@@ -519,6 +519,20 @@ func Test_quit_with_arglist()
   call term_sendkeys(buf, ":quit\n")
   call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
   call StopVimInTerminal(buf)
+
+  " Try :confirm quit with unedited files in arglist
+  let buf = RunVimInTerminal('', {'rows': 6})
+  call term_sendkeys(buf, ":set nomore\n")
+  call term_sendkeys(buf, ":args a b c\n")
+  call term_sendkeys(buf, ":confirm quit\n")
+  call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
+        \ term_getline(buf, 6))})
+  call term_sendkeys(buf, "N")
+  call term_sendkeys(buf, ":confirm quit\n")
+  call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
+        \ term_getline(buf, 6))})
+  call term_sendkeys(buf, "Y")
+  call StopVimInTerminal(buf)
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index 3b071049c23b005ab6497aee3597ece54611571f..a16329b8cd72328b6111e678a021223b1426c89f 100644 (file)
@@ -2358,4 +2358,28 @@ func Test_FileType_spell()
   setglobal spellfile=
 endfunc
 
+" Test closing a window or editing another buffer from a FileChangedRO handler
+" in a readonly buffer
+func Test_FileChangedRO_winclose()
+  augroup FileChangedROTest
+    au!
+    autocmd FileChangedRO * quit
+  augroup END
+  new
+  set readonly
+  call assert_fails('normal i', 'E788:')
+  close
+  augroup! FileChangedROTest
+
+  augroup FileChangedROTest
+    au!
+    autocmd FileChangedRO * edit Xfile
+  augroup END
+  new
+  set readonly
+  call assert_fails('normal i', 'E788:')
+  close
+  augroup! FileChangedROTest
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 2407f8eb1ee6066a28a0a1c7371152a0e94a58e2..472945d2537f986d1eea3386eb747dc1c06d1225 100644 (file)
@@ -238,6 +238,22 @@ func Test_confirm_cmd()
   call assert_equal(['foo4'], readfile('foo'))
   call assert_equal(['bar2'], readfile('bar'))
 
+  " Test for closing a window with a modified buffer
+  let buf = RunVimInTerminal('', {'rows': 20})
+  call term_sendkeys(buf, ":set nomore\n")
+  call term_sendkeys(buf, ":new\n")
+  call term_sendkeys(buf, ":call setline(1, 'abc')\n")
+  call term_sendkeys(buf, ":confirm close\n")
+  call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
+        \ term_getline(buf, 20))}, 1000)
+  call term_sendkeys(buf, "C")
+  call term_sendkeys(buf, ":confirm close\n")
+  call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
+        \ term_getline(buf, 20))}, 1000)
+  call term_sendkeys(buf, "N")
+  call term_sendkeys(buf, ":quit\n")
+  call StopVimInTerminal(buf)
+
   call delete('foo')
   call delete('bar')
 endfunc
index d3f2e3abd7bf423fe180dc767fe1ed54c53941c6..276719c1474d4eea858f9d0359d26b6ef5983c2a 100644 (file)
@@ -4195,6 +4195,20 @@ func Test_splitview()
   call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
   new | only
 
+  " Using :split or :vsplit from a quickfix window should behave like a :new
+  " or a :vnew command
+  copen
+  split
+  call assert_equal(3, winnr('$'))
+  let l = getwininfo()
+  call assert_equal([0, 0, 1], [l[0].quickfix, l[1].quickfix, l[2].quickfix])
+  close
+  copen
+  vsplit
+  let l = getwininfo()
+  call assert_equal([0, 0, 1], [l[0].quickfix, l[1].quickfix, l[2].quickfix])
+  new | only
+
   call delete('Xtestfile1')
   call delete('Xtestfile2')
 endfunc
index 9567aa468b2c1be5dbc097424fc309aa6f3d8106..afbea94e6b4684a88ad7672b2c35fdaf429062ae 100644 (file)
@@ -1515,4 +1515,31 @@ func Test_search_tilde_pat()
   call delete('Xresult')
 endfunc
 
+" Test for searching a pattern that is not present with 'nowrapscan'
+func Test_search_pat_not_found()
+  new
+  set nowrapscan
+  let @/ = '1abcxyz2'
+  call assert_fails('normal n', 'E385:')
+  call assert_fails('normal N', 'E384:')
+  set wrapscan&
+  close
+endfunc
+
+" Test for v:searchforward variable
+func Test_searchforward_var()
+  new
+  call setline(1, ['foo', '', 'foo'])
+  call cursor(2, 1)
+  let @/ = 'foo'
+  let v:searchforward = 0
+  normal N
+  call assert_equal(3, line('.'))
+  call cursor(2, 1)
+  let v:searchforward = 1
+  normal N
+  call assert_equal(1, line('.'))
+  close!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index aa67b430e6fb02e0f32aaaabc29d4602388fe608..7ce35ccaeddf05b20b454b259544722e0d346c17 100644 (file)
@@ -277,7 +277,6 @@ func Test_swap_recover_ext()
     autocmd SwapExists * let v:swapchoice = 'r'
   augroup END
 
-
   " Create a valid swapfile by editing a file with a special extension.
   split Xtest.scr
   call setline(1, ['one', 'two', 'three'])
@@ -309,3 +308,45 @@ func Test_swap_recover_ext()
   augroup END
   augroup! test_swap_recover_ext
 endfunc
+
+" Test for closing a split window automatically when a swap file is detected
+" and 'Q' is selected in the confirmation prompt.
+func Test_swap_split_win()
+  autocmd! SwapExists
+  augroup test_swap_splitwin
+    autocmd!
+    autocmd SwapExists * let v:swapchoice = 'q'
+  augroup END
+
+  " Create a valid swapfile by editing a file with a special extension.
+  split Xtest.scr
+  call setline(1, ['one', 'two', 'three'])
+  write  " file is written, not modified
+  write  " write again to make sure the swapfile is created
+  " read the swapfile as a Blob
+  let swapfile_name = swapname('%')
+  let swapfile_bytes = readfile(swapfile_name, 'B')
+
+  " Close and delete the file and recreate the swap file.
+  quit
+  call delete('Xtest.scr')
+  call writefile(swapfile_bytes, swapfile_name)
+  " Split edit the file again. This should fail to open the window
+  try
+    split Xtest.scr
+  catch
+    " E308 should be caught, not E306.
+    call assert_exception('E308:')  " Original file may have been changed
+  endtry
+  call assert_equal(1, winnr('$'))
+
+  call delete('Xtest.scr')
+  call delete(swapfile_name)
+
+  augroup test_swap_splitwin
+      autocmd!
+  augroup END
+  augroup! test_swap_splitwin
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index 362b0eb02a797cda1381e21eb689acb2738db2fa..77e58d2d0b7c54c19062de5f98b102c5c19a630c 100644 (file)
@@ -965,4 +965,12 @@ func Test_winpos_errors()
   call assert_fails('winpos 10', 'E466:')
 endfunc
 
+" Test for +cmd in a :split command
+func Test_split_cmd()
+  split +set\ readonly
+  call assert_equal(1, &readonly)
+  call assert_equal(2, winnr('$'))
+  close
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 679354768804bc79eb946acf36a4d1e09f893fad..41d021f7e8d3bb5356b84c5b5d90aa1317aff6cf 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    275,
 /**/
     274,
 /**/