-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR always uses the per-language Codec to perform any "case conversion". We need to involve the Codec because each language has a different number of reserved words that must be escaped, and the escaping is also language specific. I also fixed a number of places where we used "camel case" when we meant `PascalCase` (note the starting upper case, as opposed to `camelCase`). Almost incidentally, I fixed the conversion for `data_crc32c` (and other names already in `snake_case` form). Previously that got converted to `data_crc_32_c`.
- Loading branch information
Showing
8 changed files
with
286 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
generator/internal/genclient/language/internal/golang/golang_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package golang | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type CaseConvertTest struct { | ||
Input string | ||
Expected string | ||
} | ||
|
||
func TestToSnake(t *testing.T) { | ||
c := &Codec{} | ||
var snakeConvertTests = []CaseConvertTest{ | ||
{"FooBar", "foo_bar"}, | ||
{"foo_bar", "foo_bar"}, | ||
{"data_crc32c", "data_crc32c"}, | ||
{"Map", "map_"}, | ||
{"switch", "switch_"}, | ||
} | ||
for _, test := range snakeConvertTests { | ||
if output := c.ToSnake(test.Input); output != test.Expected { | ||
t.Errorf("Output %s not equal to expected %s, input=%s", output, test.Expected, test.Input) | ||
} | ||
} | ||
} | ||
|
||
func TestToPascal(t *testing.T) { | ||
c := &Codec{} | ||
var pascalConvertTests = []CaseConvertTest{ | ||
{"foo_bar", "FooBar"}, | ||
{"FooBar", "FooBar"}, | ||
{"True", "True"}, | ||
{"return", "Return"}, | ||
} | ||
for _, test := range pascalConvertTests { | ||
if output := c.ToPascal(test.Input); output != test.Expected { | ||
t.Errorf("Output %s not equal to expected %s, input=%s", output, test.Expected, test.Input) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.