diff --git a/src/error.rs b/src/error.rs index ee9e73b..5560315 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,7 +2,7 @@ use std::{fmt, path::PathBuf}; use colored::Colorize; -#[derive(Debug)] +#[derive(PartialEq, Eq, Debug)] pub enum Error { UnknownExtensionError(String), MissingExtensionError(String), diff --git a/src/test.rs b/src/test.rs index 3f523d5..2dcabe4 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,8 +1,11 @@ +use std::{convert::TryFrom}; + + + #[cfg(test)] mod cli { - - use std::{convert::TryFrom}; + use std::convert::TryFrom; use crate::cli::clap_app; use crate::cli::Command; use crate::file::File; @@ -10,6 +13,7 @@ mod cli { use crate::extensions::CompressionExtension::*; use crate::error::OuchResult; + #[test] fn decompress_files_into_folder() -> OuchResult<()> { let matches = clap_app(). @@ -40,7 +44,7 @@ mod cli { fn decompress_files() -> OuchResult<()> { let matches = clap_app(). get_matches_from( - vec!["ouch", "-i", "file.zip"] + vec!["ouch", "-i", "file.zip", "file.tar"] ); let command_from_matches = Command::try_from(matches)?; @@ -53,6 +57,10 @@ mod cli { "file.zip".into(), Zip, ), + ( + "file.tar".into(), + Tar, + ), ], ), output: None, @@ -61,4 +69,51 @@ mod cli { Ok(()) } + + #[test] + fn compress_files() -> OuchResult<()> { + let matches = clap_app(). + get_matches_from( + vec!["ouch", "-i", "file", "file2.jpeg", "file3.ok", "-o", "file.tar"] + ); + let command_from_matches = Command::try_from(matches)?; + + assert_eq!( + command_from_matches, + Command { command_type: Compression(vec!["file".into(), "file2.jpeg".into(), "file3.ok".into()]), output: Some(File::WithExtension(("file.tar".into(), Tar))) } + ); + + Ok(()) + } +} + +#[cfg(test)] +mod cli_errors { + + use std::convert::TryFrom; + + use crate::cli::clap_app; + use crate::cli::Command; + use crate::file::File; + use crate::cli::CommandType::*; + use crate::extensions::CompressionExtension::*; + use crate::error::OuchResult; + use crate::error::Error; + + + #[test] + fn compress_files() -> OuchResult<()> { + let matches = clap_app(). + get_matches_from( + vec!["ouch", "-i", "a_file", "file2.jpeg", "file3.ok"] + ); + let res = Command::try_from(matches); + + assert_eq!( + res, + Err(Error::InputsMustHaveBeenDecompressible("a_file".into())) + ); + + Ok(()) + } } \ No newline at end of file