6 type random_encode_test struct {
11 type random_struct struct {
12 ABC int `bencode:"abc"`
13 SkipThisOne string `bencode:"-"`
17 var random_encode_tests = []random_encode_test{
20 {"hello, world", "12:hello, world"},
24 {int16(-16), "i-16e"},
26 {int64(-64), "i-64e"},
31 {random_struct{123, "nono", "hello"}, "d3:CDE5:hello3:abci123ee"},
32 {map[string]string{"a": "b", "c": "d"}, "d1:a1:b1:c1:de"},
33 {[]byte{1, 2, 3, 4}, "4:\x01\x02\x03\x04"},
34 {[4]byte{1, 2, 3, 4}, "li1ei2ei3ei4ee"},
39 {map[string]int{}, "de"},
42 func TestRandomEncode(t *testing.T) {
43 for _, test := range random_encode_tests {
44 data, err := Marshal(test.value)
48 if !bytes.Equal(data, []byte(test.expected)) {
49 t.Errorf("got: %s, expected: %s\n",
50 string(data), string(test.expected))