From cf9e66821412aaf7461410928659c1b0296bc5c2 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 12 Jun 2016 05:36:39 +0200 Subject: Unmarshal --- bencode/bencode_test.go | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'bencode/bencode_test.go') diff --git a/bencode/bencode_test.go b/bencode/bencode_test.go index a7c534c..9ee40d7 100644 --- a/bencode/bencode_test.go +++ b/bencode/bencode_test.go @@ -1,6 +1,7 @@ package bencode import ( + "io/ioutil" "testing" "time" @@ -27,18 +28,38 @@ func TestMarshal(t *testing.T) { t.Logf("%q\n", string(out)) } -func TestUnmarshalString(t *testing.T) { +func TestParseString(t *testing.T) { in := "4:testZZZ" - s := unmarshalString([]byte(in)) - if s != "test" { + s, l := parseString([]byte(in)) + if s != "test" || l != 6 { t.Error("expected test, got", s) } } -func TestUnmarshalInt(t *testing.T) { +func TestParseInt(t *testing.T) { in := "i12345e999" - i := unmarshalInt([]byte(in)) - if i != 12345 { + i, l := parseInt([]byte(in)) + if i != 12345 || l != 7 { t.Error("expected 12345, got", i) } } + +func TestUnmarshal(t *testing.T) { + files := []string{ + "../examples/OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent", + "../examples/OpenBSD_songs_ogg-2016-03-25-0127.torrent", + "../examples/debian-8.5.0-amd64-netinst.iso.torrent", + } + for _, file := range files { + var tor torrent.Torrent + body, err := ioutil.ReadFile(file) + if err != nil { + t.Error(err) + } + err = Unmarshal(body, &tor) + if err != nil { + t.Error(err) + } + t.Logf("%+v\n", tor) + } +} -- cgit v1.2.3