pull/13387/head
Dialga 2022-02-06 05:02:36 +13:00 committed by Delyan Angelov
parent a1d34d8b1d
commit 4fbd610bfc
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 16 additions and 3 deletions

View File

@ -4,15 +4,19 @@ import os
const (
test_out_zip = 'v_test_zip.zip'
test_path = 'zip files'
test_path2 = '.zip files folder'
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)
)
fn cleanup() {
os.chdir(os.temp_dir()) or {}
os.rmdir_all(test_path) or {}
os.rmdir_all(test_path2) or {}
os.rm(test_out_zip) or {}
}
@ -26,27 +30,36 @@ fn testsuite_end() ? {
fn test_szip_create_temp_files() ? {
os.mkdir(test_path) ?
os.mkdir(test_path2) ?
os.write_file(fpath1, 'file one') ?
os.write_file(fpath2, 'file two') ?
os.write_file(fpath3, 'file three') ?
assert os.exists(fpath1)
assert os.exists(fpath2)
assert os.exists(fpath3)
}
fn test_zipping_files() ? {
files := (os.ls(test_path) ?).map(os.join_path(test_path, it))
mut files := (os.ls(test_path) ?).map(os.join_path(test_path, it))
files << (os.ls(test_path2) ?).map(os.join_path(test_path2, it))
szip.zip_files(files, test_out_zip) ?
assert os.exists(test_out_zip)
os.rm(fpath1) ?
os.rm(fpath2) ?
os.rm(fpath3) ?
}
fn test_extract_zipped_files() ? {
os.rm(fpath1) ?
os.rm(fpath2) ?
szip.extract_zip_to_dir(test_out_zip, test_path) ?
szip.extract_zip_to_dir(test_out_zip, test_path2) ?
assert os.exists(fpath1)
assert os.exists(fpath2)
assert os.exists(fpath3)
assert (os.read_file(fpath1) ?) == 'file one'
assert (os.read_file(fpath2) ?) == 'file two'
assert (os.read_file(fpath3) ?) == 'file three'
os.rmdir_all(test_path) ?
os.rmdir_all(test_path2) ?
os.rm(test_out_zip) or {}
}