Skip to content

Commit 2650592

Browse files
committed
Add unit test for TestGetCellStringFunc, and simplify code
1 parent 79b9d65 commit 2650592

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

cell.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,11 +1502,11 @@ func (f *File) getCellStringFunc(sheet, cell string, fn func(x *xlsxWorksheet, c
15021502
idx, found := sort.Find(len(ws.SheetData.Row), func(i int) int {
15031503
if ws.SheetData.Row[i].R == row {
15041504
return 0
1505-
} else if ws.SheetData.Row[i].R > row {
1505+
}
1506+
if ws.SheetData.Row[i].R > row {
15061507
return -1
1507-
} else {
1508-
return 1
15091508
}
1509+
return 1
15101510
})
15111511
if !found {
15121512
return "", nil

cell_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,3 +1265,14 @@ func TestSetCellIntFunc(t *testing.T) {
12651265
func TestSIString(t *testing.T) {
12661266
assert.Empty(t, xlsxSI{}.String())
12671267
}
1268+
1269+
func TestGetCellStringFunc(t *testing.T) {
1270+
f := NewFile()
1271+
ws, ok := f.Sheet.Load("xl/worksheets/sheet1.xml")
1272+
assert.True(t, ok)
1273+
ws.(*xlsxWorksheet).SheetData.Row = []xlsxRow{{R: 2}}
1274+
val, err := f.GetCellValue("Sheet1", "A1")
1275+
assert.Empty(t, val)
1276+
assert.NoError(t, err)
1277+
assert.NoError(t, f.Close())
1278+
}

0 commit comments

Comments
 (0)