1 // TODO: remove tests of CompressionFormat::try_from since that's no longer used anywhere
6 use crate::cli::clap_app;
7 use crate::cli::Command;
8 use crate::cli::CommandKind::*;
9 use crate::error::OuchResult;
10 use crate::extension::CompressionFormat::*;
11 use crate::extension::Extension;
12 use crate::file::File;
13 use std::convert::TryFrom;
16 fn decompress_files_into_folder() -> OuchResult<()> {
17 let matches = clap_app().get_matches_from(vec!["ouch", "-i", "file.zip", "-o", "folder/"]);
18 let command_from_matches = Command::try_from(matches)?;
23 kind: Decompression(vec![
25 path: "file.zip".into(),
26 contents_in_memory: None,
27 extension: Some(Extension::from(Zip))
31 path: "folder".into(),
32 contents_in_memory: None,
42 fn decompress_files() -> OuchResult<()> {
43 let matches = clap_app().get_matches_from(vec!["ouch", "-i", "file.zip", "file.tar"]);
44 let command_from_matches = Command::try_from(matches)?;
49 kind: Decompression(vec![
51 path: "file.zip".into(),
52 contents_in_memory: None,
53 extension: Some(Extension::from(Zip))
56 path: "file.tar".into(),
57 contents_in_memory: None,
58 extension: Some(Extension::from(Tar))
69 fn compress_files() -> OuchResult<()> {
70 let matches = clap_app().get_matches_from(vec![
79 let command_from_matches = Command::try_from(matches)?;
84 kind: Compression(vec![
91 path: "file.tar".into(),
92 contents_in_memory: None,
93 extension: Some(Extension::from(Tar))
106 use std::convert::TryFrom;
108 use crate::cli::clap_app;
109 use crate::cli::Command;
110 use crate::error::Error;
111 use crate::error::OuchResult;
114 fn compress_files() -> OuchResult<()> {
116 clap_app().get_matches_from(vec!["ouch", "-i", "a_file", "file2.jpeg", "file3.ok"]);
117 let res = Command::try_from(matches);
121 Err(Error::InputsMustHaveBeenDecompressible("a_file".into()))
129 mod extension_extraction {
130 use crate::{error::OuchResult, extension::Extension} ;
131 use crate::extension::CompressionFormat;
132 use std::{convert::TryFrom, path::PathBuf, str::FromStr};
135 fn zip() -> OuchResult<()> {
136 let path = PathBuf::from_str("filename.tar.zip").unwrap();
138 CompressionFormat::try_from(&path)?,
139 CompressionFormat::Zip
146 fn tar_gz() -> OuchResult<()> {
147 let extension = Extension::new("folder.tar.gz")?;
152 first_ext: Some(CompressionFormat::Tar),
153 second_ext: CompressionFormat::Gzip
161 fn tar() -> OuchResult<()> {
162 let path = PathBuf::from_str("pictures.tar").unwrap();
164 CompressionFormat::try_from(&path)?,
165 CompressionFormat::Tar
172 fn gz() -> OuchResult<()> {
173 let path = PathBuf::from_str("passwords.tar.gz").unwrap();
175 CompressionFormat::try_from(&path)?,
176 CompressionFormat::Gzip
183 fn lzma() -> OuchResult<()> {
184 let path = PathBuf::from_str("mygame.tar.lzma").unwrap();
186 CompressionFormat::try_from(&path)?,
187 CompressionFormat::Lzma
194 fn bz() -> OuchResult<()> {
195 let path = PathBuf::from_str("songs.tar.bz").unwrap();
197 CompressionFormat::try_from(&path)?,
198 CompressionFormat::Bzip
207 // use crate::extension::Extension;
208 // use crate::error::OuchResult;
209 // use crate::file::File;
210 // use crate::evaluator::Evaluator;
211 // use crate::decompressors::{Decompressor, TarDecompressor, GzipDecompressor};
214 // fn test() -> OuchResult<()> {
215 // let extension = Extension::new("folder.tar.gz")?;
218 // path: "folder.tar.gz".into(),
219 // contents_in_memory: None,
220 // extension: Some(extension),
223 // let (fst, snd) = Evaluator::get_decompressor(&file)?;
225 // let fst = fst.unwrap();
229 // Some(Box::new(TarDecompressor::{})