Add MarshalBencode test.

This commit is contained in:
nsf 2012-06-24 17:10:27 +06:00
parent 8db0c29da9
commit 69d1e17b80
1 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package bencode
import "testing"
import "bytes"
import "fmt"
type random_encode_test struct {
value interface{}
@ -14,6 +15,19 @@ type random_struct struct {
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"},
@ -37,6 +51,7 @@ var random_encode_tests = []random_encode_test{
{"", "0:"},
{[]int{}, "le"},
{map[string]int{}, "de"},
{&dummy{1, 2, 3}, "i2ei3ei4e"},
}
func TestRandomEncode(t *testing.T) {