[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 {
|
||||
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]
|
||||
fn basic_traits_working() {
|
||||
let inputs = vec![
|
||||
|
|
@ -116,40 +128,24 @@ mod tests {
|
|||
for input in inputs {
|
||||
{
|
||||
// check AliasID
|
||||
let _ = AliasID(input.to_owned());
|
||||
let aid = AliasID::from(input.to_owned()); // "From" trait
|
||||
assert_eq!(
|
||||
aid.as_ref(),
|
||||
input,
|
||||
"`impl AsRef<str> for AliasID` expected: {:?}, got {:?}",
|
||||
input,
|
||||
aid.as_ref(),
|
||||
);
|
||||
let _ = AliasID(input.to_owned()); // direct creation
|
||||
let aid = AliasID::from(input.to_owned());
|
||||
check_trait(&input, &aid.0, "From<String>", "AliasID");
|
||||
check_trait(&input, &aid.as_ref(), "AsRef<str>", "AliasID");
|
||||
}
|
||||
|
||||
{
|
||||
// check ShareID
|
||||
let _ = ShareID(input.to_owned());
|
||||
let sid = ShareID::from(input.to_owned()); // "From" trait
|
||||
assert_eq!(
|
||||
sid.to_string(),
|
||||
input,
|
||||
"`impl Display for ShareID` expected: {:?}, got {:?}",
|
||||
input,
|
||||
sid.to_string(),
|
||||
);
|
||||
let _ = ShareID(input.to_owned()); // direct creation
|
||||
let sid = ShareID::from(input.to_owned());
|
||||
check_trait(&input, &sid.0, "From<String>", "ShareID");
|
||||
check_trait(&input, &sid.to_string(), "Display", "ShareID");
|
||||
}
|
||||
|
||||
{
|
||||
// check FileID
|
||||
let fid = FileID(input.to_owned());
|
||||
assert_eq!(
|
||||
fid.to_string(),
|
||||
input,
|
||||
"`impl Display for FileID` expected: {:?}, got {:?}",
|
||||
fid.to_string(),
|
||||
input
|
||||
);
|
||||
let fid = FileID(input.to_owned()); // direct creation
|
||||
check_trait(&input, &fid.to_string(), "Display", "FileID");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,8 +169,7 @@ mod tests {
|
|||
];
|
||||
|
||||
for (good, expected_fid) in cases {
|
||||
let s = good.to_owned();
|
||||
let file_id = FileID::try_from(s.clone()).expect("URL should parse successfully");
|
||||
let file_id = FileID::try_from(good.to_owned()).expect("URL should parse successfully");
|
||||
assert_eq!(
|
||||
file_id.0, expected_fid,
|
||||
"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>",
|
||||
"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:?}"),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue