]> Sergey Matveev's repositories - btrtrc.git/blob - bencode/decode_test.go
Initial commit.
[btrtrc.git] / bencode / decode_test.go
1 package bencode
2
3 import "testing"
4 import "reflect"
5
6 type random_decode_test struct {
7         data     string
8         expected interface{}
9 }
10
11 var random_decode_tests = []random_decode_test{
12         {"i57e", int64(57)},
13         {"i-9223372036854775808e", int64(-9223372036854775808)},
14         {"5:hello", "hello"},
15         {"29:unicode test проверка", "unicode test проверка"},
16         {"d1:ai5e1:b5:helloe", map[string]interface{}{"a": int64(5), "b": "hello"}},
17         {"li5ei10ei15ei20e7:bencodee",
18                 []interface{}{int64(5), int64(10), int64(15), int64(20), "bencode"}},
19 }
20
21 func TestRandomDecode(t *testing.T) {
22         for _, test := range random_decode_tests {
23                 var value interface{}
24                 err := Unmarshal([]byte(test.data), &value)
25                 if err != nil {
26                         t.Error(err)
27                         continue
28                 }
29                 if !reflect.DeepEqual(test.expected, value) {
30                         t.Errorf("got: %v (%T), expected: %v (%T)\n",
31                                 value, value, test.expected, test.expected)
32                 }
33         }
34 }