termstatus: Fix panic for non-terminal runs

Closes #1803
This commit is contained in:
Alexander Neumann
2018-05-27 12:51:42 +02:00
parent 4bf07a74a0
commit 7d9642523b
2 changed files with 48 additions and 6 deletions

View File

@@ -0,0 +1,32 @@
package termstatus
import "testing"
func TestTruncate(t *testing.T) {
var tests = []struct {
input string
maxlen int
output string
}{
{"", 80, ""},
{"", 0, ""},
{"", -1, ""},
{"foo", 80, "foo"},
{"foo", 4, "foo"},
{"foo", 3, "foo"},
{"foo", 2, "fo"},
{"foo", 1, "f"},
{"foo", 0, ""},
{"foo", -1, ""},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
out := truncate(test.input, test.maxlen)
if out != test.output {
t.Fatalf("wrong output for input %v, maxlen %d: want %q, got %q",
test.input, test.maxlen, test.output, out)
}
})
}
}