Implement linter fixes
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Jan Bader 2022-02-23 22:08:47 +00:00
parent 253ecd1720
commit 24e5b18ded
3 changed files with 12 additions and 11 deletions

View File

@ -18,16 +18,11 @@ func Zero() Numeric {
} }
func FromInt64(value int64) Numeric { func FromInt64(value int64) Numeric {
num := Numeric{} return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Status: pgtype.Present}}
num.Set(value)
return num
} }
func FromInt64WithExp(value int64, exp int32) Numeric { func FromInt64WithExp(value int64, exp int32) Numeric {
num := Numeric{} return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Exp: exp, Status: pgtype.Present}}
num.Set(value)
num.Exp = exp
return num
} }
func (n Numeric) GetFloat64() float64 { func (n Numeric) GetFloat64() float64 {

View File

@ -12,6 +12,7 @@ type TestCaseMarshalJSON struct {
} }
func TestMarshalJSON(t *testing.T) { func TestMarshalJSON(t *testing.T) {
t.Parallel()
tests := []TestCaseMarshalJSON{ tests := []TestCaseMarshalJSON{
{numeric.Zero(), `0`}, {numeric.Zero(), `0`},
{numeric.MustParse("1.23"), "1.23"}, {numeric.MustParse("1.23"), "1.23"},
@ -21,8 +22,10 @@ func TestMarshalJSON(t *testing.T) {
{numeric.MustParse("-1,24"), "-1.24"}, {numeric.MustParse("-1,24"), "-1.24"},
{numeric.MustParse("-123456789.12345"), "-123456789.12345"}, {numeric.MustParse("-123456789.12345"), "-123456789.12345"},
} }
for _, test := range tests { for i := range tests {
test := tests[i]
t.Run(test.Result, func(t *testing.T) { t.Run(test.Result, func(t *testing.T) {
t.Parallel()
z := test.Value z := test.Value
result, err := z.MarshalJSON() result, err := z.MarshalJSON()
if err != nil { if err != nil {
@ -44,6 +47,7 @@ type TestCaseParse struct {
} }
func TestParse(t *testing.T) { func TestParse(t *testing.T) {
t.Parallel()
tests := []TestCaseParse{ tests := []TestCaseParse{
{numeric.FromInt64WithExp(0, 0), `0`}, {numeric.FromInt64WithExp(0, 0), `0`},
{numeric.FromInt64WithExp(1, 0), `1`}, {numeric.FromInt64WithExp(1, 0), `1`},
@ -60,8 +64,10 @@ func TestParse(t *testing.T) {
{numeric.FromInt64WithExp(-124, -2), "-1,24"}, {numeric.FromInt64WithExp(-124, -2), "-1,24"},
{numeric.FromInt64WithExp(-12345678912345, -5), "-123456789.12345"}, {numeric.FromInt64WithExp(-12345678912345, -5), "-123456789.12345"},
} }
for _, test := range tests { for i := range tests {
test := tests[i]
t.Run(test.Value, func(t *testing.T) { t.Run(test.Value, func(t *testing.T) {
t.Parallel()
result, err := numeric.Parse(test.Value) result, err := numeric.Parse(test.Value)
if err != nil { if err != nil {
t.Error(err) t.Error(err)

View File

@ -296,7 +296,7 @@ func (ynab *YNABImport) ImportTransferTransaction(context context.Context, payee
} }
func GetAmount(inflow string, outflow string) (numeric.Numeric, error) { func GetAmount(inflow string, outflow string) (numeric.Numeric, error) {
in, err := numeric.Parse(inflow) in, err := numeric.ParseCurrency(inflow)
if err != nil { if err != nil {
return in, fmt.Errorf("parse inflow: %w", err) return in, fmt.Errorf("parse inflow: %w", err)
} }
@ -306,7 +306,7 @@ func GetAmount(inflow string, outflow string) (numeric.Numeric, error) {
} }
// if inflow is zero, use outflow // if inflow is zero, use outflow
out, err := numeric.Parse("-" + outflow) out, err := numeric.ParseCurrency("-" + outflow)
if err != nil { if err != nil {
return out, fmt.Errorf("parse outflow: %w", err) return out, fmt.Errorf("parse outflow: %w", err)
} }