From 15e922b7ba75134218515b9d8be5d915de46d758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20M=2E=20Bezerra?= Date: Tue, 2 Nov 2021 01:16:42 -0300 Subject: [PATCH] Fixing some Extension tests --- src/extension.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/extension.rs b/src/extension.rs index d0ae41b..07beb03 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -85,14 +85,6 @@ impl fmt::Display for CompressionFormat { /// Extracts extensions from a path, /// return both the remaining path and the list of extension objects -/// -/// ```rust -/// use ouch::extension::{separate_known_extensions_from_name, CompressionFormat}; -/// use std::path::Path; -/// -/// let mut path = Path::new("bolovo.tar.gz"); -/// assert_eq!(separate_known_extensions_from_name(&path), (Path::new("bolovo"), vec![CompressionFormat::Tar, CompressionFormat::Gzip])); -/// ``` pub fn separate_known_extensions_from_name(mut path: &Path) -> (&Path, Vec) { // // TODO: check for file names with the name of an extension // // TODO2: warn the user that currently .tar.gz is a .gz file named .tar @@ -130,15 +122,23 @@ pub fn separate_known_extensions_from_name(mut path: &Path) -> (&Path, Vec Vec { let (_, extensions) = separate_known_extensions_from_name(path); extensions } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_extensions_from_path() { + use CompressionFormat::*; + let path = Path::new("bolovo.tar.gz"); + + let extensions: Vec = extensions_from_path(&path); + let formats: Vec<&CompressionFormat> = extensions.iter().flat_map(Extension::iter).collect::>(); + + assert_eq!(formats, vec![&Tar, &Gzip]); + } +}