Skip to content

Commit

Permalink
stringutil.Concat: len(parts) == 1
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Feb 25, 2024
1 parent 1698ae2 commit 22936bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions stringutil/concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package stringutil

// Concat concatenates parts of a string together.
func Concat(parts ...string) string {
if len(parts) == 1 {
return parts[0]
}
n := 0
for _, part := range parts {
n += len(part)
Expand Down
3 changes: 3 additions & 0 deletions stringutil/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
)

func TestConcat(t *testing.T) {
if ret := Concat("1"); ret != "1" {
t.Fatal("Concat(1):", ret)
}
if ret := Concat("1", "23", "!"); ret != "123!" {
t.Fatal("Concat:", ret)
}
Expand Down

0 comments on commit 22936bf

Please sign in to comment.