github.com/wtfutil/wtf@v0.43.0/view/info_table_test.go (about) 1 package view 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func makeMap() map[string]string { 10 m := make(map[string]string) 11 m["foo"] = "val1" 12 m["bar"] = "val2" 13 m["baz"] = "val3" 14 15 return m 16 } 17 18 func newTestTable(height, colWidth0, colWidth1 int) *InfoTable { 19 var headers [2]string 20 21 headers[0] = "hdr0" 22 headers[1] = "hdr1" 23 24 table := NewInfoTable( 25 headers[:], 26 makeMap(), 27 colWidth0, 28 colWidth1, 29 height, 30 ) 31 return table 32 } 33 34 func Test_RenderSimpleInfoTable(t *testing.T) { 35 table := newTestTable(4, 1, 1).Render() 36 37 assert.Equal(t, " ----- ------ \n HDR0 HDR1 \n ----- ------ \n bar val2 \n baz val3 \n foo val1 \n ----- ------ \n", table) 38 } 39 40 func Test_RenderPaddedInfoTable(t *testing.T) { 41 table := newTestTable(6, 1, 1).Render() 42 43 assert.Equal(t, " ----- ------ \n HDR0 HDR1 \n ----- ------ \n bar val2 \n baz val3 \n foo val1 \n \n \n ----- ------ \n", table) 44 } 45 46 func Test_RenderWithSpecifiedWidthLeftColumn(t *testing.T) { 47 table := newTestTable(4, 10, 1).Render() 48 49 assert.Equal(t, " ------------ ------ \n HDR0 HDR1 \n ------------ ------ \n bar val2 \n baz val3 \n foo val1 \n ------------ ------ \n", table) 50 } 51 52 func Test_RenderWithSpecifiedWidthRightColumn(t *testing.T) { 53 table := newTestTable(4, 1, 10).Render() 54 55 assert.Equal(t, " ----- ------------ \n HDR0 HDR1 \n ----- ------------ \n bar val2 \n baz val3 \n foo val1 \n ----- ------------ \n", table) 56 } 57 58 func Test_RenderWithSpecifiedWidthBothColumns(t *testing.T) { 59 table := newTestTable(4, 15, 10).Render() 60 61 assert.Equal(t, " ----------------- ------------ \n HDR0 HDR1 \n ----------------- ------------ \n bar val2 \n baz val3 \n foo val1 \n ----------------- ------------ \n", table) 62 }