aboutsummaryrefslogtreecommitdiff
path: root/bencode/bencode_test.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-06-12 05:36:39 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-06-12 05:36:39 +0200
commitcf9e66821412aaf7461410928659c1b0296bc5c2 (patch)
tree15ed393753907b9821bae6271b06fdfb41009983 /bencode/bencode_test.go
parent695ac4be1f813f3605ed4f15444670dbd1689288 (diff)
Unmarshal
Diffstat (limited to 'bencode/bencode_test.go')
-rw-r--r--bencode/bencode_test.go33
1 files changed, 27 insertions, 6 deletions
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)
+ }
+}