Skip to content

Commit

Permalink
👔 update: strutil - update the Repeat() handle logic on times < 1
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 27, 2023
1 parent 28271fb commit 3dfc858
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion strutil/padding.go
Expand Up @@ -136,7 +136,10 @@ func PadRunesRight(rs []rune, pad rune, length int) []rune {

// Repeat a string by given times.
func Repeat(s string, times int) string {
if times <= 1 {
if times < 1 {
return ""
}
if times == 1 {
return s
}

Expand Down
4 changes: 2 additions & 2 deletions strutil/padding_test.go
Expand Up @@ -55,8 +55,8 @@ func TestRepeat(t *testing.T) {
assert.Eq(t, "aaa", strutil.Repeat("a", 3))
assert.Eq(t, "DD", strutil.Repeat("D", 2))
assert.Eq(t, "D", strutil.Repeat("D", 1))
assert.Eq(t, "A", strutil.Repeat("A", 0))
assert.Eq(t, "D", strutil.Repeat("D", -3))
assert.Eq(t, "", strutil.Repeat("A", 0))
assert.Eq(t, "", strutil.Repeat("D", -3))
}

func TestRepeatRune(t *testing.T) {
Expand Down

0 comments on commit 3dfc858

Please sign in to comment.