Skip to content

Commit 0961fdc

Browse files
authored
feat: add rows count (#32)
1 parent 0852ecf commit 0961fdc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

table.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,3 +939,8 @@ func (t *Table) Render() {
939939
func (t *Table) IsEmpty() bool {
940940
return len(t.data) == 0
941941
}
942+
943+
// RowCount returns the number of rows in the table.
944+
func (t *Table) RowCount() int {
945+
return len(t.data)
946+
}

table_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,13 @@ func Test_TableIsNotEmpty(t *testing.T) {
830830
table.AddRow("4", "5", "6")
831831
assert.Equal(t, false, table.IsEmpty())
832832
}
833+
834+
func Test_TableRowCount(t *testing.T) {
835+
builder := &strings.Builder{}
836+
table := New(builder)
837+
table.SetHeaders("A", "B", "C")
838+
assert.Equal(t, 0, table.RowCount())
839+
table.AddRow("1", "2", "3")
840+
table.AddRow("4", "5", "6")
841+
assert.Equal(t, 2, table.RowCount())
842+
}

0 commit comments

Comments
 (0)