|
|
|
@ -5888,3 +5888,50 @@ func TestCalcCellResolver(t *testing.T) {
|
|
|
|
|
assert.Equal(t, expected, result, formula)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFile_CalcFormulaValue(t *testing.T) {
|
|
|
|
|
cellData := [][]interface{}{
|
|
|
|
|
{1, 4, nil, "Month", "Team", "Sales"},
|
|
|
|
|
{2, 5, nil, "Jan", "North 1", 36693},
|
|
|
|
|
{3, nil, nil, "Jan", "North 2", 22100},
|
|
|
|
|
{0, nil, nil, "Jan", "South 1", 53321},
|
|
|
|
|
{nil, nil, nil, "Jan", "South 2", 34440},
|
|
|
|
|
{nil, nil, nil, "Feb", "North 1", 29889},
|
|
|
|
|
{nil, nil, nil, "Feb", "North 2", 50090},
|
|
|
|
|
{nil, nil, nil, "Feb", "South 1", 32080},
|
|
|
|
|
{nil, nil, nil, "Feb", "South 2", 45500},
|
|
|
|
|
}
|
|
|
|
|
type args struct {
|
|
|
|
|
sheet string
|
|
|
|
|
formula string
|
|
|
|
|
}
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
f *File
|
|
|
|
|
args args
|
|
|
|
|
wantResult string
|
|
|
|
|
wantErr bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "test CalcFormulaValue",
|
|
|
|
|
f: prepareCalcData(cellData),
|
|
|
|
|
args: args{
|
|
|
|
|
sheet: "Sheet1",
|
|
|
|
|
formula: "A1+B1",
|
|
|
|
|
},
|
|
|
|
|
wantResult: "5",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
gotResult, err := tt.f.CalcFormulaValue(tt.args.sheet, tt.args.formula)
|
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
|
t.Errorf("File.CalcFormulaValue() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if gotResult != tt.wantResult {
|
|
|
|
|
t.Errorf("File.CalcFormulaValue() = %v, want %v", gotResult, tt.wantResult)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|