2021-09-29 00:13:32 +00:00
|
|
|
//go:build go1.18
|
|
|
|
|
|
|
|
package bencode
|
|
|
|
|
|
|
|
import (
|
2021-09-29 02:11:17 +00:00
|
|
|
"math/big"
|
2021-09-29 00:13:32 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
qt "github.com/frankban/quicktest"
|
2021-09-29 02:11:17 +00:00
|
|
|
"github.com/google/go-cmp/cmp"
|
2021-09-29 00:13:32 +00:00
|
|
|
)
|
|
|
|
|
2021-09-29 02:11:17 +00:00
|
|
|
var bencodeInterfaceChecker = qt.CmpEquals(cmp.Comparer(func(a, b *big.Int) bool {
|
|
|
|
return a.Cmp(b) == 0
|
|
|
|
}))
|
|
|
|
|
2021-09-29 00:13:32 +00:00
|
|
|
func Fuzz(f *testing.F) {
|
2021-09-29 02:12:16 +00:00
|
|
|
for _, ret := range random_encode_tests {
|
|
|
|
f.Add([]byte(ret.expected))
|
|
|
|
}
|
2021-09-29 00:13:32 +00:00
|
|
|
f.Fuzz(func(t *testing.T, b []byte) {
|
|
|
|
c := qt.New(t)
|
|
|
|
var d interface{}
|
|
|
|
err := Unmarshal(b, &d)
|
|
|
|
if err != nil {
|
|
|
|
t.Skip()
|
|
|
|
}
|
|
|
|
b0, err := Marshal(d)
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
var d0 interface{}
|
|
|
|
err = Unmarshal(b0, &d0)
|
|
|
|
c.Assert(err, qt.IsNil)
|
2021-09-29 02:11:17 +00:00
|
|
|
c.Assert(d0, bencodeInterfaceChecker, d)
|
2021-09-29 00:13:32 +00:00
|
|
|
})
|
|
|
|
}
|