Implement linter fixes
This commit is contained in:
parent
253ecd1720
commit
24e5b18ded
@ -18,16 +18,11 @@ func Zero() Numeric {
|
||||
}
|
||||
|
||||
func FromInt64(value int64) Numeric {
|
||||
num := Numeric{}
|
||||
num.Set(value)
|
||||
return num
|
||||
return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Status: pgtype.Present}}
|
||||
}
|
||||
|
||||
func FromInt64WithExp(value int64, exp int32) Numeric {
|
||||
num := Numeric{}
|
||||
num.Set(value)
|
||||
num.Exp = exp
|
||||
return num
|
||||
return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Exp: exp, Status: pgtype.Present}}
|
||||
}
|
||||
|
||||
func (n Numeric) GetFloat64() float64 {
|
||||
|
@ -12,6 +12,7 @@ type TestCaseMarshalJSON struct {
|
||||
}
|
||||
|
||||
func TestMarshalJSON(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := []TestCaseMarshalJSON{
|
||||
{numeric.Zero(), `0`},
|
||||
{numeric.MustParse("1.23"), "1.23"},
|
||||
@ -21,8 +22,10 @@ func TestMarshalJSON(t *testing.T) {
|
||||
{numeric.MustParse("-1,24"), "-1.24"},
|
||||
{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.Parallel()
|
||||
z := test.Value
|
||||
result, err := z.MarshalJSON()
|
||||
if err != nil {
|
||||
@ -44,6 +47,7 @@ type TestCaseParse struct {
|
||||
}
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := []TestCaseParse{
|
||||
{numeric.FromInt64WithExp(0, 0), `0`},
|
||||
{numeric.FromInt64WithExp(1, 0), `1`},
|
||||
@ -60,8 +64,10 @@ func TestParse(t *testing.T) {
|
||||
{numeric.FromInt64WithExp(-124, -2), "-1,24"},
|
||||
{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.Parallel()
|
||||
result, err := numeric.Parse(test.Value)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
@ -296,7 +296,7 @@ func (ynab *YNABImport) ImportTransferTransaction(context context.Context, payee
|
||||
}
|
||||
|
||||
func GetAmount(inflow string, outflow string) (numeric.Numeric, error) {
|
||||
in, err := numeric.Parse(inflow)
|
||||
in, err := numeric.ParseCurrency(inflow)
|
||||
if err != nil {
|
||||
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
|
||||
out, err := numeric.Parse("-" + outflow)
|
||||
out, err := numeric.ParseCurrency("-" + outflow)
|
||||
if err != nil {
|
||||
return out, fmt.Errorf("parse outflow: %w", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user