package bencode
import (
+ "bytes"
+ "fmt"
+ "math/big"
"testing"
"github.com/stretchr/testify/assert"
)
-import "bytes"
-import "fmt"
type random_encode_test struct {
value interface{}
{random_struct{123, "nono", "hello"}, "d3:CDE5:hello3:abci123ee"},
{map[string]string{"a": "b", "c": "d"}, "d1:a1:b1:c1:de"},
{[]byte{1, 2, 3, 4}, "4:\x01\x02\x03\x04"},
- {[4]byte{1, 2, 3, 4}, "li1ei2ei3ei4ee"},
+ {&[4]byte{1, 2, 3, 4}, "4:\x01\x02\x03\x04"},
{nil, ""},
{[]byte{}, "0:"},
+ {[]byte(nil), "0:"},
{"", "0:"},
{[]int{}, "le"},
{map[string]int{}, "de"},
{struct {
A *string `bencode:",omitempty"`
}{new(string)}, "d1:A0:e"},
+ {bigIntFromString("62208002200000000000"), "i62208002200000000000e"},
+ {*bigIntFromString("62208002200000000000"), "i62208002200000000000e"},
+}
+
+func bigIntFromString(s string) *big.Int {
+ bi, ok := new(big.Int).SetString(s, 10)
+ if !ok {
+ panic(s)
+ }
+ return bi
}
func TestRandomEncode(t *testing.T) {