summaryrefslogtreecommitdiff
path: root/src/testdir/test_delete.vim
blob: 3cf26234dcf02fbdbebb76a6dcf3ff9f13dcb437 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
" Test for delete().

func Test_file_delete()
  split Xfile
  call setline(1, ['a', 'b'])
  wq
  call assert_equal(['a', 'b'], readfile('Xfile'))
  call assert_equal(0, delete('Xfile'))
  call assert_fails('call readfile("Xfile")', 'E484:')
  call assert_equal(-1, delete('Xfile'))
endfunc

func Test_dir_delete()
  call mkdir('Xdir1')
  call assert_true(isdirectory('Xdir1'))
  call assert_equal(0, delete('Xdir1', 'd'))
  call assert_false(isdirectory('Xdir1'))
  call assert_equal(-1, delete('Xdir1', 'd'))
endfunc

func Test_recursive_delete()
  call mkdir('Xdir1')
  call mkdir('Xdir1/subdir')
  call mkdir('Xdir1/empty')
  split Xdir1/Xfile
  call setline(1, ['a', 'b'])
  w
  w Xdir1/subdir/Xfile
  close
  call assert_true(isdirectory('Xdir1'))
  call assert_equal(['a', 'b'], readfile('Xdir1/Xfile'))
  call assert_true(isdirectory('Xdir1/subdir'))
  call assert_equal(['a', 'b'], readfile('Xdir1/subdir/Xfile'))
  call assert_true(isdirectory('Xdir1/empty'))
  call assert_equal(0, delete('Xdir1', 'rf'))
  call assert_false(isdirectory('Xdir1'))
  call assert_equal(-1, delete('Xdir1', 'd'))
endfunc

func Test_symlink_delete()
  if !has('unix')
    return
  endif
  split Xfile
  call setline(1, ['a', 'b'])
  wq
  silent !ln -s Xfile Xlink
  " Delete the link, not the file
  call assert_equal(0, delete('Xlink'))
  call assert_equal(-1, delete('Xlink'))
  call assert_equal(0, delete('Xfile'))
endfunc

func Test_symlink_dir_delete()
  if !has('unix')
    return
  endif
  call mkdir('Xdir1')
  silent !ln -s Xdir1 Xlink
  call assert_true(isdirectory('Xdir1'))
  call assert_true(isdirectory('Xlink'))
  " Delete the link, not the directory
  call assert_equal(0, delete('Xlink'))
  call assert_equal(-1, delete('Xlink'))
  call assert_equal(0, delete('Xdir1', 'd'))
endfunc

func Test_symlink_recursive_delete()
  if !has('unix')
    return
  endif
  call mkdir('Xdir3')
  call mkdir('Xdir3/subdir')
  call mkdir('Xdir4')
  split Xdir3/Xfile
  call setline(1, ['a', 'b'])
  w
  w Xdir3/subdir/Xfile
  w Xdir4/Xfile
  close
  silent !ln -s ../Xdir4 Xdir3/Xlink

  call assert_true(isdirectory('Xdir3'))
  call assert_equal(['a', 'b'], readfile('Xdir3/Xfile'))
  call assert_true(isdirectory('Xdir3/subdir'))
  call assert_equal(['a', 'b'], readfile('Xdir3/subdir/Xfile'))
  call assert_true(isdirectory('Xdir4'))
  call assert_true(isdirectory('Xdir3/Xlink'))
  call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))

  call assert_equal(0, delete('Xdir3', 'rf'))
  call assert_false(isdirectory('Xdir3'))
  call assert_equal(-1, delete('Xdir3', 'd'))
  " symlink is deleted, not the directory it points to
  call assert_true(isdirectory('Xdir4'))
  call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))
  call assert_equal(0, delete('Xdir4/Xfile'))
  call assert_equal(0, delete('Xdir4', 'd'))
endfunc