diff --git a/table/render.go b/table/render.go index 8bc0de5..2fa1772 100644 --- a/table/render.go +++ b/table/render.go @@ -307,7 +307,7 @@ func (t *Table) renderRow(out *strings.Builder, row rowStr, hint renderHint) { // split each column into individual lines and render them one-by-one if colMaxLines == 1 { hint.isLastLineOfRow = true - t.renderLine(out, row, hint) + t.renderLine(out, rowWrapped, hint) } else { // convert one row into N # of rows based on colMaxLines rowLines := make([]rowStr, len(row)) diff --git a/table/render_test.go b/table/render_test.go index 110c1a2..6c08f5f 100644 --- a/table/render_test.go +++ b/table/render_test.go @@ -1289,5 +1289,31 @@ func TestTable_Render_SetWidth_Title(t *testing.T) { assert.Equal(t, strings.Join(expectedOut, "\n"), tw.Render()) }) +} + +func TestTable_Render_WidthEnforcer(t *testing.T) { + tw := NewWriter() + tw.AppendRows([]Row{ + {"U2", "Hey", "2021-04-19 13:37", "Yuh yuh yuh"}, + {"S12", "Uhhhh", "2021-04-19 13:37", "Some dummy data here"}, + {"R123", "Lobsters", "2021-04-19 13:37", "I like lobsters"}, + {"R123", "Some big name here and it's pretty big", "2021-04-19 13:37", "Abcdefghijklmnopqrstuvwxyz"}, + {"R123", "Small name", "2021-04-19 13:37", "Abcdefghijklmnopqrstuvwxyz"}, + }) + tw.SetColumnConfigs([]ColumnConfig{ + {Number: 2, WidthMax: 20, WidthMaxEnforcer: text.Trim}, + }) + expectedOut := `+------+----------------------+------------------+----------------------------+ +| U2 | Hey | 2021-04-19 13:37 | Yuh yuh yuh | +| S12 | Uhhhh | 2021-04-19 13:37 | Some dummy data here | +| R123 | Lobsters | 2021-04-19 13:37 | I like lobsters | +| R123 | Some big name here a | 2021-04-19 13:37 | Abcdefghijklmnopqrstuvwxyz | +| R123 | Small name | 2021-04-19 13:37 | Abcdefghijklmnopqrstuvwxyz | ++------+----------------------+------------------+----------------------------+` + actualOut := tw.Render() + assert.Equal(t, expectedOut, actualOut) + if expectedOut != actualOut { + fmt.Println(actualOut) + } }