decimal
decimal copied to clipboard
UnmarshalText doesn't reset the number before parsing
If UnmarshalText is called multiple times for the same decimal.Big instance, the input is appended to the internal state instead of overriding previous input.
package decimal_test
import (
"testing"
"github.com/ericlagergren/decimal"
)
func TestUnmarshalTest(t *testing.T) {
x := &decimal.Big{}
x.UnmarshalText([]byte(`1`))
x.UnmarshalText([]byte(`2`))
if x.String() != "2" {
t.Errorf("expect 1 got %s", x.String())
}
}
Test run:
--- FAIL: TestUnmarshalTest (0.00s)
decimal_test.go:19: expect 1 got 12
FAIL
FAIL decimals 0.001s
**FAIL**
Could be related to #185 - something's wrong with reusing decimal.Big from strings.