From 3863ee56b5c360b23dcef24b52ff843737a7957d Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 9 Oct 2018 13:24:04 -0700 Subject: [PATCH] protogen: camel-case "Foo.bar" as "FooBar" instead of "Foo_Bar". Given: message Parent { message Child1 {} message child2 {} } Historic behavior is to generate child messages named: Parent_Child1 ParentChild2 Avoid adding an _ in the latter case. Change-Id: I49a6732655d64967b8c7bb7ad358ae54d294f7b4 Reviewed-on: https://go-review.googlesource.com/c/140898 Reviewed-by: Joe Tsai --- protogen/names.go | 2 ++ protogen/names_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/protogen/names.go b/protogen/names.go index 445613fc..9da11d99 100644 --- a/protogen/names.go +++ b/protogen/names.go @@ -136,6 +136,8 @@ func camelCase(s string) string { for ; i < len(s); i++ { c := s[i] switch { + case c == '.' && i+1 < len(s) && isASCIILower(s[i+1]): + // Skip over ., to match historic behavior. case c == '.': t = append(t, '_') // Convert . to _. case c == '_' && (i == 0 || s[i-1] == '.'): diff --git a/protogen/names_test.go b/protogen/names_test.go index 05e698e1..3271954b 100644 --- a/protogen/names_test.go +++ b/protogen/names_test.go @@ -18,8 +18,10 @@ func TestCamelCase(t *testing.T) { {"OneTwo", "OneTwo"}, {"_", "X"}, {"_a_", "XA_"}, - {"one.two", "One_Two"}, - {"one_two.three_four", "OneTwo_ThreeFour"}, + {"one.two", "OneTwo"}, + {"one.Two", "One_Two"}, + {"one_two.three_four", "OneTwoThreeFour"}, + {"one_two.Three_four", "OneTwo_ThreeFour"}, {"_one._two", "XOne_XTwo"}, {"SCREAMING_SNAKE_CASE", "SCREAMING_SNAKE_CASE"}, {"double__underscore", "Double_Underscore"},