summaryrefslogtreecommitdiff
path: root/adjust_test.go
diff options
context:
space:
mode:
authorDokiy <49900744+Dokiys@users.noreply.github.com>2021-12-06 22:37:25 +0800
committerGitHub <noreply@github.com>2021-12-06 22:37:25 +0800
commit3325c3946d0ab77083555bab334381a1167ee580 (patch)
tree481222faa55f9b3e25be6224d5e3cb681d64bead /adjust_test.go
parent7af55a54552d36805ed9ad2e2173757fd6626a55 (diff)
Fix adjustMergeCellsHelper and add some test cases (#1082)
Signed-off-by: Dokiys <dokiychang@gmail.com>
Diffstat (limited to 'adjust_test.go')
-rw-r--r--adjust_test.go207
1 files changed, 203 insertions, 4 deletions
diff --git a/adjust_test.go b/adjust_test.go
index f56f763..3509b5d 100644
--- a/adjust_test.go
+++ b/adjust_test.go
@@ -45,6 +45,209 @@ func TestAdjustMergeCells(t *testing.T) {
},
},
}, columns, 1, -1))
+
+ // testing adjustMergeCells
+ var cases []struct {
+ lable string
+ ws *xlsxWorksheet
+ dir adjustDirection
+ num int
+ offset int
+ expect string
+ }
+
+ // testing insert
+ cases = []struct {
+ lable string
+ ws *xlsxWorksheet
+ dir adjustDirection
+ num int
+ offset int
+ expect string
+ }{
+ {
+ lable: "insert row on ref",
+ ws: &xlsxWorksheet{
+ MergeCells: &xlsxMergeCells{
+ Cells: []*xlsxMergeCell{
+ {
+ Ref: "A2:B3",
+ },
+ },
+ },
+ },
+ dir: rows,
+ num: 2,
+ offset: 1,
+ expect: "A3:B4",
+ },
+ {
+ lable: "insert row on bottom of ref",
+ ws: &xlsxWorksheet{
+ MergeCells: &xlsxMergeCells{
+ Cells: []*xlsxMergeCell{
+ {
+ Ref: "A2:B3",
+ },
+ },
+ },
+ },
+ dir: rows,
+ num: 3,
+ offset: 1,
+ expect: "A2:B4",
+ },
+ {
+ lable: "insert column on the left",
+ ws: &xlsxWorksheet{
+ MergeCells: &xlsxMergeCells{
+ Cells: []*xlsxMergeCell{
+ {
+ Ref: "A2:B3",
+ },
+ },
+ },
+ },
+ dir: columns,
+ num: 1,
+ offset: 1,
+ expect: "B2:C3",
+ },
+ }
+ for _, c := range cases {
+ assert.NoError(t, f.adjustMergeCells(c.ws, c.dir, c.num, 1))
+ assert.Equal(t, c.expect, c.ws.MergeCells.Cells[0].Ref, c.lable)
+ }
+
+ // testing delete
+ cases = []struct {
+ lable string
+ ws *xlsxWorksheet
+ dir adjustDirection
+ num int
+ offset int
+ expect string
+ }{
+ {
+ lable: "delete row on top of ref",
+ ws: &xlsxWorksheet{
+ MergeCells: &xlsxMergeCells{
+ Cells: []*xlsxMergeCell{
+ {
+ Ref: "A2:B3",
+ },
+ },
+ },
+ },
+ dir: rows,
+ num: 2,
+ offset: -1,
+ expect: "A2:B2",
+ },
+ {
+ lable: "delete row on bottom of ref",
+ ws: &xlsxWorksheet{
+ MergeCells: &xlsxMergeCells{
+ Cells: []*xlsxMergeCell{
+ {
+ Ref: "A2:B3",
+ },
+ },
+ },
+ },
+ dir: rows,
+ num: 3,
+ offset: -1,
+ expect: "A2:B2",
+ },
+ {
+ lable: "delete column on the ref left",
+ ws: &xlsxWorksheet{
+ MergeCells: &xlsxMergeCells{
+ Cells: []*xlsxMergeCell{
+ {
+ Ref: "A2:B3",
+ },
+ },
+ },
+ },
+ dir: columns,
+ num: 1,
+ offset: -1,
+ expect: "A2:A3",
+ },
+ {
+ lable: "delete column on the ref right",
+ ws: &xlsxWorksheet{
+ MergeCells: &xlsxMergeCells{
+ Cells: []*xlsxMergeCell{
+ {
+ Ref: "A2:B3",
+ },
+ },
+ },
+ },
+ dir: columns,
+ num: 2,
+ offset: -1,
+ expect: "A2:A3",
+ },
+ }
+ for _, c := range cases {
+ assert.NoError(t, f.adjustMergeCells(c.ws, c.dir, c.num, -1))
+ assert.Equal(t, c.expect, c.ws.MergeCells.Cells[0].Ref, c.lable)
+ }
+
+ // testing delete one row/column
+ cases = []struct {
+ lable string
+ ws *xlsxWorksheet
+ dir adjustDirection
+ num int
+ offset int
+ expect string
+ }{
+ {
+ lable: "delete one row ref",
+ ws: &xlsxWorksheet{
+ MergeCells: &xlsxMergeCells{
+ Cells: []*xlsxMergeCell{
+ {
+ Ref: "A1:B1",
+ },
+ },
+ },
+ },
+ dir: rows,
+ num: 1,
+ offset: -1,
+ },
+ {
+ lable: "delete one column ref",
+ ws: &xlsxWorksheet{
+ MergeCells: &xlsxMergeCells{
+ Cells: []*xlsxMergeCell{
+ {
+ Ref: "A1:A2",
+ },
+ },
+ },
+ },
+ dir: columns,
+ num: 1,
+ offset: -1,
+ },
+ }
+ for _, c := range cases {
+ assert.NoError(t, f.adjustMergeCells(c.ws, c.dir, c.num, -1))
+ assert.Equal(t, 0, len(c.ws.MergeCells.Cells), c.lable)
+ }
+
+ f = NewFile()
+ p1, p2 := f.adjustMergeCellsHelper(2, 1, 0, 0)
+ assert.Equal(t, 1, p1)
+ assert.Equal(t, 2, p2)
+ f.deleteMergeCell(nil, -1)
}
func TestAdjustAutoFilter(t *testing.T) {
@@ -84,10 +287,6 @@ func TestAdjustHelper(t *testing.T) {
assert.EqualError(t, f.adjustHelper("SheetN", rows, 0, 0), "sheet SheetN is not exist")
}
-func TestAdjustMergeCellsHelper(t *testing.T) {
- assert.Equal(t, 1, NewFile().adjustMergeCellsHelper(1, 0, -2))
-}
-
func TestAdjustCalcChain(t *testing.T) {
f := NewFile()
f.CalcChain = &xlsxCalcChain{