changeset 18233:7d147c191ef7 v8.1.2111

patch 8.1.2111: viminfo file not sufficiently tested Commit: https://github.com/vim/vim/commit/2a8d3b8997d4fe94bc9c02ae04e873eab2f13b09 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Oct 4 21:20:25 2019 +0200 patch 8.1.2111: viminfo file not sufficiently tested Problem: Viminfo file not sufficiently tested. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5009)
author Bram Moolenaar <Bram@vim.org>
date Fri, 04 Oct 2019 21:30:04 +0200
parents 4baa5df0f47e
children 636e37695b55
files src/testdir/test_viminfo.vim src/version.c
diffstat 2 files changed, 196 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_viminfo.vim
+++ b/src/testdir/test_viminfo.vim
@@ -40,6 +40,9 @@ function Test_viminfo_read_and_write()
 endfunc
 
 func Test_global_vars()
+  let g:MY_GLOBAL_STRING = "Vim Editor"
+  let g:MY_GLOBAL_NUM = 345
+  let g:MY_GLOBAL_FLOAT = 3.14
   let test_dict = {'foo': 1, 'bar': 0, 'longvarible': 1000}
   let g:MY_GLOBAL_DICT = test_dict
   " store a really long list, so line wrapping will occur in viminfo file
@@ -59,6 +62,9 @@ func Test_global_vars()
   set viminfo='100,<50,s10,h,!,nviminfo
   wv! Xviminfo
 
+  unlet g:MY_GLOBAL_STRING
+  unlet g:MY_GLOBAL_NUM
+  unlet g:MY_GLOBAL_FLOAT
   unlet g:MY_GLOBAL_DICT
   unlet g:MY_GLOBAL_LIST
   unlet g:MY_GLOBAL_BLOB
@@ -68,6 +74,9 @@ func Test_global_vars()
   unlet g:MY_GLOBAL_NONE
 
   rv! Xviminfo
+  call assert_equal("Vim Editor", g:MY_GLOBAL_STRING)
+  call assert_equal(345, g:MY_GLOBAL_NUM)
+  call assert_equal(3.14, g:MY_GLOBAL_FLOAT)
   call assert_equal(test_dict, g:MY_GLOBAL_DICT)
   call assert_equal(test_list, g:MY_GLOBAL_LIST)
   call assert_equal(test_blob, g:MY_GLOBAL_BLOB)
@@ -221,6 +230,7 @@ func Test_viminfo_registers()
     call add(l, 'something')
   endfor
   call setreg('d', l, 'l')
+  call setreg('e', "abc\<C-V>xyz")
   wviminfo Xviminfo
 
   call test_settime(10)
@@ -231,6 +241,7 @@ func Test_viminfo_registers()
   call setreg('c', 'keep', 'l')
   call test_settime(30)
   call setreg('d', 'drop', 'l')
+  call setreg('e', 'drop')
   rviminfo Xviminfo
 
   call assert_equal("", getreg('a'))
@@ -241,6 +252,7 @@ func Test_viminfo_registers()
   call assert_equal("V", getregtype('c'))
   call assert_equal(l, getreg('d', 1, 1))
   call assert_equal("V", getregtype('d'))
+  call assert_equal("abc\<C-V>xyz", getreg('e'))
 
   " Length around 440 switches to line continuation.
   let len = 434
@@ -514,12 +526,41 @@ func Test_viminfo_file_mark_zero_time()
   delmark B
 endfunc
 
+" Test for saving and restoring file marks in unloaded buffers
+func Test_viminfo_file_mark_unloaded_buf()
+  let save_viminfo = &viminfo
+  set viminfo&vim
+  call writefile(repeat(['vim'], 10), 'Xfile1')
+  %bwipe
+  edit! Xfile1
+  call setpos("'u", [0, 3, 1, 0])
+  call setpos("'v", [0, 5, 1, 0])
+  enew
+  wviminfo Xviminfo
+  %bwipe
+  edit Xfile1
+  rviminfo! Xviminfo
+  call assert_equal([0, 3, 1, 0], getpos("'u"))
+  call assert_equal([0, 5, 1, 0], getpos("'v"))
+  %bwipe
+  call delete('Xfile1')
+  call delete('Xviminfo')
+  let &viminfo = save_viminfo
+endfunc
+
 func Test_viminfo_oldfiles()
   let v:oldfiles = []
   let lines = [
 	\ '# comment line',
 	\ '*encoding=utf-8',
 	\ '',
+	\ ':h viminfo',
+	\ '?/session',
+	\ '=myvar',
+	\ '@123',
+	\ '',
+	\ "'E  2  0  /tmp/nothing",
+	\ '',
 	\ "> /tmp/file_one.txt",
 	\ "\t\"\t11\t0",
 	\ "",
@@ -531,9 +572,15 @@ func Test_viminfo_oldfiles()
 	\ "",
 	\ ]
   call writefile(lines, 'Xviminfo')
+  delmark E
   rviminfo! Xviminfo
   call delete('Xviminfo')
 
+  call assert_equal('h viminfo', histget(':'))
+  call assert_equal('session', histget('/'))
+  call assert_equal('myvar', histget('='))
+  call assert_equal('123', histget('@'))
+  call assert_equal(2, line("'E"))
   call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt', '3: /tmp/another.txt'], filter(split(execute('oldfiles'), "\n"), {i, v -> v =~ '/tmp/'}))
   call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt'], filter(split(execute('filter file_ oldfiles'), "\n"), {i, v -> v =~ '/tmp/'}))
   call assert_equal(['3: /tmp/another.txt'], filter(split(execute('filter /another/ oldfiles'), "\n"), {i, v -> v =~ '/tmp/'}))
@@ -543,4 +590,151 @@ func Test_viminfo_oldfiles()
   browse oldfiles
   call assert_equal("/tmp/another.txt", expand("%"))
   bwipe
+  delmark E
 endfunc
+
+" Test for storing and restoring buffer list in 'viminfo'
+func Test_viminfo_bufferlist()
+  " If there are arguments, then :rviminfo doesn't read the buffer list.
+  " Need to delete all the arguments for :rviminfo to work.
+  %argdelete
+
+  edit Xfile1
+  edit Xfile2
+  set viminfo-=%
+  wviminfo Xviminfo
+  %bwipe
+  rviminfo Xviminfo
+  call assert_equal(1, len(getbufinfo()))
+
+  edit Xfile1
+  edit Xfile2
+  set viminfo^=%
+  wviminfo Xviminfo
+  %bwipe
+  rviminfo Xviminfo
+  let l = getbufinfo()
+  call assert_equal(3, len(l))
+  call assert_equal('Xfile1', bufname(l[1].bufnr))
+  call assert_equal('Xfile2', bufname(l[2].bufnr))
+
+  call delete('Xviminfo')
+  %bwipe
+  set viminfo-=%
+endfunc
+
+" Test for errors in a viminfo file
+func Test_viminfo_error()
+  " Non-existing viminfo files
+  call assert_fails('rviminfo xyz', 'E195:')
+
+  " Illegal starting character
+  call writefile(["a 123"], 'Xviminfo')
+  call assert_fails('rv Xviminfo', 'E575:')
+
+  " Illegal register name in the viminfo file
+  call writefile(['"@	LINE	0'], 'Xviminfo')
+  call assert_fails('rv Xviminfo', 'E577:')
+
+  " Invalid file mark line
+  call writefile(['>', '@'], 'Xviminfo')
+  call assert_fails('rv Xviminfo', 'E576:')
+
+  " Too many errors in viminfo file
+  call writefile(repeat(["a 123"], 15), 'Xviminfo')
+  call assert_fails('rv Xviminfo', 'E136:')
+
+  call writefile(['>'] + repeat(['@'], 10), 'Xviminfo')
+  call assert_fails('rv Xviminfo', 'E136:')
+
+  call writefile(repeat(['"@'], 15), 'Xviminfo')
+  call assert_fails('rv Xviminfo', 'E136:')
+
+  call delete('Xviminfo')
+endfunc
+
+" Test for saving and restoring last substitute string in viminfo
+func Test_viminfo_lastsub()
+  enew
+  call append(0, "blue blue blue")
+  call cursor(1, 1)
+  s/blue/green/
+  wviminfo Xviminfo
+  s/blue/yellow/
+  rviminfo! Xviminfo
+  &
+  call assert_equal("green yellow green", getline(1))
+  enew!
+  call delete('Xviminfo')
+endfunc
+
+" Test saving and restoring the register values using the older method
+func Test_viminfo_registers_old()
+  let lines = [
+	\ '# Viminfo version',
+	\ '|1,1',
+	\ '',
+	\ '*encoding=utf-8',
+	\ '',
+	\ '# Registers:',
+	\ '""0 CHAR  0',
+	\ '	Vim',
+	\ '"a  CHAR  0',
+	\ '	red',
+	\ '"m@ CHAR  0',
+	\ "	:echo 'Hello'\<CR>",
+	\ "",
+	\ ]
+  call writefile(lines, 'Xviminfo')
+  let @a = 'one'
+  let @b = 'two'
+  let @m = 'three'
+  let @" = 'four'
+  let @t = ":echo 'Unix'\<CR>"
+  silent! normal @t
+  rviminfo! Xviminfo
+  call assert_equal('red', getreg('a'))
+  call assert_equal('two', getreg('b'))
+  call assert_equal(":echo 'Hello'\<CR>", getreg('m'))
+  call assert_equal('Vim', getreg('"'))
+  call assert_equal("\nHello", execute('normal @@'))
+  call delete('Xviminfo')
+  let @" = ''
+endfunc
+
+" Test for saving and restoring large number of lines in a register
+func Test_viminfo_large_register()
+  let save_viminfo = &viminfo
+  set viminfo&vim
+  set viminfo-=<50
+  set viminfo+=<200
+  let lines = ['"r	CHAR	0']
+  call extend(lines, repeat(["\tsun is rising"], 200))
+  call writefile(lines, 'Xviminfo')
+  let @r = ''
+  rviminfo! Xviminfo
+  call assert_equal(join(repeat(["sun is rising"], 200), "\n"), @r)
+  call delete('Xviminfo')
+  let &viminfo = save_viminfo
+endfunc
+
+" Test for setting 'viminfofile' to NONE
+func Test_viminfofile_none()
+  set viminfofile=NONE
+  wviminfo Xviminfo
+  call assert_false(filereadable('Xviminfo'))
+  call writefile([''], 'Xviminfo')
+  call assert_fails('rviminfo Xviminfo', 'E195:')
+  call delete('Xviminfo')
+endfunc
+
+" Test for an unwritable 'viminfo' file
+func Test_viminfo_readonly()
+  if !has('unix')
+      return
+  endif
+  call writefile([''], 'Xviminfo')
+  call setfperm('Xviminfo', 'r-x------')
+  call assert_fails('wviminfo Xviminfo', 'E137:')
+  call delete('Xviminfo')
+endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2111,
+/**/
     2110,
 /**/
     2109,