fix(ui): panic in rightPad
This commit is contained in:
parent
c4287b75b2
commit
3efd009983
@ -464,8 +464,11 @@ func (a *Actor) showAbout() {
|
||||
}
|
||||
|
||||
func rightPad(s string, n int) string {
|
||||
if s == "" {
|
||||
if s == "" || len(s) == n {
|
||||
return s
|
||||
}
|
||||
if len(s) > n {
|
||||
return s[:n]
|
||||
}
|
||||
return s + strings.Repeat(" ", n-len(s))
|
||||
}
|
||||
|
42
terminal/actor_test.go
Normal file
42
terminal/actor_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRightPad(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "empty string",
|
||||
input: "",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "short string",
|
||||
input: "foo",
|
||||
want: "foo ",
|
||||
},
|
||||
{
|
||||
name: "string with equal lenth to required width",
|
||||
input: "foobar",
|
||||
want: "foobar",
|
||||
},
|
||||
{
|
||||
name: "long string",
|
||||
input: "foobarbaz",
|
||||
want: "foobar",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert.Equal(t, tc.want, rightPad(tc.input, 6))
|
||||
})
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user