summaryrefslogtreecommitdiff
path: root/rows_test.go
diff options
context:
space:
mode:
authorli <liying0721@vip.126.com>2021-11-05 00:01:34 +0800
committerGitHub <noreply@github.com>2021-11-05 00:01:34 +0800
commit60b13affbda954261888a7829c88a32993edb5b2 (patch)
treef0d4cedb6003eb8c57c20f36407ca2d4084dd505 /rows_test.go
parente64775fdcc38a9bc882ef32b4d4d491ad63acbdd (diff)
Support get current row/col and total rows/cols in the stream reader (#1054)
Diffstat (limited to 'rows_test.go')
-rw-r--r--rows_test.go22
1 files changed, 10 insertions, 12 deletions
diff --git a/rows_test.go b/rows_test.go
index 19ed866..9fee3d9 100644
--- a/rows_test.go
+++ b/rows_test.go
@@ -65,18 +65,17 @@ func TestRows(t *testing.T) {
}
func TestRowsIterator(t *testing.T) {
- const (
- sheet2 = "Sheet2"
- expectedNumRow = 11
- )
+ sheetName, rowCount, expectedNumRow := "Sheet2", 0, 11
f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
require.NoError(t, err)
- rows, err := f.Rows(sheet2)
+ rows, err := f.Rows(sheetName)
require.NoError(t, err)
- var rowCount int
+
for rows.Next() {
rowCount++
+ assert.Equal(t, rowCount, rows.CurrentRow())
+ assert.Equal(t, expectedNumRow, rows.TotalRows())
require.True(t, rowCount <= expectedNumRow, "rowCount is greater than expected")
}
assert.Equal(t, expectedNumRow, rowCount)
@@ -84,19 +83,18 @@ func TestRowsIterator(t *testing.T) {
assert.NoError(t, f.Close())
// Valued cell sparse distribution test
- f = NewFile()
+ f, sheetName, rowCount, expectedNumRow = NewFile(), "Sheet1", 0, 3
cells := []string{"C1", "E1", "A3", "B3", "C3", "D3", "E3"}
for _, cell := range cells {
- assert.NoError(t, f.SetCellValue("Sheet1", cell, 1))
+ assert.NoError(t, f.SetCellValue(sheetName, cell, 1))
}
- rows, err = f.Rows("Sheet1")
+ rows, err = f.Rows(sheetName)
require.NoError(t, err)
- rowCount = 0
for rows.Next() {
rowCount++
- require.True(t, rowCount <= 3, "rowCount is greater than expected")
+ require.True(t, rowCount <= expectedNumRow, "rowCount is greater than expected")
}
- assert.Equal(t, 3, rowCount)
+ assert.Equal(t, expectedNumRow, rowCount)
}
func TestRowsError(t *testing.T) {