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:
parent
33f4eb4135
commit
313afe7cc1
1 changed files with 34 additions and 22 deletions
|
@ -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;
|
||||||
|
@ -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.
|
/// Ensure that `extension_from_path` successfully returns the extension from a set of paths.
|
||||||
fn get_ext() {
|
fn get_ext() {
|
||||||
let ext_checks: HashMap<_, Option<&OsStr>> = hashmap![
|
let ext_checks: HashMap<_, Option<&OsStr>> = hashmap![
|
||||||
Path::new("test.txt") => Some(OsStr::new("txt")),
|
Path::new("test.txt") => Some(OsStr::new("txt")),
|
||||||
Path::new("test.zip") => Some(OsStr::new("zip")),
|
Path::new("test.zip") => Some(OsStr::new("zip")),
|
||||||
Path::new("test.tar.gz") => Some(OsStr::new("gz")),
|
Path::new("test.tar.gz") => Some(OsStr::new("gz")),
|
||||||
Path::new("test.") => Some(OsStr::new("")),
|
Path::new("test.") => Some(OsStr::new("")),
|
||||||
Path::new("test") => None,
|
Path::new("test") => None,
|
||||||
Path::new(".hidden") => None,
|
Path::new(".hidden") => None,
|
||||||
];
|
];
|
||||||
|
|
||||||
for (path, ext) in ext_checks {
|
for (path, ext) in ext_checks {
|
||||||
assert_eq!(path.extension(), ext);
|
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
|
/// 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![
|
||||||
.unwrap()
|
&IMAGE_JPEG => "jpg",
|
||||||
.contains(&String::from("jpg")));
|
&IMAGE_PNG => "png",
|
||||||
assert!(mime_extension_lookup(IMAGE_PNG.essence_str().into())
|
&APPLICATION_PDF => "pdf",
|
||||||
.unwrap()
|
APPLICATION_ZIP.deref() => "zip",
|
||||||
.contains(&String::from("png")));
|
];
|
||||||
assert!(mime_extension_lookup(APPLICATION_PDF.essence_str().into())
|
|
||||||
.unwrap()
|
for (mime, ext) in tests.into_iter() {
|
||||||
.contains(&String::from("pdf")));
|
assert!(
|
||||||
assert!(mime_extension_lookup(APPLICATION_ZIP.essence_str().into())
|
mime_extension_lookup(mime.essence_str().into())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.contains(&String::from("zip")));
|
.contains(&String::from(ext)),
|
||||||
|
"mime_extension_lookup for {} didn't contain {}!",
|
||||||
|
mime.essence_str(),
|
||||||
|
ext
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue