[wip] unit tests for sharry module
- `ids` done
This commit is contained in:
parent
91085a9eec
commit
d891e6d1c4
1 changed files with 24 additions and 29 deletions
|
|
@ -103,6 +103,18 @@ impl TryFrom<String> for FileID {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn check_trait<E, A>(expected: &E, actual: &A, tr: &'static str, ty: &'static str)
|
||||||
|
where
|
||||||
|
E: fmt::Debug + PartialEq<A>,
|
||||||
|
A: fmt::Debug,
|
||||||
|
{
|
||||||
|
assert_eq!(
|
||||||
|
expected, actual,
|
||||||
|
"`impl {tr} for {ty}` expected: {expected:?}, actual: {actual:?}",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_traits_working() {
|
fn basic_traits_working() {
|
||||||
let inputs = vec![
|
let inputs = vec![
|
||||||
|
|
@ -116,40 +128,24 @@ mod tests {
|
||||||
for input in inputs {
|
for input in inputs {
|
||||||
{
|
{
|
||||||
// check AliasID
|
// check AliasID
|
||||||
let _ = AliasID(input.to_owned());
|
let _ = AliasID(input.to_owned()); // direct creation
|
||||||
let aid = AliasID::from(input.to_owned()); // "From" trait
|
let aid = AliasID::from(input.to_owned());
|
||||||
assert_eq!(
|
check_trait(&input, &aid.0, "From<String>", "AliasID");
|
||||||
aid.as_ref(),
|
check_trait(&input, &aid.as_ref(), "AsRef<str>", "AliasID");
|
||||||
input,
|
|
||||||
"`impl AsRef<str> for AliasID` expected: {:?}, got {:?}",
|
|
||||||
input,
|
|
||||||
aid.as_ref(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// check ShareID
|
// check ShareID
|
||||||
let _ = ShareID(input.to_owned());
|
let _ = ShareID(input.to_owned()); // direct creation
|
||||||
let sid = ShareID::from(input.to_owned()); // "From" trait
|
let sid = ShareID::from(input.to_owned());
|
||||||
assert_eq!(
|
check_trait(&input, &sid.0, "From<String>", "ShareID");
|
||||||
sid.to_string(),
|
check_trait(&input, &sid.to_string(), "Display", "ShareID");
|
||||||
input,
|
|
||||||
"`impl Display for ShareID` expected: {:?}, got {:?}",
|
|
||||||
input,
|
|
||||||
sid.to_string(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// check FileID
|
// check FileID
|
||||||
let fid = FileID(input.to_owned());
|
let fid = FileID(input.to_owned()); // direct creation
|
||||||
assert_eq!(
|
check_trait(&input, &fid.to_string(), "Display", "FileID");
|
||||||
fid.to_string(),
|
|
||||||
input,
|
|
||||||
"`impl Display for FileID` expected: {:?}, got {:?}",
|
|
||||||
fid.to_string(),
|
|
||||||
input
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -173,8 +169,7 @@ mod tests {
|
||||||
];
|
];
|
||||||
|
|
||||||
for (good, expected_fid) in cases {
|
for (good, expected_fid) in cases {
|
||||||
let s = good.to_owned();
|
let file_id = FileID::try_from(good.to_owned()).expect("URL should parse successfully");
|
||||||
let file_id = FileID::try_from(s.clone()).expect("URL should parse successfully");
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
file_id.0, expected_fid,
|
file_id.0, expected_fid,
|
||||||
"Expected `{good}` → FileID({expected_fid}), got {file_id:?}",
|
"Expected `{good}` → FileID({expected_fid}), got {file_id:?}",
|
||||||
|
|
@ -206,7 +201,7 @@ mod tests {
|
||||||
expected, "<proto>://<base>/api/v2/alias/upload/<share>/files/tus/<file>",
|
expected, "<proto>://<base>/api/v2/alias/upload/<share>/files/tus/<file>",
|
||||||
"Error should output expected format"
|
"Error should output expected format"
|
||||||
);
|
);
|
||||||
assert_eq!(actual, bad.to_owned(), "Error should echo back the input");
|
assert_eq!(actual, bad, "Error should echo back the input");
|
||||||
}
|
}
|
||||||
_ => panic!("Expected Error::Mismatch for input `{bad}` but got {err:?}"),
|
_ => panic!("Expected Error::Mismatch for input `{bad}` but got {err:?}"),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue