From 5727f38c3e7290322f81a48d9741d3bfa505e27b Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Fri, 20 Jan 2023 16:52:39 +0545 Subject: [PATCH] fix: camelcase result as pascal case issue resolved --- stringy.go | 6 +++++- stringy_test.go | 12 ++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/stringy.go b/stringy.go index 943ef89..801a7ab 100644 --- a/stringy.go +++ b/stringy.go @@ -119,7 +119,11 @@ func (i *input) CamelCase(rule ...string) string { // removing excess space wordArray := caseHelper(input, true, rule...) for i, word := range wordArray { - wordArray[i] = ucfirst(word) + if i == 0 { + wordArray[i] = strings.ToLower(word) + } else { + wordArray[i] = ucfirst(word) + } } return strings.Join(wordArray, "") } diff --git a/stringy_test.go b/stringy_test.go index 82a51fb..0ab5ede 100644 --- a/stringy_test.go +++ b/stringy_test.go @@ -78,16 +78,16 @@ func TestInput_BooleanError(t *testing.T) { func TestInput_CamelCase(t *testing.T) { str := New("Camel case this_complicated__string%%") val := str.CamelCase("%", "") - if val != "CamelCaseThisComplicatedString" { - t.Errorf("Expected: to be %s but got: %s", "CamelCaseThisComplicatedString", val) + if val != "camelCaseThisComplicatedString" { + t.Errorf("Expected: to be %s but got: %s", "camelCaseThisComplicatedString", val) } } func TestInput_CamelCaseNoRule(t *testing.T) { str := New("Camel case this_complicated__string%%") val := str.CamelCase() - if val != "CamelCaseThisComplicatedString%%" { - t.Errorf("Expected: to be %s but got: %s", "CamelCaseThisComplicatedString", val) + if val != "camelCaseThisComplicatedString%%" { + t.Errorf("Expected: to be %s but got: %s", "camelCaseThisComplicatedString", val) } } @@ -100,8 +100,8 @@ func TestInput_CamelCaseOddRuleError(t *testing.T) { str := New("Camel case this_complicated__string%%") val := str.CamelCase("%") - if val != "CamelCaseThisComplicatedString%%" { - t.Errorf("Expected: to be %s but got: %s", "CamelCaseThisComplicatedString", val) + if val != "camelCaseThisComplicatedString%%" { + t.Errorf("Expected: to be %s but got: %s", "camelCaseThisComplicatedString", val) } }