Merge pull request #21 from gobeam/fix/camelCase

fix: camelcase result as pascal case issue resolved
This commit is contained in:
Roshan Ranabhat 2023-01-20 16:54:21 +05:45 committed by GitHub
commit 2605d35cf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -119,8 +119,12 @@ func (i *input) CamelCase(rule ...string) string {
// removing excess space
wordArray := caseHelper(input, true, rule...)
for i, word := range wordArray {
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)
}
}