fix: camelcase result as pascal case issue resolved

This commit is contained in:
Roshan Ranabhat 2023-01-20 16:52:39 +05:45
parent 103d950d1d
commit 5727f38c3e
2 changed files with 11 additions and 7 deletions

View File

@ -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, "")
}

View File

@ -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)
}
}