From 313afe7cc1c4aeeb1be9ebac636fe37cf9b2a860 Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Thu, 25 Nov 2021 06:40:34 +1000 Subject: [PATCH] test improvements - fix tests on big endian 32 bit archs - condense the recommend_ext test - also test writablesln! - general engoodening --- src/tests/mod.rs | 56 +++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 7d2b23d..da39d42 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -4,6 +4,7 @@ use std::collections::{BTreeMap, HashMap}; use std::ffi::OsStr; +use std::ops::Deref; use std::path::{Path, PathBuf}; use clap::Clap; @@ -29,13 +30,13 @@ const ZIP_BYTES: &[u8] = b"PK\x03\x04"; /// Ensure that `extension_from_path` successfully returns the extension from a set of paths. fn get_ext() { let ext_checks: HashMap<_, Option<&OsStr>> = hashmap![ - Path::new("test.txt") => Some(OsStr::new("txt")), - Path::new("test.zip") => Some(OsStr::new("zip")), - Path::new("test.tar.gz") => Some(OsStr::new("gz")), - Path::new("test.") => Some(OsStr::new("")), - Path::new("test") => None, - Path::new(".hidden") => None, - ]; + Path::new("test.txt") => Some(OsStr::new("txt")), + Path::new("test.zip") => Some(OsStr::new("zip")), + Path::new("test.tar.gz") => Some(OsStr::new("gz")), + Path::new("test.") => Some(OsStr::new("")), + Path::new("test") => None, + Path::new(".hidden") => None, + ]; for (path, ext) in ext_checks { assert_eq!(path.extension(), ext); @@ -55,18 +56,23 @@ fn detect_type() { /// Ensure that `mime_extension_lookup` works as expected, and that the set of extensions for JPEG, PNG, PDF, and ZIP /// contain "jpg", "png", "pdf", and "zip", respectively. fn recommend_ext() { - assert!(mime_extension_lookup(IMAGE_JPEG.essence_str().into()) - .unwrap() - .contains(&String::from("jpg"))); - assert!(mime_extension_lookup(IMAGE_PNG.essence_str().into()) - .unwrap() - .contains(&String::from("png"))); - assert!(mime_extension_lookup(APPLICATION_PDF.essence_str().into()) - .unwrap() - .contains(&String::from("pdf"))); - assert!(mime_extension_lookup(APPLICATION_ZIP.essence_str().into()) - .unwrap() - .contains(&String::from("zip"))); + let tests = hashmap![ + &IMAGE_JPEG => "jpg", + &IMAGE_PNG => "png", + &APPLICATION_PDF => "pdf", + APPLICATION_ZIP.deref() => "zip", + ]; + + for (mime, ext) in tests.into_iter() { + assert!( + mime_extension_lookup(mime.essence_str().into()) + .unwrap() + .contains(&String::from(ext)), + "mime_extension_lookup for {} didn't contain {}!", + mime.essence_str(), + ext + ); + } } #[test] @@ -427,15 +433,20 @@ fn media_contains_audio_video_images() { } #[test] -/// Ensure that the `writables!` macro produces the output it should. +/// Ensure that the `writables!` and `writablesln!` macros produce the output they should. fn writables_is_correct() { use fif::formats::Writable; - use fif::writables; + use fif::{writables, writablesln}; assert_eq!( &["henlo".into(), Path::new("henlo").into(), Writable::Newline,], writables!["henlo", (Path::new("henlo")), Newline] ); + + assert_eq!( + &["henlo".into(), Path::new("henlo").into(), Writable::Newline, Writable::Newline], + writablesln!["henlo", (Path::new("henlo")), Newline] + ) } #[test] @@ -499,6 +510,7 @@ fn sort_findings() { } #[test] +#[cfg(not(all(target_endian = "big", target_pointer_width = "32")))] /// Ensures that [`SmartString`]s don't deviate from std's Strings fn validate_string_type() { use std::string::String as StdString; @@ -510,6 +522,6 @@ fn validate_string_type() { SmartString::from("A long and therefore heap-allocated string"), StdString::from("A long and therefore heap-allocated string") ); - // uncomment if i ever update to smartstring >= 0.2.9 + smartstring::validate(); }