Skip to content

Commit

Permalink
fix: handle camel case package (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
cobbinma authored Jun 2, 2022
1 parent 0e6aa1d commit b6af2a3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pbjson-build/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub struct Package {

impl Display for Package {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.path[0])?;
write!(f, "{}", self.path[0].to_snake_case())?;
for element in &self.path[1..self.path.len()] {
write!(f, ".{}", element)?;
write!(f, ".{}", element.to_snake_case())?;
}
Ok(())
}
Expand Down Expand Up @@ -291,4 +291,12 @@ mod tests {
assert_eq!(t.prefix_match(".foo.bar.Baz.Bar"), Some(4));
assert_eq!(t.prefix_match(".foo.bar.Baz.Bar.Boo"), None);
}

#[test]
fn test_handle_camel_case_in_package() {
assert_eq!(
Package::new("fooBar.baz.boo").to_string(),
String::from("foo_bar.baz.boo")
)
}
}

0 comments on commit b6af2a3

Please sign in to comment.