11" Tests for the swap feature
22
3+ func s: swapname ()
4+ return trim (execute (' swapname' ))
5+ endfunc
6+
37" Tests for 'directory' option.
48func Test_swap_directory ()
59 if ! has (" unix" )
@@ -17,7 +21,7 @@ func Test_swap_directory()
1721 " Verify that the swap file doesn't exist in the current directory
1822 call assert_equal ([], glob (" .Xtest1*.swp" , 1 , 1 , 1 ))
1923 edit Xtest1
20- let swfname = split ( execute ( " swapname" ))[ 0 ]
24+ let swfname = s: swapname()
2125 call assert_equal ([swfname], glob (swfname, 1 , 1 , 1 ))
2226
2327 " './dir', swap file in a directory relative to the file
@@ -27,7 +31,7 @@ func Test_swap_directory()
2731 edit Xtest1
2832 call assert_equal ([], glob (swfname, 1 , 1 , 1 ))
2933 let swfname = " Xtest2/Xtest1.swp"
30- call assert_equal (swfname, split ( execute ( " swapname" ))[ 0 ] )
34+ call assert_equal (swfname, s: swapname() )
3135 call assert_equal ([swfname], glob (" Xtest2/*" , 1 , 1 , 1 ))
3236
3337 " 'dir', swap file in directory relative to the current dir
@@ -38,7 +42,7 @@ func Test_swap_directory()
3842 edit Xtest2/Xtest3
3943 call assert_equal ([" Xtest2/Xtest3" ], glob (" Xtest2/*" , 1 , 1 , 1 ))
4044 let swfname = " Xtest.je/Xtest3.swp"
41- call assert_equal (swfname, split ( execute ( " swapname" ))[ 0 ] )
45+ call assert_equal (swfname, s: swapname() )
4246 call assert_equal ([swfname], glob (" Xtest.je/*" , 1 , 1 , 1 ))
4347
4448 set dir &
@@ -70,7 +74,7 @@ func Test_swap_group()
7074 throw ' Skipped: cannot set second group on test file'
7175 else
7276 split Xtest
73- let swapname = substitute ( execute ( ' swapname ' ), ' [[:space:]] ' , ' ' , ' g ' )
77+ let swapname = s: swapname ( )
7478 call assert_match (' Xtest' , swapname )
7579 " Group of swapfile must now match original file.
7680 call assert_match (' ' . groups[1 ] . ' \d' , system (' ls -l ' . swapname ))
@@ -102,7 +106,7 @@ func Test_swapinfo()
102106 new Xswapinfo
103107 call setline (1 , [' one' , ' two' , ' three' ])
104108 w
105- let fname = trim ( execute ( ' swapname' ) )
109+ let fname = s: swapname( )
106110 call assert_match (' Xswapinfo' , fname)
107111 let info = swapinfo (fname)
108112
@@ -136,3 +140,24 @@ func Test_swapinfo()
136140 call assert_equal (' Not a swap file' , info.error )
137141 call delete (' Xnotaswapfile' )
138142endfunc
143+
144+ func Test_swapname ()
145+ edit Xtest1
146+ let expected = s: swapname ()
147+ call assert_equal (expected, swapname (' %' ))
148+
149+ new Xtest2
150+ let buf = bufnr (' %' )
151+ let expected = s: swapname ()
152+ wincmd p
153+ call assert_equal (expected, swapname (buf ))
154+
155+ new Xtest3
156+ setlocal noswapfile
157+ call assert_equal (' ' , swapname (' %' ))
158+
159+ bwipe!
160+ call delete (' Xtest1' )
161+ call delete (' Xtest2' )
162+ call delete (' Xtest3' )
163+ endfunc
0 commit comments