2
0
mirror of synced 2025-02-24 06:38:14 +00:00
torrent/bencode/decode_test.go

37 lines
997 B
Go

package bencode
import "testing"
import "reflect"
type random_decode_test struct {
data string
expected interface{}
}
var random_decode_tests = []random_decode_test{
{"i57e", int64(57)},
{"i-9223372036854775808e", int64(-9223372036854775808)},
{"5:hello", "hello"},
{"29:unicode test проверка", "unicode test проверка"},
{"d1:ai5e1:b5:helloe", map[string]interface{}{"a": int64(5), "b": "hello"}},
{"li5ei10ei15ei20e7:bencodee",
[]interface{}{int64(5), int64(10), int64(15), int64(20), "bencode"}},
{"ldedee", []interface{}{map[string]interface{}{}, map[string]interface{}{}}},
{"le", []interface{}{}},
}
func TestRandomDecode(t *testing.T) {
for _, test := range random_decode_tests {
var value interface{}
err := Unmarshal([]byte(test.data), &value)
if err != nil {
t.Error(err)
continue
}
if !reflect.DeepEqual(test.expected, value) {
t.Errorf("got: %v (%T), expected: %v (%T)\n",
value, value, test.expected, test.expected)
}
}
}