import "testing"
import "bytes"
+import "fmt"
type random_encode_test struct {
value interface{}
CDE string
}
+type dummy struct {
+ a, b, c int
+}
+
+func (d *dummy) MarshalBencode() ([]byte, error) {
+ var b bytes.Buffer
+ _, err := fmt.Fprintf(&b, "i%dei%dei%de", d.a + 1, d.b + 1, d.c + 1)
+ if err != nil {
+ return nil, err
+ }
+ return b.Bytes(), nil
+}
+
var random_encode_tests = []random_encode_test{
{int(10), "i10e"},
{uint(10), "i10e"},
{"", "0:"},
{[]int{}, "le"},
{map[string]int{}, "de"},
+ {&dummy{1, 2, 3}, "i2ei3ei4e"},
}
func TestRandomEncode(t *testing.T) {