github.com/andrewhsu/cli/v2@v2.0.1-0.20210910131313-d4b4061f5b89/utils/table_printer_test.go (about) 1 package utils 2 3 import ( 4 "bytes" 5 "testing" 6 ) 7 8 func Test_ttyTablePrinter_truncate(t *testing.T) { 9 buf := bytes.Buffer{} 10 tp := &ttyTablePrinter{ 11 out: &buf, 12 maxWidth: 5, 13 } 14 15 tp.AddField("1", nil, nil) 16 tp.AddField("hello", nil, nil) 17 tp.EndRow() 18 tp.AddField("2", nil, nil) 19 tp.AddField("world", nil, nil) 20 tp.EndRow() 21 22 err := tp.Render() 23 if err != nil { 24 t.Fatalf("unexpected error: %v", err) 25 } 26 27 expected := "1 he\n2 wo\n" 28 if buf.String() != expected { 29 t.Errorf("expected: %q, got: %q", expected, buf.String()) 30 } 31 }