blob: 4e8eff4edf02cf0c17e49e7d66cd071b0c689707 [file] [log] [blame]
Damiend7af21e2024-08-05 20:24:11 +02001so check.vim
2
3CheckExecutable unzip
4
5if 0 " Find uncovered line
6 profile start zip_profile
7 profile! file */zip*.vim
8endif
9
10runtime plugin/zipPlugin.vim
11
12def Test_zip_basic()
13 var _sl = &shellslash
14 set noshellslash
15
16 ### get our zip file
17 if !filecopy("samples/test.zip", "X.zip")
18 assert_report("Can't copy samples/test.zip")
19 return
20 endif
21 defer delete("X.zip")
22
23 e X.zip
24
25 ### Check header
26 assert_match('^" zip\.vim version v\d\+', getline(1))
27 assert_match('^" Browsing zipfile .*/X.zip', getline(2))
28 assert_match('^" Select a file with cursor and press ENTER', getline(3))
29 assert_match('^$', getline(4))
30
31 ### Check files listing
32 assert_equal(["Xzip/", "Xzip/dir/", "Xzip/file.txt"], getline(5, 7))
33
34 ### Check ENTER on header
35 :1
36 exe ":normal \<cr>"
37 assert_equal("X.zip", @%)
38
39 ### Check ENTER on directory
40 :1|:/^$//dir/
41 assert_match('Please specify a file, not a directory',
42 execute("normal \<CR>"))
43
44 ### Check ENTER on file
45 :1|:/^$//file/
46 exe ":normal \<cr>"
47 assert_match('zipfile://.*/X.zip::Xzip/file.txt', @%)
48 assert_equal('one', getline(1))
49
50 ### Check editing file
51 if executable("zip")
52 s/one/two/
53 assert_equal("two", getline(1))
54 w
55 bw|bw
56 e X.zip
57
58 :1|:/^$//file/
59 exe "normal \<cr>"
60 assert_equal("two", getline(1))
61 endif
62
63 only
64 e X.zip
65
66 ### Check extracting file
67 :1|:/^$//file/
68 normal x
69 assert_true(filereadable("Xzip/file.txt"))
70 delete("Xzip", "rf")
71
72 ### Check extracting directory
73 :1|:/^$//dir/
74 assert_match('Please specify a file, not a directory', execute("normal x"))
75 assert_equal("X.zip", @%)
76
77 ### Check "x" on header
78 :1
79 normal x
80 assert_equal("X.zip", @%)
81 bw
82
83 ### Check opening zip when "unzip" program is missing
84 var save_zip_unzipcmd = g:zip_unzipcmd
85 g:zip_unzipcmd = "/"
86 assert_match('unzip not available on your system', execute("e X.zip"))
87
88 ### Check when "unzip" don't work
89 if executable("false")
90 g:zip_unzipcmd = "false"
91 assert_match('X\.zip is not a zip file', execute("e X.zip"))
92 endif
93 bw
94
95 g:zip_unzipcmd = save_zip_unzipcmd
96 e X.zip
97
98 ### Check opening file when "unzip" is missing
99 g:zip_unzipcmd = "/"
100 assert_match('sorry, your system doesn''t appear to have the / program',
101 execute("normal \<CR>"))
102
103 bw|bw
104 g:zip_unzipcmd = save_zip_unzipcmd
105 e X.zip
106
107 ### Check :write when "zip" program is missing
108 :1|:/^$//file/
109 exe "normal \<cr>Goanother\<esc>"
110 var save_zip_zipcmd = g:zip_zipcmd
111 g:zip_zipcmd = "/"
112 assert_match('sorry, your system doesn''t appear to have the / program',
113 execute("write"))
114
115 ### Check when "zip" report failure
116 if executable("false")
117 g:zip_zipcmd = "false"
118 assert_match('sorry, unable to update .*/X.zip with Xzip/file.txt',
119 execute("write"))
120 endif
121 bw!|bw
122
123 g:zip_zipcmd = save_zip_zipcmd
124
125 ### Check opening an no zipfile
126 writefile(["qsdf"], "Xcorupt.zip", "D")
127 e! Xcorupt.zip
128 assert_equal("qsdf", getline(1))
129
130 bw
131
132 ### Check no existing zipfile
133 assert_match('File not readable', execute("e Xnot_exists.zip"))
134
135 bw
136
137 &shellslash = _sl
138
139enddef