#7 #2 tests added

This commit is contained in:
Andreas Schröpfer
2021-03-01 20:15:25 +01:00
parent 7dde4775dd
commit 7270660f2c
7 changed files with 36 additions and 4 deletions

2
.gitignore vendored
View File

@@ -15,4 +15,4 @@
# Dependency directories (remove the comment below to include it)
# vendor/
test/.~lock*
*.~lock*

1
go.mod
View File

@@ -5,4 +5,5 @@ go 1.16
require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.2
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/matryer/is v1.4.0 // indirect
)

2
go.sum
View File

@@ -3,6 +3,8 @@ github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.2/go.mod h1:xc0ybJZXcn084ZaIvQ
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

View File

@@ -128,7 +128,7 @@
"default": "Please choose"
},
{
"col": "E",
"col": "F",
"field": "Costs",
"type": "string",
"default": "0"

View File

@@ -43,14 +43,20 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
for r := a.StartRow; r <= a.EndRow; r++ {
sf := ecalc.SupplyFraction{}
for _, c := range a.Cols {
axis := fmt.Sprintf("%s%d", c.Col, r)
cellValue, err := xFile.GetCellValue(
xFile.GetSheetName(a.Sheet),
fmt.Sprintf("%s%d", c.Col, r),
axis,
)
if err != nil {
errs = append(errs, err)
}
set.Field(&sf, c.Field, cellValue)
err = set.Field(&sf, c.Field, cellValue)
if err != nil {
errs = append(errs,
fmt.Errorf("XLSXL.SupplyFraction: Sheet %d, Cell %s: %w",
a.Sheet, axis, err))
}
}
eBalance.CompanyFacts.SupplyFractions =
append(

23
pkg/loader/loader_test.go Normal file
View File

@@ -0,0 +1,23 @@
package loader
import (
"bytes"
_ "embed"
"testing"
"github.com/matryer/is"
)
//go:embed test/testfile.xlsx
var tb []byte
func TestXLSX(t *testing.T) {
is := is.New(t)
buf := bytes.NewBuffer(tb)
got, err := XLSX(buf, nil)
is.NoErr(err) // no error for testfile
is.Equal(got.Version, "5.04") // version 5.04
is.Equal(got.CompanyFacts.TotalPurchaseFromSuppliers, 10000)
is.Equal(got.CompanyFacts.SupplyFractions[0].Costs, 500)
is.Equal(got.CompanyFacts.SupplyFractions[0].CountryCode, "ALB")
}

Binary file not shown.