blob: e831f263456026e5dae7503810753cd7514214d2 [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()
Damiend7af21e2024-08-05 20:24:11 +020013
14 ### get our zip file
15 if !filecopy("samples/test.zip", "X.zip")
16 assert_report("Can't copy samples/test.zip")
17 return
18 endif
19 defer delete("X.zip")
20
21 e X.zip
22
23 ### Check header
24 assert_match('^" zip\.vim version v\d\+', getline(1))
25 assert_match('^" Browsing zipfile .*/X.zip', getline(2))
26 assert_match('^" Select a file with cursor and press ENTER', getline(3))
27 assert_match('^$', getline(4))
28
29 ### Check files listing
30 assert_equal(["Xzip/", "Xzip/dir/", "Xzip/file.txt"], getline(5, 7))
31
32 ### Check ENTER on header
33 :1
34 exe ":normal \<cr>"
35 assert_equal("X.zip", @%)
36
37 ### Check ENTER on directory
38 :1|:/^$//dir/
39 assert_match('Please specify a file, not a directory',
40 execute("normal \<CR>"))
41
42 ### Check ENTER on file
Christian Brabandt7790ea02024-08-20 22:41:52 +020043 :1
44 search('file.txt')
Damiend7af21e2024-08-05 20:24:11 +020045 exe ":normal \<cr>"
46 assert_match('zipfile://.*/X.zip::Xzip/file.txt', @%)
47 assert_equal('one', getline(1))
48
49 ### Check editing file
50 if executable("zip")
51 s/one/two/
52 assert_equal("two", getline(1))
53 w
54 bw|bw
55 e X.zip
56
57 :1|:/^$//file/
58 exe "normal \<cr>"
59 assert_equal("two", getline(1))
60 endif
61
62 only
63 e X.zip
64
65 ### Check extracting file
66 :1|:/^$//file/
67 normal x
68 assert_true(filereadable("Xzip/file.txt"))
Christian Brabandt7790ea02024-08-20 22:41:52 +020069
70 ## Check not overwriting existing file
71 assert_match('<Xzip/file.txt> .* not overwriting!', execute("normal x"))
72
Damiend7af21e2024-08-05 20:24:11 +020073 delete("Xzip", "rf")
74
75 ### Check extracting directory
76 :1|:/^$//dir/
77 assert_match('Please specify a file, not a directory', execute("normal x"))
78 assert_equal("X.zip", @%)
79
80 ### Check "x" on header
81 :1
82 normal x
83 assert_equal("X.zip", @%)
84 bw
85
86 ### Check opening zip when "unzip" program is missing
87 var save_zip_unzipcmd = g:zip_unzipcmd
88 g:zip_unzipcmd = "/"
89 assert_match('unzip not available on your system', execute("e X.zip"))
90
91 ### Check when "unzip" don't work
92 if executable("false")
93 g:zip_unzipcmd = "false"
94 assert_match('X\.zip is not a zip file', execute("e X.zip"))
95 endif
96 bw
97
98 g:zip_unzipcmd = save_zip_unzipcmd
99 e X.zip
100
101 ### Check opening file when "unzip" is missing
102 g:zip_unzipcmd = "/"
103 assert_match('sorry, your system doesn''t appear to have the / program',
104 execute("normal \<CR>"))
105
106 bw|bw
107 g:zip_unzipcmd = save_zip_unzipcmd
108 e X.zip
109
110 ### Check :write when "zip" program is missing
111 :1|:/^$//file/
112 exe "normal \<cr>Goanother\<esc>"
113 var save_zip_zipcmd = g:zip_zipcmd
114 g:zip_zipcmd = "/"
115 assert_match('sorry, your system doesn''t appear to have the / program',
116 execute("write"))
117
118 ### Check when "zip" report failure
119 if executable("false")
120 g:zip_zipcmd = "false"
121 assert_match('sorry, unable to update .*/X.zip with Xzip/file.txt',
122 execute("write"))
123 endif
124 bw!|bw
125
126 g:zip_zipcmd = save_zip_zipcmd
127
128 ### Check opening an no zipfile
129 writefile(["qsdf"], "Xcorupt.zip", "D")
130 e! Xcorupt.zip
131 assert_equal("qsdf", getline(1))
132
133 bw
134
135 ### Check no existing zipfile
136 assert_match('File not readable', execute("e Xnot_exists.zip"))
137
138 bw
Christian Brabandt7790ea02024-08-20 22:41:52 +0200139enddef
Damiend7af21e2024-08-05 20:24:11 +0200140
Christian Brabandt7790ea02024-08-20 22:41:52 +0200141def Test_zip_glob_fname()
142 CheckNotMSWindows
143 # does not work on Windows, why?
144
145 ### copy sample zip file
146 if !filecopy("samples/testa.zip", "X.zip")
147 assert_report("Can't copy samples/testa.zip")
148 return
149 endif
150 defer delete("X.zip")
151 defer delete('zipglob', 'rf')
152
153 e X.zip
154
155 ### 1) Check extracting strange files
156 :1
157 var fname = 'a[a].txt'
158 search('\V' .. fname)
159 normal x
160 assert_true(filereadable('zipglob/' .. fname))
161 delete('zipglob', 'rf')
162
163 :1
164 fname = 'a*.txt'
165 search('\V' .. fname)
166 normal x
167 assert_true(filereadable('zipglob/' .. fname))
168 delete('zipglob', 'rf')
169
170 :1
171 fname = 'a?.txt'
172 search('\V' .. fname)
173 normal x
174 assert_true(filereadable('zipglob/' .. fname))
175 delete('zipglob', 'rf')
176
177 :1
178 fname = 'a\.txt'
179 search('\V' .. escape(fname, '\\'))
180 normal x
181 assert_true(filereadable('zipglob/' .. fname))
182 delete('zipglob', 'rf')
183
184 :1
185 fname = 'a\\.txt'
186 search('\V' .. escape(fname, '\\'))
187 normal x
188 assert_true(filereadable('zipglob/' .. fname))
189 delete('zipglob', 'rf')
190
191 ### 2) Check entering strange file names
192 :1
193 fname = 'a[a].txt'
194 search('\V' .. fname)
195 exe ":normal \<cr>"
196 assert_match('zipfile://.*/X.zip::zipglob/a\[a\].txt', @%)
197 assert_equal('a test file with []', getline(1))
198 bw
199
200 e X.zip
201 :1
202 fname = 'a*.txt'
203 search('\V' .. fname)
204 exe ":normal \<cr>"
205 assert_match('zipfile://.*/X.zip::zipglob/a\*.txt', @%)
206 assert_equal('a test file with a*', getline(1))
207 bw
208
209 e X.zip
210 :1
211 fname = 'a?.txt'
212 search('\V' .. fname)
213 exe ":normal \<cr>"
214 assert_match('zipfile://.*/X.zip::zipglob/a?.txt', @%)
215 assert_equal('a test file with a?', getline(1))
216 bw
217
218 e X.zip
219 :1
220 fname = 'a\.txt'
221 search('\V' .. escape(fname, '\\'))
222 exe ":normal \<cr>"
223 assert_match('zipfile://.*/X.zip::zipglob/a\\.txt', @%)
224 assert_equal('a test file with a\', getline(1))
225 bw
226
227 e X.zip
228 :1
229 fname = 'a\\.txt'
230 search('\V' .. escape(fname, '\\'))
231 exe ":normal \<cr>"
232 assert_match('zipfile://.*/X.zip::zipglob/a\\\\.txt', @%)
233 assert_equal('a test file with a double \', getline(1))
234 bw
235
236 bw
Damiend7af21e2024-08-05 20:24:11 +0200237enddef