diff --git a/src/sharry/ids.rs b/src/sharry/ids.rs index 4bd35d3..fc63f16 100644 --- a/src/sharry/ids.rs +++ b/src/sharry/ids.rs @@ -103,6 +103,18 @@ impl TryFrom for FileID { mod tests { use super::*; + #[inline] + fn check_trait(expected: &E, actual: &A, tr: &'static str, ty: &'static str) + where + E: fmt::Debug + PartialEq, + 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 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", "AliasID"); + check_trait(&input, &aid.as_ref(), "AsRef", "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", "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, ":///api/v2/alias/upload//files/tus/", "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:?}"), }