diff src/testdir/test_swap.vim @ 14778:20653d6f3d95 v8.1.0401

patch 8.1.0401: can't get swap name of another buffer commit https://github.com/vim/vim/commit/110bd60985c31e8978e9b071e2179f4233ef8557 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 16 18:46:59 2018 +0200 patch 8.1.0401: can't get swap name of another buffer Problem: Can't get swap name of another buffer. Solution: Add swapname(). (Ozaki Kiichi, closes https://github.com/vim/vim/issues/3441)
author Christian Brabandt <cb@256bit.org>
date Sun, 16 Sep 2018 19:00:06 +0200
parents 0c47880f3d95
children f315ab10d579
line wrap: on
line diff
--- a/src/testdir/test_swap.vim
+++ b/src/testdir/test_swap.vim
@@ -1,5 +1,9 @@
 " Tests for the swap feature
 
+func s:swapname()
+  return trim(execute('swapname'))
+endfunc
+
 " Tests for 'directory' option.
 func Test_swap_directory()
   if !has("unix")
@@ -17,7 +21,7 @@ func Test_swap_directory()
   " Verify that the swap file doesn't exist in the current directory
   call assert_equal([], glob(".Xtest1*.swp", 1, 1, 1))
   edit Xtest1
-  let swfname = split(execute("swapname"))[0]
+  let swfname = s:swapname()
   call assert_equal([swfname], glob(swfname, 1, 1, 1))
 
   " './dir', swap file in a directory relative to the file
@@ -27,7 +31,7 @@ func Test_swap_directory()
   edit Xtest1
   call assert_equal([], glob(swfname, 1, 1, 1))
   let swfname = "Xtest2/Xtest1.swp"
-  call assert_equal(swfname, split(execute("swapname"))[0])
+  call assert_equal(swfname, s:swapname())
   call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1))
 
   " 'dir', swap file in directory relative to the current dir
@@ -38,7 +42,7 @@ func Test_swap_directory()
   edit Xtest2/Xtest3
   call assert_equal(["Xtest2/Xtest3"], glob("Xtest2/*", 1, 1, 1))
   let swfname = "Xtest.je/Xtest3.swp"
-  call assert_equal(swfname, split(execute("swapname"))[0])
+  call assert_equal(swfname, s:swapname())
   call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1))
 
   set dir&
@@ -70,7 +74,7 @@ func Test_swap_group()
 	throw 'Skipped: cannot set second group on test file'
       else
 	split Xtest
-	let swapname = substitute(execute('swapname'), '[[:space:]]', '', 'g')
+	let swapname = s:swapname()
 	call assert_match('Xtest', swapname)
 	" Group of swapfile must now match original file.
 	call assert_match(' ' . groups[1] . ' \d', system('ls -l ' . swapname))
@@ -102,7 +106,7 @@ func Test_swapinfo()
   new Xswapinfo
   call setline(1, ['one', 'two', 'three'])
   w
-  let fname = trim(execute('swapname'))
+  let fname = s:swapname()
   call assert_match('Xswapinfo', fname)
   let info = swapinfo(fname)
 
@@ -136,3 +140,24 @@ func Test_swapinfo()
   call assert_equal('Not a swap file', info.error)
   call delete('Xnotaswapfile')
 endfunc
+
+func Test_swapname()
+  edit Xtest1
+  let expected = s:swapname()
+  call assert_equal(expected, swapname('%'))
+
+  new Xtest2
+  let buf = bufnr('%')
+  let expected = s:swapname()
+  wincmd p
+  call assert_equal(expected, swapname(buf))
+
+  new Xtest3
+  setlocal noswapfile
+  call assert_equal('', swapname('%'))
+
+  bwipe!
+  call delete('Xtest1')
+  call delete('Xtest2')
+  call delete('Xtest3')
+endfunc