From 421f945f51f254054991127758db0520cf0f5456 Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 8 Jun 2019 00:00:55 +0800 Subject: Fixed #418, #420, #421, init adjust calculation chain support Update testing case --- adjust_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'adjust_test.go') diff --git a/adjust_test.go b/adjust_test.go index 7b708ab..28432bc 100644 --- a/adjust_test.go +++ b/adjust_test.go @@ -67,3 +67,19 @@ func TestAdjustHelper(t *testing.T) { // testing adjustHelper on not exists worksheet. assert.EqualError(t, f.adjustHelper("SheetN", rows, 0, 0), "sheet SheetN is not exist") } + +func TestAdjustCalcChain(t *testing.T) { + f := NewFile() + f.CalcChain = &xlsxCalcChain{ + C: []xlsxCalcChainC{ + {R: "B2"}, + }, + } + assert.NoError(t, f.InsertCol("Sheet1", "A")) + assert.NoError(t, f.InsertRow("Sheet1", 1)) + + f.CalcChain.C[0].R = "invalid coordinates" + assert.EqualError(t, f.InsertCol("Sheet1", "A"), `cannot convert cell "invalid coordinates" to coordinates: invalid cell name "invalid coordinates"`) + f.CalcChain = nil + assert.NoError(t, f.InsertCol("Sheet1", "A")) +} -- cgit v1.2.1 From 821632cf89422b9955160a3af7f28f05a12f70f8 Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 12 Jun 2019 08:10:33 +0800 Subject: Fix #424, refactor merged cells adjuster --- adjust_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'adjust_test.go') diff --git a/adjust_test.go b/adjust_test.go index 28432bc..364a8b8 100644 --- a/adjust_test.go +++ b/adjust_test.go @@ -27,6 +27,24 @@ func TestAdjustMergeCells(t *testing.T) { }, }, }, rows, 0, 0), `cannot convert cell "B" to coordinates: invalid cell name "B"`) + assert.NoError(t, f.adjustMergeCells(&xlsxWorksheet{ + MergeCells: &xlsxMergeCells{ + Cells: []*xlsxMergeCell{ + { + Ref: "A1:B1", + }, + }, + }, + }, rows, 1, -1)) + assert.NoError(t, f.adjustMergeCells(&xlsxWorksheet{ + MergeCells: &xlsxMergeCells{ + Cells: []*xlsxMergeCell{ + { + Ref: "A1:A2", + }, + }, + }, + }, columns, 1, -1)) } func TestAdjustAutoFilter(t *testing.T) { @@ -83,3 +101,16 @@ func TestAdjustCalcChain(t *testing.T) { f.CalcChain = nil assert.NoError(t, f.InsertCol("Sheet1", "A")) } + +func TestCoordinatesToAreaRef(t *testing.T) { + f := NewFile() + ref, err := f.coordinatesToAreaRef([]int{}) + assert.EqualError(t, err, "coordinates length must be 4") + ref, err = f.coordinatesToAreaRef([]int{1, -1, 1, 1}) + assert.EqualError(t, err, "invalid cell coordinates [1, -1]") + ref, err = f.coordinatesToAreaRef([]int{1, 1, 1, -1}) + assert.EqualError(t, err, "invalid cell coordinates [1, -1]") + ref, err = f.coordinatesToAreaRef([]int{1, 1, 1, 1}) + assert.NoError(t, err) + assert.EqualValues(t, ref, "A1:A1") +} -- cgit v1.2.1 From 9f8623047d2fc38e12c3b214475710d25ec88c55 Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 20 Jun 2019 00:00:40 +0800 Subject: Optimize code, fix golint issues --- adjust_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'adjust_test.go') diff --git a/adjust_test.go b/adjust_test.go index 364a8b8..a0de844 100644 --- a/adjust_test.go +++ b/adjust_test.go @@ -104,13 +104,13 @@ func TestAdjustCalcChain(t *testing.T) { func TestCoordinatesToAreaRef(t *testing.T) { f := NewFile() - ref, err := f.coordinatesToAreaRef([]int{}) + _, err := f.coordinatesToAreaRef([]int{}) assert.EqualError(t, err, "coordinates length must be 4") - ref, err = f.coordinatesToAreaRef([]int{1, -1, 1, 1}) + _, err = f.coordinatesToAreaRef([]int{1, -1, 1, 1}) assert.EqualError(t, err, "invalid cell coordinates [1, -1]") - ref, err = f.coordinatesToAreaRef([]int{1, 1, 1, -1}) + _, err = f.coordinatesToAreaRef([]int{1, 1, 1, -1}) assert.EqualError(t, err, "invalid cell coordinates [1, -1]") - ref, err = f.coordinatesToAreaRef([]int{1, 1, 1, 1}) + ref, err := f.coordinatesToAreaRef([]int{1, 1, 1, 1}) assert.NoError(t, err) assert.EqualValues(t, ref, "A1:A1") } -- cgit v1.2.1 From 09485b3f9f0aefc58d51462aed65c2416205c591 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 29 Dec 2019 16:02:31 +0800 Subject: Improve code coverage unit tests --- adjust_test.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'adjust_test.go') diff --git a/adjust_test.go b/adjust_test.go index a0de844..13e47ff 100644 --- a/adjust_test.go +++ b/adjust_test.go @@ -114,3 +114,7 @@ func TestCoordinatesToAreaRef(t *testing.T) { assert.NoError(t, err) assert.EqualValues(t, ref, "A1:A1") } + +func TestSortCoordinates(t *testing.T) { + assert.EqualError(t, sortCoordinates(make([]int, 3)), "coordinates length must be 4") +} -- cgit v1.2.1