Bram Moolenaar | b782ba4 | 2018-08-07 21:39:28 +0200 | [diff] [blame] | 1 | " Tests for the backup function |
| 2 | |
| 3 | func Test_backup() |
Bram Moolenaar | efe0373 | 2018-08-09 22:26:38 +0200 | [diff] [blame] | 4 | set backup backupdir=. backupskip= |
Bram Moolenaar | b782ba4 | 2018-08-07 21:39:28 +0200 | [diff] [blame] | 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! |
Bram Moolenaar | efe0373 | 2018-08-09 22:26:38 +0200 | [diff] [blame] | 15 | set backup&vim backupdir&vim backupskip&vim |
Bram Moolenaar | b782ba4 | 2018-08-07 21:39:28 +0200 | [diff] [blame] | 16 | call delete('Xbackup.txt') |
| 17 | call delete('Xbackup.txt~') |
| 18 | endfunc |
| 19 | |
| 20 | func Test_backup2() |
Bram Moolenaar | efe0373 | 2018-08-09 22:26:38 +0200 | [diff] [blame] | 21 | set backup backupdir=.// backupskip= |
Bram Moolenaar | b782ba4 | 2018-08-07 21:39:28 +0200 | [diff] [blame] | 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('%') |
Bram Moolenaar | f8f88f8 | 2018-08-08 11:02:32 +0200 | [diff] [blame] | 32 | call assert_match('%testdir%Xbackup.txt\~', f) |
Bram Moolenaar | b782ba4 | 2018-08-07 21:39:28 +0200 | [diff] [blame] | 33 | bw! |
| 34 | bw! |
| 35 | call delete('Xbackup.txt') |
| 36 | call delete(f) |
Bram Moolenaar | efe0373 | 2018-08-09 22:26:38 +0200 | [diff] [blame] | 37 | set backup&vim backupdir&vim backupskip&vim |
Bram Moolenaar | b782ba4 | 2018-08-07 21:39:28 +0200 | [diff] [blame] | 38 | endfunc |
| 39 | |
| 40 | func Test_backup2_backupcopy() |
Bram Moolenaar | efe0373 | 2018-08-09 22:26:38 +0200 | [diff] [blame] | 41 | set backup backupdir=.// backupcopy=yes backupskip= |
Bram Moolenaar | b782ba4 | 2018-08-07 21:39:28 +0200 | [diff] [blame] | 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('%') |
Bram Moolenaar | f8f88f8 | 2018-08-08 11:02:32 +0200 | [diff] [blame] | 52 | call assert_match('%testdir%Xbackup.txt\~', f) |
Bram Moolenaar | b782ba4 | 2018-08-07 21:39:28 +0200 | [diff] [blame] | 53 | bw! |
| 54 | bw! |
| 55 | call delete('Xbackup.txt') |
| 56 | call delete(f) |
Bram Moolenaar | efe0373 | 2018-08-09 22:26:38 +0200 | [diff] [blame] | 57 | set backup&vim backupdir&vim backupcopy&vim backupskip&vim |
Bram Moolenaar | b782ba4 | 2018-08-07 21:39:28 +0200 | [diff] [blame] | 58 | endfunc |