From 44903436f27957a4f67411e0314f10892c4bc0eb Mon Sep 17 00:00:00 2001 From: Yassine EL AISSAOUI Date: Tue, 11 Mar 2025 15:17:07 +0100 Subject: [PATCH 1/2] fix: camelCase returning capital letter in the middle of words --- render/template_helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render/template_helpers.go b/render/template_helpers.go index 7d69bd66..58df1a4e 100644 --- a/render/template_helpers.go +++ b/render/template_helpers.go @@ -499,7 +499,7 @@ func camelCase(str string) string { // Capitalize each word capitalized := []string{} for _, word := range words { - capitalized = append(capitalized, strings.Title(word)) + capitalized = append(capitalized, strings.Title(strings.ToLower(word))) } // Join everything back together into a string From 3fae98134c18218d1003b70ebdddd06e04b99665 Mon Sep 17 00:00:00 2001 From: Yassine EL AISSAOUI Date: Tue, 25 Mar 2025 12:06:24 +0100 Subject: [PATCH 2/2] fix: tests for camelCase --- render/render_template_test.go | 4 +-- render/template_helpers_test.go | 48 ++++++++++++++++----------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/render/render_template_test.go b/render/render_template_test.go index b667dd8c..b9d16525 100644 --- a/render/render_template_test.go +++ b/render/render_template_test.go @@ -81,8 +81,8 @@ func TestRenderTemplate(t *testing.T) { {"Floor test: {{ .Foo | floor }}", map[string]interface{}{"Foo": "0.45"}, options.ExitWithError, "", "Floor test: 0", false}, {"Dasherize test: {{ .Foo | dasherize }}", map[string]interface{}{"Foo": "foo BAR baz!"}, options.ExitWithError, "", "Dasherize test: foo-bar-baz", false}, {"Snake case test: {{ .Foo | snakeCase }}", map[string]interface{}{"Foo": "foo BAR baz!"}, options.ExitWithError, "", "Snake case test: foo_bar_baz", false}, - {"Camel case test: {{ .Foo | camelCase }}", map[string]interface{}{"Foo": "foo BAR baz!"}, options.ExitWithError, "", "Camel case test: FooBARBaz", false}, - {"Camel case lower test: {{ .Foo | camelCaseLower }}", map[string]interface{}{"Foo": "foo BAR baz!"}, options.ExitWithError, "", "Camel case lower test: fooBARBaz", false}, + {"Camel case test: {{ .Foo | camelCase }}", map[string]interface{}{"Foo": "foo BAR baz!"}, options.ExitWithError, "", "Camel case test: FooBarBaz", false}, + {"Camel case lower test: {{ .Foo | camelCaseLower }}", map[string]interface{}{"Foo": "foo BAR baz!"}, options.ExitWithError, "", "Camel case lower test: fooBarBaz", false}, {"Plus test: {{ plus .Foo .Bar }}", map[string]interface{}{"Foo": "5", "Bar": "3"}, options.ExitWithError, "", "Plus test: 8", false}, {"Minus test: {{ minus .Foo .Bar }}", map[string]interface{}{"Foo": "5", "Bar": "3"}, options.ExitWithError, "", "Minus test: 2", false}, {"Times test: {{ times .Foo .Bar }}", map[string]interface{}{"Foo": "5", "Bar": "3"}, options.ExitWithError, "", "Times test: 15", false}, diff --git a/render/template_helpers_test.go b/render/template_helpers_test.go index 86b87dbd..858f5520 100644 --- a/render/template_helpers_test.go +++ b/render/template_helpers_test.go @@ -341,20 +341,20 @@ func TestCamelCase(t *testing.T) { {"", ""}, {" ", ""}, {"foo", "Foo"}, - {"FOO", "FOO"}, + {"FOO", "Foo"}, {" \t foo \t", "Foo"}, - {"FooBarBaz", "FooBarBaz"}, + {"FooBarBaz", "Foobarbaz"}, {"Fo", "Fo"}, - {"fooID", "FooID"}, - {"FoB", "FoB"}, - {"oFo", "OFo"}, - {"FoBa", "FoBa"}, - {"oFoBa", "OFoBa"}, - {"oFoB", "OFoB"}, - {"Foo123B1234Baz1234", "Foo123B1234Baz1234"}, + {"fooID", "Fooid"}, + {"FoB", "Fob"}, + {"oFo", "Ofo"}, + {"FoBa", "Foba"}, + {"oFoBa", "Ofoba"}, + {"oFoB", "Ofob"}, + {"Foo123B1234Baz1234", "Foo123b1234baz1234"}, {"Foo_Bar_Baz", "FooBarBaz"}, - {"FooIDbarBaz", "FooIDbarBaz"}, - {"FOOIDbarBaz", "FOOIDbarBaz"}, + {"FooIDbarBaz", "Fooidbarbaz"}, + {"FOOIDbarBaz", "Fooidbarbaz"}, {" A B C ", "ABC"}, {"foo bar baz", "FooBarBaz"}, {"foo \t \tbar baz \t", "FooBarBaz"}, @@ -364,7 +364,7 @@ func TestCamelCase(t *testing.T) { {"foo--bar----baz", "FooBarBaz"}, {"foo__bar____baz", "FooBarBaz"}, {" Foo Bar Baz ", "FooBarBaz"}, - {" Foo Bar_BazBlah ", "FooBarBazBlah"}, + {" Foo Bar_BazBlah ", "FooBarBazblah"}, {" Foo.Bar.Baz", "FooBarBaz"}, {"#@!Foo@#$@$Bar>>>>>Baz", "FooBarBaz"}, } @@ -385,20 +385,20 @@ func TestCamelCaseLower(t *testing.T) { {"", ""}, {" ", ""}, {"foo", "foo"}, - {"FOO", "fOO"}, + {"FOO", "foo"}, {" \t foo \t", "foo"}, - {"FooBarBaz", "fooBarBaz"}, + {"FooBarBaz", "foobarbaz"}, {"Fo", "fo"}, - {"fooID", "fooID"}, - {"FoB", "foB"}, - {"oFo", "oFo"}, - {"FoBa", "foBa"}, - {"oFoBa", "oFoBa"}, - {"oFoB", "oFoB"}, - {"Foo123B1234Baz1234", "foo123B1234Baz1234"}, + {"fooID", "fooid"}, + {"FoB", "fob"}, + {"oFo", "ofo"}, + {"FoBa", "foba"}, + {"oFoBa", "ofoba"}, + {"oFoB", "ofob"}, + {"Foo123B1234Baz1234", "foo123b1234baz1234"}, {"Foo_Bar_Baz", "fooBarBaz"}, - {"FooIDbarBaz", "fooIDbarBaz"}, - {"FOOIDbarBaz", "fOOIDbarBaz"}, + {"FooIDbarBaz", "fooidbarbaz"}, + {"FOOIDbarBaz", "fooidbarbaz"}, {" A B C ", "aBC"}, {"foo bar baz", "fooBarBaz"}, {"foo \t \tbar baz \t", "fooBarBaz"}, @@ -408,7 +408,7 @@ func TestCamelCaseLower(t *testing.T) { {"foo--bar----baz", "fooBarBaz"}, {"foo__bar____baz", "fooBarBaz"}, {" Foo Bar Baz ", "fooBarBaz"}, - {" Foo Bar_BazBlah ", "fooBarBazBlah"}, + {" Foo Bar_BazBlah ", "fooBarBazblah"}, {" Foo.Bar.Baz", "fooBarBaz"}, {"#@!Foo@#$@$Bar>>>>>Baz", "fooBarBaz"}, }