diff options
author | xuri <xuri.me@gmail.com> | 2019-03-24 13:08:32 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2019-03-24 13:08:32 +0800 |
commit | f0244c00161ad6372ceb1ec951f3a82c741cd46a (patch) | |
tree | aafa677e607193b121575d8a734fdd70fa291b56 /adjust_test.go | |
parent | 40ff5dc1a7d7aa42f5db9cf9dfe858cc3820b44e (diff) |
Add unit test to improve testing coverage
Diffstat (limited to 'adjust_test.go')
-rw-r--r-- | adjust_test.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/adjust_test.go b/adjust_test.go new file mode 100644 index 0000000..104eff9 --- /dev/null +++ b/adjust_test.go @@ -0,0 +1,66 @@ +package excelize + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAdjustMergeCells(t *testing.T) { + f := NewFile() + // testing adjustAutoFilter with illegal cell coordinates. + assert.EqualError(t, f.adjustMergeCells(&xlsxWorksheet{ + MergeCells: &xlsxMergeCells{ + Cells: []*xlsxMergeCell{ + &xlsxMergeCell{ + Ref: "A:B1", + }, + }, + }, + }, rows, 0, 0), `cannot convert cell "A" to coordinates: invalid cell name "A"`) + assert.EqualError(t, f.adjustMergeCells(&xlsxWorksheet{ + MergeCells: &xlsxMergeCells{ + Cells: []*xlsxMergeCell{ + &xlsxMergeCell{ + Ref: "A1:B", + }, + }, + }, + }, rows, 0, 0), `cannot convert cell "B" to coordinates: invalid cell name "B"`) +} + +func TestAdjustAutoFilter(t *testing.T) { + f := NewFile() + // testing adjustAutoFilter with illegal cell coordinates. + assert.EqualError(t, f.adjustAutoFilter(&xlsxWorksheet{ + AutoFilter: &xlsxAutoFilter{ + Ref: "A:B1", + }, + }, rows, 0, 0), `cannot convert cell "A" to coordinates: invalid cell name "A"`) + assert.EqualError(t, f.adjustAutoFilter(&xlsxWorksheet{ + AutoFilter: &xlsxAutoFilter{ + Ref: "A1:B", + }, + }, rows, 0, 0), `cannot convert cell "B" to coordinates: invalid cell name "B"`) +} + +func TestAdjustHelper(t *testing.T) { + f := NewFile() + f.Sheet["xl/worksheets/sheet1.xml"] = &xlsxWorksheet{ + MergeCells: &xlsxMergeCells{ + Cells: []*xlsxMergeCell{ + &xlsxMergeCell{ + Ref: "A:B1", + }, + }, + }, + } + f.Sheet["xl/worksheets/sheet2.xml"] = &xlsxWorksheet{ + AutoFilter: &xlsxAutoFilter{ + Ref: "A1:B", + }, + } + // testing adjustHelper with illegal cell coordinates. + assert.EqualError(t, f.adjustHelper("sheet1", rows, 0, 0), `cannot convert cell "A" to coordinates: invalid cell name "A"`) + assert.EqualError(t, f.adjustHelper("sheet2", rows, 0, 0), `cannot convert cell "B" to coordinates: invalid cell name "B"`) +} |