Skip to content

Commit

Permalink
fix(table): unset data rows without causing nil pointer err (#372)
Browse files Browse the repository at this point in the history
* fix(table): unset data rows without causing nil pointer err

* test(table): add ClearRows test to repro nil ptr err
  • Loading branch information
bashbunni authored Oct 3, 2024
1 parent aff713d commit b08e7e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func New() *Table {

// ClearRows clears the table rows.
func (t *Table) ClearRows() *Table {
t.data = nil
t.data = NewStringData()
return t
}

Expand Down
18 changes: 18 additions & 0 deletions table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,24 @@ func TestTableHeightWithOffset(t *testing.T) {
}
}

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, " ", ".")
}
Expand Down

0 comments on commit b08e7e4

Please sign in to comment.