@@ -146,6 +146,16 @@ func Test_recover_multiple_swap_files()
146146 % bw !
147147 call feedkeys (" :recover Xfile1\<CR> 3\<CR> q" , ' xt' )
148148 call assert_equal ([' a' , ' b' , ' c' ], getline (1 , ' $' ))
149+ " try using out-of-range number to select a swap file
150+ bw !
151+ call feedkeys (" :recover Xfile1\<CR> 4\<CR> q" , ' xt' )
152+ call assert_equal (' Xfile1' , @% )
153+ call assert_equal ([' ' ], getline (1 , ' $' ))
154+ bw !
155+ call feedkeys (" :recover Xfile1\<CR> 0\<CR> q" , ' xt' )
156+ call assert_equal (' Xfile1' , @% )
157+ call assert_equal ([' ' ], getline (1 , ' $' ))
158+ bw !
149159
150160 call delete (' .Xfile1.swm' )
151161 call delete (' .Xfile1.swn' )
@@ -166,6 +176,8 @@ func Test_recover_empty_swap_file()
166176endfunc
167177
168178" Test for :recover using a corrupted swap file
179+ " Refer to the comments in the memline.c file for the swap file headers
180+ " definition.
169181func Test_recover_corrupted_swap_file ()
170182 CheckUnix
171183
@@ -197,26 +209,91 @@ func Test_recover_corrupted_swap_file()
197209 call writefile (b , sn )
198210 let msg = execute (' recover Xfile1' )
199211 call assert_match (' the file has been damaged' , msg)
212+ call assert_equal (' Xfile1' , @% )
213+ call assert_equal ([' ' ], getline (1 , ' $' ))
214+ bw !
215+
216+ " reduce the page size
217+ let b = copy (save_b)
218+ let b [12 :15 ] = 0z00010000
219+ call writefile (b , sn )
220+ let msg = execute (' recover Xfile1' )
221+ call assert_match (' page size is smaller than minimum value' , msg)
222+ call assert_equal (' Xfile1' , @% )
223+ call assert_equal ([' ' ], getline (1 , ' $' ))
200224 bw !
201225
202226 " clear the pointer ID
203227 let b = copy (save_b)
204228 let b [4096 :4097 ] = 0z0000
205229 call writefile (b , sn )
206230 call assert_fails (' recover Xfile1' , ' E310:' )
231+ call assert_equal (' Xfile1' , @% )
232+ call assert_equal ([' ' ], getline (1 , ' $' ))
233+ bw !
234+
235+ " set the number of pointers in a pointer block to zero
236+ let b = copy (save_b)
237+ let b [4098 :4099 ] = 0z0000
238+ call writefile (b , sn )
239+ call assert_fails (' recover Xfile1' , ' E312:' )
240+ call assert_equal (' Xfile1' , @% )
241+ call assert_equal ([' ???EMPTY BLOCK' ], getline (1 , ' $' ))
242+ bw !
243+
244+ " set the block number in a pointer entry to a negative number
245+ let b = copy (save_b)
246+ let b [4104 :4111 ] = 0z00000000 .00000080
247+ call writefile (b , sn )
248+ call assert_fails (' recover Xfile1' , ' E312:' )
249+ call assert_equal (' Xfile1' , @% )
250+ call assert_equal ([' ???LINES MISSING' ], getline (1 , ' $' ))
207251 bw !
208252
209253 " clear the data block ID
210254 let b = copy (save_b)
211255 let b [8192 :8193 ] = 0z0000
212256 call writefile (b , sn )
213257 call assert_fails (' recover Xfile1' , ' E312:' )
258+ call assert_equal (' Xfile1' , @% )
259+ call assert_equal ([' ???BLOCK MISSING' ], getline (1 , ' $' ))
260+ bw !
261+
262+ " set the number of lines in the data block to zero
263+ let b = copy (save_b)
264+ let b [8208 :8211 ] = 0z00000000
265+ call writefile (b , sn )
266+ call assert_fails (' recover Xfile1' , ' E312:' )
267+ call assert_equal (' Xfile1' , @% )
268+ call assert_equal ([' ??? from here until ???END lines may have been inserted/deleted' ,
269+ \ ' ???END' ], getline (1 , ' $' ))
270+ bw !
271+
272+ " use an invalid text start for the lines in a data block
273+ let b = copy (save_b)
274+ let b [8216 :8219 ] = 0z00000000
275+ call writefile (b , sn )
276+ call assert_fails (' recover Xfile1' , ' E312:' )
277+ call assert_equal (' Xfile1' , @% )
278+ call assert_equal ([' ???' ], getline (1 , ' $' ))
279+ bw !
280+
281+ " use an incorrect text end (db_txt_end) for the data block
282+ let b = copy (save_b)
283+ let b [8204 :8207 ] = 0z80000000
284+ call writefile (b , sn )
285+ call assert_fails (' recover Xfile1' , ' E312:' )
286+ call assert_equal (' Xfile1' , @% )
287+ call assert_equal ([' ??? from here until ???END lines may be messed up' , ' ' ,
288+ \ ' ???END' ], getline (1 , ' $' ))
214289 bw !
215290
216291 " remove the data block
217292 let b = copy (save_b)
218293 call writefile (b [:8191 ], sn )
219294 call assert_fails (' recover Xfile1' , ' E312:' )
295+ call assert_equal (' Xfile1' , @% )
296+ call assert_equal ([' ???MANY LINES MISSING' ], getline (1 , ' $' ))
220297 endif
221298
222299 bw !
@@ -290,4 +367,27 @@ func Test_recover_unmodified_file()
290367 call delete (' .Xfile1.swz' )
291368endfunc
292369
370+ " Test for recovering a file when editing a symbolically linked file
371+ func Test_recover_symbolic_link ()
372+ CheckUnix
373+ call writefile ([' aaa' , ' bbb' , ' ccc' ], ' Xfile1' )
374+ silent ! ln -s Xfile1 Xfile2
375+ edit Xfile2
376+ call assert_equal (' .Xfile1.swp' , fnamemodify (swapname (' ' ), ' :t' ))
377+ preserve
378+ let b = readblob (' .Xfile1.swp' )
379+ % bw !
380+ call writefile ([], ' Xfile1' )
381+ call writefile (b , ' .Xfile1.swp' )
382+ silent ! recover Xfile2
383+ call assert_equal ([' aaa' , ' bbb' , ' ccc' ], getline (1 , ' $' ))
384+ call assert_true (&modified )
385+ update
386+ % bw !
387+ call assert_equal ([' aaa' , ' bbb' , ' ccc' ], readfile (' Xfile1' ))
388+ call delete (' Xfile1' )
389+ call delete (' Xfile2' )
390+ call delete (' .Xfile1.swp' )
391+ endfunc
392+
293393" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments