mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 11:58:21 +00:00
5c5b531562
Rename encoding/*pb to follow the convention of prefixing package names with 'proto': google.golang.org/protobuf/encoding/protojson google.golang.org/protobuf/encoding/prototext Move protogen under a compiler/ directory, just in case we ever do add more compiler-related packages. google.golang.org/protobuf/compiler/protogen Change-Id: I31010cb5cabcea8274fffcac468477b58b56e8eb Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/177178 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
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"},
|
|
{"camelCase", "CamelCase"},
|
|
{"go2proto", "Go2Proto"},
|
|
{"世界", "世界"},
|
|
{"x世界", "X世界"},
|
|
{"foo_bar世界", "FooBar世界"},
|
|
}
|
|
for _, tc := range tests {
|
|
if got := camelCase(tc.in); got != tc.want {
|
|
t.Errorf("CamelCase(%q) = %q, want %q", tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCleanGoName(t *testing.T) {
|
|
tests := []struct {
|
|
in, want string
|
|
}{
|
|
{"", "_"},
|
|
{"boo", "boo"},
|
|
{"Boo", "Boo"},
|
|
{"ßoo", "ßoo"},
|
|
{"default", "_default"},
|
|
{"hello", "hello"},
|
|
{"hello-world!!", "hello_world__"},
|
|
{"hello-\xde\xad\xbe\xef\x00", "hello_____"},
|
|
{"hello 世界", "hello_世界"},
|
|
{"世界", "世界"},
|
|
}
|
|
for _, tc := range tests {
|
|
if got := cleanGoName(tc.in); got != tc.want {
|
|
t.Errorf("cleanGoName(%q) = %q, want %q", tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|