mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
szip: run vfmt, refactor test
This commit is contained in:
@ -1,37 +1,37 @@
|
||||
import szip
|
||||
import os
|
||||
|
||||
fn test_szip() {
|
||||
const (
|
||||
test_out_zip = 'v_test_zip.zip'
|
||||
test_path = 'zip files'
|
||||
fpath1 = os.join_path(test_path, 'file_1.txt')
|
||||
fpath2 = os.join_path(test_path, 'file_2.txt')
|
||||
)
|
||||
|
||||
// create temp files for zip/unzip test
|
||||
test_path := 'zip files'
|
||||
test_out_zip := 'v_test_zip.zip'
|
||||
|
||||
os.mkdir(test_path) or { panic(err) }
|
||||
os.write_file(test_path + os.path_separator + 'file_1.txt', 'file one') or { panic(err) }
|
||||
os.write_file(test_path + os.path_separator + 'file_2.txt', 'file file two') or { panic(err) }
|
||||
fn test_szip_create_temp_files() ? {
|
||||
os.chdir(os.temp_dir())
|
||||
os.rmdir_all(test_path) or {}
|
||||
os.mkdir(test_path) ?
|
||||
os.write_file(fpath1, 'file one') ?
|
||||
os.write_file(fpath2, 'file two') ?
|
||||
assert os.exists(fpath1)
|
||||
assert os.exists(fpath2)
|
||||
}
|
||||
|
||||
// get list files from directory
|
||||
mut files := os.ls(test_path) or { panic(err) }
|
||||
for mut file in files {
|
||||
file = os.getwd() + os.path_separator + test_path + os.path_separator + *file
|
||||
}
|
||||
|
||||
// zip files
|
||||
szip.zip_files(files, test_out_zip) or { panic(err) }
|
||||
fn test_zipping_files() ? {
|
||||
files := (os.ls(test_path) ?).map(os.join_path(test_path, it))
|
||||
szip.zip_files(files, test_out_zip) ?
|
||||
assert os.exists(test_out_zip)
|
||||
}
|
||||
|
||||
// remove files before next test
|
||||
os.rm(test_path + os.path_separator + 'file_1.txt') or { panic(err) }
|
||||
os.rm(test_path + os.path_separator + 'file_2.txt') or { panic(err) }
|
||||
|
||||
// extract test
|
||||
szip.extract_zip_to_dir(test_out_zip, test_path) or { panic(err) }
|
||||
assert os.exists(test_path + os.path_separator + 'file_1.txt')
|
||||
assert os.exists(test_path + os.path_separator + 'file_2.txt')
|
||||
|
||||
// clear temp files
|
||||
// remove temp files and dir
|
||||
os.rmdir_all (test_path) or { panic(err) }
|
||||
os.rm(test_out_zip) or { }
|
||||
}
|
||||
fn test_extract_zipped_files() ? {
|
||||
os.rm(fpath1) ?
|
||||
os.rm(fpath2) ?
|
||||
szip.extract_zip_to_dir(test_out_zip, test_path) ?
|
||||
assert os.exists(fpath1)
|
||||
assert os.exists(fpath2)
|
||||
assert (os.read_file(fpath1) ?) == 'file one'
|
||||
assert (os.read_file(fpath2) ?) == 'file two'
|
||||
os.rmdir_all(test_path) ?
|
||||
os.rm(test_out_zip) or {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user