protobuf-go/protogen/names_test.go
Damien Neil 3863ee56b5 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 <thebrokentoaster@gmail.com>
2018-10-16 16:18:01 +00:00

35 lines
907 B
Go

// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package protogen
import "testing"
func TestCamelCase(t *testing.T) {
tests := []struct {
in, want string
}{
{"one", "One"},
{"one_two", "OneTwo"},
{"_my_field_name_2", "XMyFieldName_2"},
{"Something_Capped", "Something_Capped"},
{"my_Name", "My_Name"},
{"OneTwo", "OneTwo"},
{"_", "X"},
{"_a_", "XA_"},
{"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"},
}
for _, tc := range tests {
if got := camelCase(tc.in); got != tc.want {
t.Errorf("CamelCase(%q) = %q, want %q", tc.in, got, tc.want)
}
}
}