diff --git a/mock-builder/src/location.rs b/mock-builder/src/location.rs index 5315bf6..b561eb1 100644 --- a/mock-builder/src/location.rs +++ b/mock-builder/src/location.rs @@ -74,6 +74,12 @@ impl FunctionLocation { .strip_suffix('>') .unwrap(); + // Remove generic from trait name + let trait_name = trait_name + .split_once('<') + .map(|(fst, _)| fst) + .unwrap_or(trait_name); + (struct_path, Some(trait_name.to_owned())) } None => (path, None), @@ -160,6 +166,10 @@ mod tests { fn generic_method>(_: impl Into) -> FunctionLocation; } + trait TraitExampleGen { + fn foo() -> FunctionLocation; + } + struct Example; impl Example { @@ -187,6 +197,12 @@ mod tests { } } + impl TraitExampleGen for Example { + fn foo() -> FunctionLocation { + FunctionLocation::from(|| ()) + } + } + #[test] fn function_location() { assert_eq!( @@ -228,6 +244,16 @@ mod tests { trait_info: None, } ); + + assert_eq!( + Example::foo(), + FunctionLocation { + location: format!( + "<{PREFIX}::Example as {PREFIX}::TraitExampleGen>::foo" + ), + trait_info: None, + } + ); } #[test] @@ -255,6 +281,14 @@ mod tests { trait_info: Some("TraitExample".into()), } ); + + assert_eq!( + Example::foo().normalize(), + FunctionLocation { + location: format!("{PREFIX}::Example::foo"), + trait_info: Some("TraitExampleGen".into()), + } + ); } #[test]