Fix string truncation in ui/termstatus

Fixes #3046.
This commit is contained in:
greatroar
2020-11-02 12:06:21 +01:00
parent bb4b3481a6
commit 3ed84ff0c6
4 changed files with 35 additions and 14 deletions

View File

@@ -5,7 +5,7 @@ import "testing"
func TestTruncate(t *testing.T) {
var tests = []struct {
input string
maxlen int
width int
output string
}{
{"", 80, ""},
@@ -18,14 +18,17 @@ func TestTruncate(t *testing.T) {
{"foo", 1, "f"},
{"foo", 0, ""},
{"foo", -1, ""},
{"Löwen", 4, "Löwe"},
{"あああああああああ/data", 10, "あああああ"},
{"あああああああああ/data", 11, "あああああ"},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
out := truncate(test.input, test.maxlen)
out := truncate(test.input, test.width)
if out != test.output {
t.Fatalf("wrong output for input %v, maxlen %d: want %q, got %q",
test.input, test.maxlen, test.output, out)
t.Fatalf("wrong output for input %v, width %d: want %q, got %q",
test.input, test.width, test.output, out)
}
})
}