1" Test :recover 2 3func Test_recover_root_dir() 4 " This used to access invalid memory. 5 split Xtest 6 set dir=/ 7 call assert_fails('recover', 'E305:') 8 close! 9 10 if has('win32') || filewritable('/') == 2 11 " can write in / directory on MS-Windows 12 set dir=/notexist/ 13 endif 14 call assert_fails('split Xtest', 'E303:') 15 16 " No error with empty 'directory' setting. 17 set directory= 18 split XtestOK 19 close! 20 21 set dir& 22endfunc 23 24" Inserts 10000 lines with text to fill the swap file with two levels of pointer 25" blocks. Then recovers from the swap file and checks all text is restored. 26" 27" We need about 10000 lines of 100 characters to get two levels of pointer 28" blocks. 29func Test_swap_file() 30 set fileformat=unix undolevels=-1 31 edit! Xtest 32 let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789" 33 let i = 1 34 let linecount = 10000 35 while i <= linecount 36 call append(i - 1, i . text) 37 let i += 1 38 endwhile 39 $delete 40 preserve 41 " get the name of the swap file 42 let swname = split(execute("swapname"))[0] 43 let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '') 44 " make a copy of the swap file in Xswap 45 set binary 46 exe 'sp ' . swname 47 w! Xswap 48 set nobinary 49 new 50 only! 51 bwipe! Xtest 52 call rename('Xswap', swname) 53 recover Xtest 54 call delete(swname) 55 let linedollar = line('$') 56 call assert_equal(linecount, linedollar) 57 if linedollar < linecount 58 let linecount = linedollar 59 endif 60 let i = 1 61 while i <= linecount 62 call assert_equal(i . text, getline(i)) 63 let i += 1 64 endwhile 65 66 set undolevels& 67 enew! | only 68endfunc 69