1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
package strutil
import (
"testing"
)
func TestResize(t *testing.T) {
s := "foo"
got := Resize(s, 5, false)
if len(got) != 5 {
t.Fatal("want", 5, "got", len(got))
}
s = "foobar"
got = Resize(s, 5, false)
if got != "fo..." {
t.Fatal("want", "fo...", "got", got)
}
}
func TestAlign(t *testing.T) {
s := "foo"
got := Resize(s, 5, false)
if got != "foo " {
t.Fatal("want", "foo ", "got", got)
}
got = Resize(s, 5, true)
if got != " foo" {
t.Fatal("want", " foo", "got", got)
}
}
func TestJoin(t *testing.T) {
got := Join([]string{"foo", "bar"}, ",")
if got != "foo,bar" {
t.Fatal("want", "foo,bar", "got", got)
}
}
func TestPadRight(t *testing.T) {
got := PadRight("foo", 5, '-')
if got != "foo--" {
t.Fatal("want", "foo--", "got", got)
}
}
func TestPadLeft(t *testing.T) {
got := PadLeft("foo", 5, '-')
if got != "--foo" {
t.Fatal("want", "--foo", "got", got)
}
}
|