blob: 3187b588781f52e28526dbd94b1d7aedd38cb4df [file] [log] [blame]
Bram Moolenaarb782ba42018-08-07 21:39:28 +02001" Tests for the backup function
2
3func Test_backup()
4 set backup backupdir=.
5 new
6 call setline(1, ['line1', 'line2'])
7 :f Xbackup.txt
8 :w! Xbackup.txt
9 " backup file is only created after
10 " writing a second time (before overwriting)
11 :w! Xbackup.txt
12 let l = readfile('Xbackup.txt~')
13 call assert_equal(['line1', 'line2'], l)
14 bw!
15 set backup&vim backupdir&vim
16 call delete('Xbackup.txt')
17 call delete('Xbackup.txt~')
18endfunc
19
20func Test_backup2()
21 set backup backupdir=.//
22 new
23 call setline(1, ['line1', 'line2', 'line3'])
24 :f Xbackup.txt
25 :w! Xbackup.txt
26 " backup file is only created after
27 " writing a second time (before overwriting)
28 :w! Xbackup.txt
29 sp *Xbackup.txt~
30 call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
31 let f=expand('%')
32 call assert_match('src%testdir%Xbackup.txt\~', f)
33 bw!
34 bw!
35 call delete('Xbackup.txt')
36 call delete(f)
37 set backup&vim backupdir&vim
38endfunc
39
40func Test_backup2_backupcopy()
41 set backup backupdir=.// backupcopy=yes
42 new
43 call setline(1, ['line1', 'line2', 'line3'])
44 :f Xbackup.txt
45 :w! Xbackup.txt
46 " backup file is only created after
47 " writing a second time (before overwriting)
48 :w! Xbackup.txt
49 sp *Xbackup.txt~
50 call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
51 let f=expand('%')
52 call assert_match('src%testdir%Xbackup.txt\~', f)
53 bw!
54 bw!
55 call delete('Xbackup.txt')
56 call delete(f)
57 set backup&vim backupdir&vim backupcopy&vim
58endfunc