mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-01 08:42:55 +08:00
util: Moar tests.
This commit is contained in:
parent
85ba184b5a
commit
e0ee3f1a07
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user