From b9630ae4189dc4888e43cd5cd76d175e0a4386ef Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Fri, 14 Nov 2025 15:30:48 +0800 Subject: [PATCH] fix: CamelSplit ignore trailing char --- utils/utils.go | 5 +++++ utils/utils_test.go | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/utils/utils.go b/utils/utils.go index 13ab410..fa65eb4 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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 { diff --git a/utils/utils_test.go b/utils/utils_test.go index da39ea5..cff836a 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -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) + } + } +}