diff --git a/pbjson-build/src/resolver.rs b/pbjson-build/src/resolver.rs index 3a8e5d3..5d1d68f 100644 --- a/pbjson-build/src/resolver.rs +++ b/pbjson-build/src/resolver.rs @@ -57,7 +57,7 @@ impl<'a> Resolver<'a> { .path() .iter() .zip(path.path()) - .filter(|(a, b)| a == b) + .take_while(|(a, b)| a == b) .count(); let super_count = self.package.path().len() - shared_prefix; @@ -176,6 +176,19 @@ mod tests { ); } + #[test] + // https://github.com/influxdata/pbjson/issues/48 + fn test_resolver_shared_prefix_false_match() { + assert_eq!( + Resolver::new(&[], &Package::new("test.api.v1"), false).rust_type( + &TypePath::new(Package::new("test.domain.v1")) + .child(TypeName::new("Foo")) + .child(TypeName::new("Bar")) + ), + "super::super::domain::v1::foo::Bar" + ); + } + #[test] fn test_variant() { let package = Package::new("test.syntax3");