Skip to content

Commit

Permalink
TestCapitalize
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jan 12, 2025
1 parent 5e9ce17 commit 33dcf91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions stringutil/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ import (
"testing"
)

func TestCapitalize(t *testing.T) {
if ret := Capitalize(""); ret != "" {
t.Fatal("Capitalize:", ret)
}
if ret := Capitalize("hello"); ret != "Hello" {
t.Fatal("Capitalize:", ret)
}
if ret := Capitalize("Hello"); ret != "Hello" {
t.Fatal("Capitalize:", ret)
}
}

func TestConcat(t *testing.T) {
if ret := Concat("1"); ret != "1" {
t.Fatal("Concat(1):", ret)
Expand Down
2 changes: 1 addition & 1 deletion stringutil/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// its upper case.
func Capitalize(str string) string {
c, nc := utf8.DecodeRuneInString(str)
if c == utf8.RuneError || unicode.IsUpper(c) {
if unicode.IsUpper(c) || c == utf8.RuneError {
return str
}
ret := make([]byte, len(str))
Expand Down

0 comments on commit 33dcf91

Please sign in to comment.