mirror of https://github.com/gobeam/stringy.git
Merge pull request #9 from mattcarmody/lcFirst-bug
Fix LcFirst bug with leading multi-byte character. Addresses #8
This commit is contained in:
commit
342f99b0fa
|
@ -180,10 +180,10 @@ func (i *input) Last(length int) string {
|
||||||
// function which return StringManipulation interface
|
// function which return StringManipulation interface
|
||||||
func (i *input) LcFirst() string {
|
func (i *input) LcFirst() string {
|
||||||
input := getInput(*i)
|
input := getInput(*i)
|
||||||
for i, v := range input {
|
for _, v := range input {
|
||||||
return string(unicode.ToLower(v)) + input[i+1:]
|
return string(unicode.ToLower(v)) + input[len(string(v)):]
|
||||||
}
|
}
|
||||||
return input
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lines returns slice of strings by removing white space characters
|
// Lines returns slice of strings by removing white space characters
|
||||||
|
|
|
@ -123,18 +123,34 @@ func TestInput_KebabCase(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInput_LcFirst(t *testing.T) {
|
func TestInput_LcFirst(t *testing.T) {
|
||||||
str := New("This is an all lower")
|
tests := []struct {
|
||||||
against := "this is an all lower"
|
name string
|
||||||
if val := str.LcFirst(); val != against {
|
arg string
|
||||||
t.Errorf("Expected: to be %s but got: %s", against, val)
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "leading uppercase",
|
||||||
|
arg: "This is an all lower",
|
||||||
|
want: "this is an all lower",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty string",
|
||||||
|
arg: "",
|
||||||
|
want: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multi-byte leading character",
|
||||||
|
arg: "ΔΔΔ",
|
||||||
|
want: "δΔΔ",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func TestInput_LcFirstEmpty(t *testing.T) {
|
for _, tt := range tests {
|
||||||
str := New("")
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
against := ""
|
if got := New(tt.arg).LcFirst(); got != tt.want {
|
||||||
if val := str.LcFirst(); val != against {
|
t.Errorf("LcFirst(%v) = %v, want %v", tt.arg, got, tt.want)
|
||||||
t.Errorf("Expected: to be %s but got: %s", against, val)
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue