Skip to content

Commit

Permalink
fix: reset state before scanning (#189)
Browse files Browse the repository at this point in the history
Fixes #185
Fixes #188
  • Loading branch information
ab0455a08d03 authored Mar 5, 2024
1 parent 495c538 commit 93d5865
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func (z *Big) scan(r io.ByteScanner) error {
// We deviate a little by being a tad bit more forgiving. For instance,
// we allow case-insensitive nan and infinity values.

// Before scanning, reset it to zero
z.SetUint64(0)

// Sign
neg, err := scanSign(r)
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,26 @@ func BenchmarkBig_SetString(b *testing.B) {
}
globOk = ok
}



func TestUnmarshalTextTwice(t *testing.T) {
x := &Big{}

x.UnmarshalText([]byte(`1`))
x.UnmarshalText([]byte(`2`))
if x.String() != "2" {
t.Errorf("wanted: %q, got %q", "2", x.String())
}
}


func TestSetStringTwice(t *testing.T) {
x := &Big{}

x.SetString("1")
x.SetString("2")
if x.String() != "2" {
t.Errorf("wanted: %q, got %q", "2", x.String())
}
}

0 comments on commit 93d5865

Please sign in to comment.