make SetCellStyle quicker by skipping conversions in checkCellInArea, and skipping area checks when we are sure the cell can't be before or past the current row/col
Signed-off-by: Matthieu Bressonformula
parent
50cdaed5a3
commit
317ef65381
@ -0,0 +1,40 @@
|
|||||||
|
package excelize
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestCheckCellInArea(t *testing.T) {
|
||||||
|
expectedTrueCellInAreaList := [][2]string{
|
||||||
|
[2]string{"c2", "A1:AAZ32"},
|
||||||
|
[2]string{"AA0", "Z0:AB1"},
|
||||||
|
[2]string{"B9", "A1:B9"},
|
||||||
|
[2]string{"C2", "C2:C2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, expectedTrueCellInArea := range expectedTrueCellInAreaList {
|
||||||
|
cell := expectedTrueCellInArea[0]
|
||||||
|
area := expectedTrueCellInArea[1]
|
||||||
|
|
||||||
|
cellInArea := checkCellInArea(cell, area)
|
||||||
|
|
||||||
|
if !cellInArea {
|
||||||
|
t.Fatalf("Expected cell %v to be in area %v, got false\n", cell, area)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedFalseCellInAreaList := [][2]string{
|
||||||
|
[2]string{"c2", "A4:AAZ32"},
|
||||||
|
[2]string{"C4", "D6:A1"}, // weird case, but you never know
|
||||||
|
[2]string{"AEF42", "BZ40:AEF41"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, expectedFalseCellInArea := range expectedFalseCellInAreaList {
|
||||||
|
cell := expectedFalseCellInArea[0]
|
||||||
|
area := expectedFalseCellInArea[1]
|
||||||
|
|
||||||
|
cellInArea := checkCellInArea(cell, area)
|
||||||
|
|
||||||
|
if cellInArea {
|
||||||
|
t.Fatalf("Expected cell %v not to be inside of area %v, but got true\n", cell, area)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package excelize
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestAxisLowerOrEqualThan(t *testing.T) {
|
||||||
|
trueExpectedInputList := [][2]string{
|
||||||
|
[2]string{"A", "B"},
|
||||||
|
[2]string{"A", "AA"},
|
||||||
|
[2]string{"B", "AA"},
|
||||||
|
[2]string{"BC", "ABCD"},
|
||||||
|
[2]string{"1", "2"},
|
||||||
|
[2]string{"2", "11"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, trueExpectedInput := range trueExpectedInputList {
|
||||||
|
isLowerOrEqual := axisLowerOrEqualThan(trueExpectedInput[0], trueExpectedInput[1])
|
||||||
|
if !isLowerOrEqual {
|
||||||
|
t.Fatalf("Expected %v <= %v = true, got false\n", trueExpectedInput[0], trueExpectedInput[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
falseExpectedInputList := [][2]string{
|
||||||
|
[2]string{"B", "A"},
|
||||||
|
[2]string{"AA", "A"},
|
||||||
|
[2]string{"AA", "B"},
|
||||||
|
[2]string{"ABCD", "AB"},
|
||||||
|
[2]string{"2", "1"},
|
||||||
|
[2]string{"11", "2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, falseExpectedInput := range falseExpectedInputList {
|
||||||
|
isLowerOrEqual := axisLowerOrEqualThan(falseExpectedInput[0], falseExpectedInput[1])
|
||||||
|
if isLowerOrEqual {
|
||||||
|
t.Fatalf("Expected %v <= %v = false, got true\n", falseExpectedInput[0], falseExpectedInput[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetCellColRow(t *testing.T) {
|
||||||
|
cellExpectedColRowList := map[string][2]string{
|
||||||
|
"C220": [2]string{"C", "220"},
|
||||||
|
"aaef42": [2]string{"aaef", "42"},
|
||||||
|
"bonjour": [2]string{"bonjour", ""},
|
||||||
|
"59": [2]string{"", "59"},
|
||||||
|
"": [2]string{"", ""},
|
||||||
|
}
|
||||||
|
|
||||||
|
for cell, expectedColRow := range cellExpectedColRowList {
|
||||||
|
col, row := getCellColRow(cell)
|
||||||
|
|
||||||
|
if col != expectedColRow[0] {
|
||||||
|
t.Fatalf("Expected cell %v to return col %v, got col %v\n", cell, expectedColRow[0], col)
|
||||||
|
}
|
||||||
|
|
||||||
|
if row != expectedColRow[1] {
|
||||||
|
t.Fatalf("Expected cell %v to return row %v, got row %v\n", cell, expectedColRow[1], row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue