Skip to content

Commit

Permalink
thrift/thriftutil/enums: avoid duplicating underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
xgoffin committed Jan 3, 2025
1 parent 8599469 commit 0f9a154
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion thrift/thriftutil/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func SanitizeCamelCaseThriftEnumValue(v string) string {
if sks := strings.SplitN(v, "_", 2); len(sks) == 2 {
return stringutil.CamelToSnakeCase(sks[1])
return strings.ReplaceAll(stringutil.CamelToSnakeCase(sks[1]), "__", "_")
}

return strings.ToLower(v)
Expand Down
1 change: 1 addition & 0 deletions thrift/thriftutil/enums_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestSanitizeCamelCaseThriftEnumValue(t *testing.T) {
{"ContentType_InstagramMedia", "instagram_media"},
{"ContentType_Unknown", "unknown"},
{"regular string", "regular string"},
{"MFAVector_RECOVERY_CODE", "recovery_code"},
} {
if out := SanitizeCamelCaseThriftEnumValue(tt.in); tt.out != out {
t.Errorf("SanitizeCamelCaseThriftEnumValue(%q) = %q wanted: %q", tt.in, out, tt.out)
Expand Down

0 comments on commit 0f9a154

Please sign in to comment.