diff --git a/table/table.go b/table/table.go index a859729a..0380149b 100644 --- a/table/table.go +++ b/table/table.go @@ -89,7 +89,7 @@ func New() *Table { // ClearRows clears the table rows. func (t *Table) ClearRows() *Table { - t.data = nil + t.data = NewStringData() return t } diff --git a/table/table_test.go b/table/table_test.go index 50cfc35d..ca8d43e1 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -1168,6 +1168,24 @@ func TestStyleFunc(t *testing.T) { golden.RequireEqual(t, []byte(table.String())) } +func TestClearRows(t *testing.T) { + defer func() { + if r := recover(); r != nil { + t.Fatalf("had to recover: %v", r) + } + }() + + table := New(). + Border(lipgloss.NormalBorder()). + Headers("LANGUAGE", "FORMAL", "INFORMAL"). + Row("Chinese", "Nǐn hǎo", "Nǐ hǎo") + table.ClearRows() + table.Row("French", "Bonjour", "Salut") + + // String() will try to get the rows from table.data + table.String() +} + func debug(s string) string { return strings.ReplaceAll(s, " ", ".") }