| 1 |
package strutil |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
"time" |
| 6 |
) |
| 7 |
|
| 8 |
func TestResize(t *testing.T) { |
| 9 |
s := "foo" |
| 10 |
got := Resize(s, 5) |
| 11 |
if len(got) != 5 { |
| 12 |
t.Fatal("want", 5, "got", len(got)) |
| 13 |
} |
| 14 |
s = "foobar" |
| 15 |
got = Resize(s, 5) |
| 16 |
|
| 17 |
if got != "fo..." { |
| 18 |
t.Fatal("want", "fo...", "got", got) |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
func TestPadRight(t *testing.T) { |
| 23 |
got := PadRight("foo", 5, '-') |
| 24 |
if got != "foo--" { |
| 25 |
t.Fatal("want", "foo--", "got", got) |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
func TestPadLeft(t *testing.T) { |
| 30 |
got := PadLeft("foo", 5, '-') |
| 31 |
if got != "--foo" { |
| 32 |
t.Fatal("want", "--foo", "got", got) |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
func TestPrettyTime(t *testing.T) { |
| 37 |
d, _ := time.ParseDuration("") |
| 38 |
got := PrettyTime(d) |
| 39 |
if got != "---" { |
| 40 |
t.Fatal("want", "---", "got", got) |
| 41 |
} |
| 42 |
} |