diff src/testdir/test_edit.vim @ 20861:1725bb56178a v8.2.0982

patch 8.2.0982: insufficient testing for reading/writing files Commit: https://github.com/vim/vim/commit/b340baed9f7fc1c19a0742e2214d54982190c15e Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jun 15 19:51:56 2020 +0200 patch 8.2.0982: insufficient testing for reading/writing files Problem: Insufficient testing for reading/writing files. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6257) Add "ui_delay" to test_override() and use it for the CTRL-O test.
author Bram Moolenaar <Bram@vim.org>
date Mon, 15 Jun 2020 20:00:05 +0200
parents 045442aa392b
children 505d97ea54da
line wrap: on
line diff
--- a/src/testdir/test_edit.vim
+++ b/src/testdir/test_edit.vim
@@ -1486,6 +1486,7 @@ func Test_edit_InsertLeave_undo()
   bwipe!
   au! InsertLeave
   call delete('XtestUndo')
+  call delete(undofile('XtestUndo'))
   set undofile&
 endfunc
 
@@ -1557,11 +1558,11 @@ func Test_edit_noesckeys()
 endfunc
 
 " Test for running an invalid ex command in insert mode using CTRL-O
-" Note that vim has a hard-coded sleep of 3 seconds. So this test will take
-" more than 3 seconds to complete.
 func Test_edit_ctrl_o_invalid_cmd()
   new
   set showmode showcmd
+  " Avoid a sleep of 3 seconds. Zero might have side effects.
+  call test_override('ui_delay', 50)
   let caught_e492 = 0
   try
     call feedkeys("i\<C-O>:invalid\<CR>abc\<Esc>", "xt")
@@ -1571,7 +1572,115 @@ func Test_edit_ctrl_o_invalid_cmd()
   call assert_equal(1, caught_e492)
   call assert_equal('abc', getline(1))
   set showmode& showcmd&
+  call test_override('ui_delay', 0)
+  close!
+endfunc
+
+" Test for editing a file with a very long name
+func Test_edit_illegal_filename()
+  CheckEnglish
+  new
+  redir => msg
+  exe 'edit ' . repeat('f', 5000)
+  redir END
+  call assert_match("Illegal file name$", split(msg, "\n")[0])
+  close!
+endfunc
+
+" Test for editing a file using invalid file encoding
+func Test_edit_invalid_encoding()
+  CheckEnglish
+  call writefile([], 'Xfile')
+  redir => msg
+  new ++enc=axbyc Xfile
+  redir END
+  call assert_match('\[NOT converted\]', msg)
+  call delete('Xfile')
   close!
 endfunc
 
+" Test for the "charconvert" option
+func Test_edit_charconvert()
+  CheckEnglish
+  call writefile(['one', 'two'], 'Xfile')
+
+  " set 'charconvert' to a non-existing function
+  set charconvert=NonExitingFunc()
+  new
+  let caught_e117 = v:false
+  try
+    redir => msg
+    edit ++enc=axbyc Xfile
+  catch /E117:/
+    let caught_e117 = v:true
+  finally
+    redir END
+  endtry
+  call assert_true(caught_e117)
+  call assert_equal(['one', 'two'], getline(1, '$'))
+  call assert_match("Conversion with 'charconvert' failed", msg)
+  close!
+  set charconvert&
+
+  " 'charconvert' function doesn't create a output file
+  func Cconv1()
+  endfunc
+  set charconvert=Cconv1()
+  new
+  redir => msg
+  edit ++enc=axbyc Xfile
+  redir END
+  call assert_equal(['one', 'two'], getline(1, '$'))
+  call assert_match("can't read output of 'charconvert'", msg)
+  close!
+  delfunc Cconv1
+  set charconvert&
+
+  " 'charconvert' function to convert to upper case
+  func Cconv2()
+    let data = readfile(v:fname_in)
+    call map(data, 'toupper(v:val)')
+    call writefile(data, v:fname_out)
+  endfunc
+  set charconvert=Cconv2()
+  new Xfile
+  write ++enc=ucase Xfile1
+  call assert_equal(['ONE', 'TWO'], readfile('Xfile1'))
+  call delete('Xfile1')
+  close!
+  delfunc Cconv2
+  set charconvert&
+
+  " 'charconvert' function removes the input file
+  func Cconv3()
+    call delete(v:fname_in)
+  endfunc
+  set charconvert=Cconv3()
+  new
+  call assert_fails('edit ++enc=lcase Xfile', 'E202:')
+  call assert_equal([''], getline(1, '$'))
+  close!
+  delfunc Cconv3
+  set charconvert&
+
+  call delete('Xfile')
+endfunc
+
+" Test for editing a file without read permission
+func Test_edit_file_no_read_perm()
+  CheckUnix
+  CheckNotBSD
+  call writefile(['one', 'two'], 'Xfile')
+  call setfperm('Xfile', '-w-------')
+  new
+  redir => msg
+  edit Xfile
+  redir END
+  call assert_equal(1, &readonly)
+  call assert_equal([''], getline(1, '$'))
+  call assert_match('\[Permission Denied\]', msg)
+  close!
+  call delete('Xfile')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab