util: Moar tests.

This commit is contained in:
Qi Xiao 2017-12-19 02:16:49 +00:00
parent 85ba184b5a
commit e0ee3f1a07

View File

@ -38,3 +38,39 @@ func TestOverrideWcwidth(t *testing.T) {
t.Errorf("Wcwidth(%q) != %d after UnoverrideWcwidth", r, oldw)
}
}
func TestTrimWcwidth(t *testing.T) {
if TrimWcwidth("abc", 2) != "ab" {
t.Errorf("TrimWcwidth #1 fails")
}
if TrimWcwidth("你好", 3) != "你" {
t.Errorf("TrimWcwidth #2 fails")
}
}
func TestForceWcwidth(t *testing.T) {
for i, c := range []struct {
s string
w int
want string
}{
// Triming
{"abc", 2, "ab"},
{"你好", 2, "你"},
// Padding
{"abc", 4, "abc "},
{"你好", 5, "你好 "},
// Trimming and Padding
{"你好", 3, "你 "},
} {
if got := ForceWcwidth(c.s, c.w); got != c.want {
t.Errorf("ForceWcwidth #%d fails", i)
}
}
}
func TestTrimEachLineWcwidth(t *testing.T) {
if TrimEachLineWcwidth("abcdefg\n你好", 3) != "abc\n你" {
t.Errorf("TestTrimEachLineWcwidth fails")
}
}