Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func CamelSplitTokens(str string) []string {
} else {
upperCount = 0
split = true
// For non-alphanumeric characters at the end of the string,
// include them in the current buffer before splitting to preserve them
if i == len(str)-1 && len(buf) > 0 {
buf = append(buf, c)
}
inc = false
}
if split && len(buf) > 0 {
Expand Down
20 changes: 20 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,23 @@ func TestInArray(t *testing.T) {
}
}
}

func TestCamelSplit(t *testing.T) {
cases := []struct {
in string
want string
}{
{"TEST", "test"},
{"GPUTestScore", "gpu_test_score"},
{"UserName", "user_name"},
{"AuthURL", "auth_url"},
{"ID_", "id_"},
{"DEPLOYMENT_ID_", "deployment_id_"},
}
for _, c := range cases {
got := CamelSplit(c.in, "_")
if got != c.want {
t.Errorf("CamelSplit(%s) = %s, want %s", c.in, got, c.want)
}
}
}