1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

szip: expose zip_folder (#14356)

This commit is contained in:
Larpon
2022-05-11 15:48:41 +02:00
committed by GitHub
parent 3afc7c4c6d
commit 0ec1c8d9f0
3 changed files with 104 additions and 26 deletions

View File

@ -3,21 +3,33 @@ import os
const (
test_out_zip = 'v_test_zip.zip'
test_dir_zip = 'v_test_dir_zip.zip'
test_path = 'zip files'
test_path2 = '.zip folder'
test_path3 = 'test zip folder'
test_path3_1 = os.join_path(test_path3, '1', '1')
test_path3_2 = os.join_path(test_path3, '2', '1')
test_path3_3 = os.join_path(test_path3, '3', '1')
test_path3_4 = os.join_path(test_path3, '4', '1')
fname1 = 'file_1.txt'
fpath1 = os.join_path(test_path, fname1)
fname2 = 'file_2.txt'
fpath2 = os.join_path(test_path, fname2)
fname3 = '.New Text Document.txt'
fpath3 = os.join_path(test_path2, fname3)
fname4 = 'file.txt'
fpath4 = os.join_path(test_path3_1, fname4)
fpath5 = os.join_path(test_path3_2, fname4)
fpath6 = os.join_path(test_path3_4, fname4)
)
fn cleanup() {
os.chdir(os.temp_dir()) or {}
os.rmdir_all(test_path) or {}
os.rmdir_all(test_path2) or {}
os.rmdir_all(test_path3) or {}
os.rm(test_out_zip) or {}
os.rm(test_dir_zip) or {}
}
fn testsuite_begin() ? {
@ -110,3 +122,53 @@ fn test_reading_zipping_files() ? {
}
zp.close()
}
fn test_zip_folder() ? {
cleanup()
os.mkdir_all(test_path3_1) ?
os.mkdir_all(test_path3_2) ?
os.mkdir_all(test_path3_3) ?
os.mkdir_all(test_path3_4) ?
os.write_file(fpath4, '4') ?
os.write_file(fpath5, '5') ?
os.write_file(fpath6, '6') ?
szip.zip_folder(test_path3, test_dir_zip) ?
assert os.exists(test_dir_zip)
os.rmdir_all(test_path3) ?
os.mkdir_all(test_path3) ?
szip.extract_zip_to_dir(test_dir_zip, test_path3) ?
assert os.exists(test_path3_1)
assert os.exists(test_path3_2)
assert os.exists(test_path3_3) // This is the empty dir
assert os.exists(test_path3_4)
assert (os.read_file(fpath4) ?) == '4'
assert (os.read_file(fpath5) ?) == '5'
assert (os.read_file(fpath6) ?) == '6'
}
fn test_zip_folder_omit_empty_directories() ? {
cleanup()
os.mkdir_all(test_path3_1) ?
os.mkdir_all(test_path3_2) ?
os.mkdir_all(test_path3_3) ?
os.mkdir_all(test_path3_4) ?
os.write_file(fpath4, '4') ?
os.write_file(fpath5, '5') ?
os.write_file(fpath6, '6') ?
szip.zip_folder(test_path3, test_dir_zip, omit_empty_folders: true) ?
assert os.exists(test_dir_zip)
os.rmdir_all(test_path3) ?
os.mkdir_all(test_path3) ?
szip.extract_zip_to_dir(test_dir_zip, test_path3) ?
assert os.exists(test_path3_1)
assert os.exists(test_path3_2)
assert !os.exists(test_path3_3) // This is the empty dir, should be omitted with `omit_empty_folders`
assert os.exists(test_path3_4)
assert (os.read_file(fpath4) ?) == '4'
assert (os.read_file(fpath5) ?) == '5'
assert (os.read_file(fpath6) ?) == '6'
}