fix(build): snake_case service names (#190)

This commit is contained in:
Juan Alvarez
2019-12-14 15:08:28 -05:00
committed by Lucio Franco
parent 82facb6283
commit 3a5c66d5f2
8 changed files with 42 additions and 14 deletions
+28
View File
@@ -321,3 +321,31 @@ fn replace_wellknown(proto_path: &str, method: &Method) -> (TokenStream, TokenSt
(request, response)
}
fn naive_snake_case(name: &str) -> String {
let mut s = String::new();
let mut it = name.chars().peekable();
while let Some(x) = it.next() {
s.push(x.to_ascii_lowercase());
if let Some(y) = it.peek() {
if y.is_uppercase() {
s.push('_');
}
}
}
s
}
#[test]
fn test_snake_case() {
for case in &[
("Service", "service"),
("ThatHasALongName", "that_has_a_long_name"),
("greeter", "greeter"),
("ABCServiceX", "a_b_c_service_x"),
] {
assert_eq!(naive_snake_case(case.0), case.1)
}
}