Skip to content

Commit

Permalink
fix enum capitalization (#2630)
Browse files Browse the repository at this point in the history
* fix enum capitalization

* apply suggestion: adding comment
  • Loading branch information
dukhyungkim authored May 11, 2023
1 parent 82a110c commit 33fdd1b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
20 changes: 19 additions & 1 deletion codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,25 @@ func wordWalker(str string, f func(*wordInfo)) {
}

matchCommonInitial := false
if commonInitialisms[strings.ToUpper(word)] {
upperWord := strings.ToUpper(word)
if commonInitialisms[upperWord] {
// If the uppercase word (string(runes[w:i]) is "ID" or "IP"
// AND
// the word is the first two characters of the str
// AND
// that is not the end of the word
// AND
// the length of the string is greater than 3
// AND
// the third rune is an uppercase one
// THEN
// do NOT count this as an initialism.
switch upperWord {
case "ID", "IP":
if word == str[:2] && !eow && len(str) > 3 && unicode.IsUpper(runes[3]) {
continue
}
}
hasCommonInitial = true
matchCommonInitial = true
}
Expand Down
18 changes: 18 additions & 0 deletions codegen/templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ func TestToGo(t *testing.T) {
require.Equal(t, "RelatedUrls", ToGo("RelatedUrls"))
require.Equal(t, "ITicket", ToGo("ITicket"))
require.Equal(t, "FooTicket", ToGo("fooTicket"))

require.Equal(t, "Idle", ToGo("IDLE"))
require.Equal(t, "Idle", ToGo("Idle"))
require.Equal(t, "Idle", ToGo("idle"))
require.Equal(t, "Identities", ToGo("IDENTITIES"))
require.Equal(t, "Identities", ToGo("Identities"))
require.Equal(t, "Identities", ToGo("identities"))
require.Equal(t, "Iphone", ToGo("IPHONE"))
require.Equal(t, "IPhone", ToGo("iPHONE"))
}

func TestToGoPrivate(t *testing.T) {
Expand Down Expand Up @@ -73,6 +82,15 @@ func TestToGoPrivate(t *testing.T) {
require.Equal(t, "id", ToGoPrivate("id"))
require.Equal(t, "", ToGoPrivate(""))
require.Equal(t, "_", ToGoPrivate("_"))

require.Equal(t, "idle", ToGoPrivate("IDLE"))
require.Equal(t, "idle", ToGoPrivate("Idle"))
require.Equal(t, "idle", ToGoPrivate("idle"))
require.Equal(t, "identities", ToGoPrivate("IDENTITIES"))
require.Equal(t, "identities", ToGoPrivate("Identities"))
require.Equal(t, "identities", ToGoPrivate("identities"))
require.Equal(t, "iphone", ToGoPrivate("IPHONE"))
require.Equal(t, "iPhone", ToGoPrivate("iPHONE"))
}

func TestToGoModelName(t *testing.T) {
Expand Down

0 comments on commit 33fdd1b

Please sign in to comment.