| 83 | } |
| 84 | |
| 85 | func TestRowsIterator(t *testing.T) { |
| 86 | sheetName, rowCount, expectedNumRow := "Sheet2", 0, 11 |
| 87 | f, err := OpenFile(filepath.Join("test", "Book1.xlsx")) |
| 88 | require.NoError(t, err) |
| 89 | |
| 90 | rows, err := f.Rows(sheetName) |
| 91 | require.NoError(t, err) |
| 92 | |
| 93 | for rows.Next() { |
| 94 | rowCount++ |
| 95 | require.True(t, rowCount <= expectedNumRow, "rowCount is greater than expected") |
| 96 | } |
| 97 | assert.Equal(t, expectedNumRow, rowCount) |
| 98 | assert.NoError(t, rows.Close()) |
| 99 | assert.NoError(t, f.Close()) |
| 100 | |
| 101 | // Valued cell sparse distribution test |
| 102 | f, sheetName, rowCount, expectedNumRow = NewFile(), "Sheet1", 0, 3 |
| 103 | cells := []string{"C1", "E1", "A3", "B3", "C3", "D3", "E3"} |
| 104 | for _, cell := range cells { |
| 105 | assert.NoError(t, f.SetCellValue(sheetName, cell, 1)) |
| 106 | } |
| 107 | rows, err = f.Rows(sheetName) |
| 108 | require.NoError(t, err) |
| 109 | for rows.Next() { |
| 110 | rowCount++ |
| 111 | require.True(t, rowCount <= expectedNumRow, "rowCount is greater than expected") |
| 112 | } |
| 113 | assert.Equal(t, expectedNumRow, rowCount) |
| 114 | } |
| 115 | |
| 116 | func TestRowsGetRowOpts(t *testing.T) { |
| 117 | sheetName := "Sheet2" |