test improvements

- fix tests on big endian 32 bit archs
- condense the recommend_ext test
- also test writablesln!
- general engoodening
This commit is contained in:
Lynne Megido 2021-11-25 06:40:34 +10:00
parent 33f4eb4135
commit 313afe7cc1
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90

View file

@ -4,6 +4,7 @@
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
use std::ffi::OsStr; use std::ffi::OsStr;
use std::ops::Deref;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use clap::Clap; use clap::Clap;
@ -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 /// 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. /// contain "jpg", "png", "pdf", and "zip", respectively.
fn recommend_ext() { fn recommend_ext() {
assert!(mime_extension_lookup(IMAGE_JPEG.essence_str().into()) 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() .unwrap()
.contains(&String::from("jpg"))); .contains(&String::from(ext)),
assert!(mime_extension_lookup(IMAGE_PNG.essence_str().into()) "mime_extension_lookup for {} didn't contain {}!",
.unwrap() mime.essence_str(),
.contains(&String::from("png"))); ext
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")));
} }
#[test] #[test]
@ -427,15 +433,20 @@ fn media_contains_audio_video_images() {
} }
#[test] #[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() { fn writables_is_correct() {
use fif::formats::Writable; use fif::formats::Writable;
use fif::writables; use fif::{writables, writablesln};
assert_eq!( assert_eq!(
&["henlo".into(), Path::new("henlo").into(), Writable::Newline,], &["henlo".into(), Path::new("henlo").into(), Writable::Newline,],
writables!["henlo", (Path::new("henlo")), 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] #[test]
@ -499,6 +510,7 @@ fn sort_findings() {
} }
#[test] #[test]
#[cfg(not(all(target_endian = "big", target_pointer_width = "32")))]
/// Ensures that [`SmartString`]s don't deviate from std's Strings /// Ensures that [`SmartString`]s don't deviate from std's Strings
fn validate_string_type() { fn validate_string_type() {
use std::string::String as StdString; use std::string::String as StdString;
@ -510,6 +522,6 @@ fn validate_string_type() {
SmartString::from("A long and therefore heap-allocated string"), SmartString::from("A long and therefore heap-allocated string"),
StdString::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(); smartstring::validate();
} }