cli/utils/table_printer_test.go
Mislav Marohnić 61ff5d73bd Fix crash in issue/pr list for narrow terminals
If the available column width is smaller than 3, don't try to truncate
with ellipsis (`...`). Instead, just truncate to available width.
2020-02-18 20:03:09 +01:00

31 lines
537 B
Go

package utils
import (
"bytes"
"testing"
)
func Test_ttyTablePrinter_truncate(t *testing.T) {
buf := bytes.Buffer{}
tp := &ttyTablePrinter{
out: &buf,
maxWidth: 5,
}
tp.AddField("1", nil, nil)
tp.AddField("hello", nil, nil)
tp.EndRow()
tp.AddField("2", nil, nil)
tp.AddField("world", nil, nil)
tp.EndRow()
err := tp.Render()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
expected := "1 he\n2 wo\n"
if buf.String() != expected {
t.Errorf("expected: %q, got: %q", expected, buf.String())
}
}