aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-12-15 15:31:59 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-12-15 15:31:59 +0100
commit158867b07fdd9b6229ba6fdea5e1fab7670b2ca0 (patch)
treeecc474ee6b08cdd9d4fc0891b58884a0a7e95d05
parent38481fb37982cf7cacf11ce020a7196d43e72b53 (diff)
split files
-rw-r--r--bencode/bdecode_test.go124
-rw-r--r--bencode/bencode_test.go123
2 files changed, 124 insertions, 123 deletions
diff --git a/bencode/bdecode_test.go b/bencode/bdecode_test.go
new file mode 100644
index 0000000..8967d78
--- /dev/null
+++ b/bencode/bdecode_test.go
@@ -0,0 +1,124 @@
+package bencode
+
+import "testing"
+
+func TestParseString(t *testing.T) {
+ in := "4:testZZZ"
+ s, l := parseString([]byte(in))
+ if s != "test" || l != 6 {
+ t.Error("want test, got", s)
+ }
+}
+
+func TestParseInt(t *testing.T) {
+ in := "i12345e999"
+ i, l := parseInt([]byte(in))
+ if i != 12345 || l != 7 {
+ t.Error("want 12345, got", i)
+ }
+}
+
+func TestUnmarshalBool(t *testing.T) {
+ var b struct{ A bool }
+ in := `d1:Ai1ee`
+ _, err := Unmarshal([]byte(in), &b)
+ if err != nil {
+ t.Error(err)
+ }
+ if b.A != true {
+ t.Error("want true, got", b.A)
+ }
+}
+
+func TestUnmarshalInt64(t *testing.T) {
+ var b struct{ A int64 }
+ in := `d1:Ai42ee`
+ _, err := Unmarshal([]byte(in), &b)
+ if err != nil {
+ t.Error(err)
+ }
+ if b.A != 42 {
+ t.Error("want true, got", b.A)
+ }
+}
+
+func TestUnmarshalSlice(t *testing.T) {
+ var b []byte
+ in := `4:test`
+ _, err := Unmarshal([]byte(in), &b)
+ if err != nil {
+ t.Error(err)
+ }
+ if string(b) != "test" {
+ t.Error("want test, got", string(b))
+ }
+}
+
+func TestUnmarshalArray(t *testing.T) {
+ var b [4]byte
+ in := `4:test`
+ _, err := Unmarshal([]byte(in), &b)
+ if err != nil {
+ t.Error(err)
+ }
+ if string(b[:]) != "test" {
+ t.Error("want test, got", string(b[:]))
+ }
+}
+
+/*
+var testCase = []struct {
+ Torrent string
+ InfoHash string
+}{
+ {
+ Torrent: "../testdata/OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent",
+ InfoHash: "e840038dea1998c39614dcd28594501df02bd32d",
+ },
+ {
+ Torrent: "../testdata/OpenBSD_songs_ogg-2016-03-25-0127.torrent",
+ InfoHash: "1aa5af9f6f533961a65169bdeeb801e611724d32",
+ },
+ {
+ Torrent: "../testdata/debian-8.5.0-amd64-netinst.iso.torrent",
+ InfoHash: "47b9ad52c009f3bd562ffc6da40e5c55d3fb47f3",
+ },
+}
+
+func TestUnmarshal(t *testing.T) {
+ for _, tc := range testCase {
+ t.Log("Testing", tc.Torrent)
+ var tor meta.Torrent
+ body, err := ioutil.ReadFile(tc.Torrent)
+ if err != nil {
+ t.Error(err)
+ }
+ err = Unmarshal(body, &tor)
+ if err != nil {
+ t.Error(err)
+ }
+ h := hex.EncodeToString(tor.InfoHash)
+ if h != tc.InfoHash {
+ t.Error("got", h, "want", tc.InfoHash)
+ }
+ }
+}
+
+func TestUnmarshalPartial(t *testing.T) {
+ for _, tc := range testCase {
+ t.Log("Testing", tc.Torrent)
+ var tor = struct {
+ Announce string // `bencode:"announce"`
+ }{}
+ body, err := ioutil.ReadFile(tc.Torrent)
+ if err != nil {
+ t.Error(err)
+ }
+ err = Unmarshal(body, &tor)
+ if err != nil {
+ t.Error(err)
+ }
+ t.Log(tor.Announce)
+ }
+}
+*/
diff --git a/bencode/bencode_test.go b/bencode/bencode_test.go
index 2120654..c994cc2 100644
--- a/bencode/bencode_test.go
+++ b/bencode/bencode_test.go
@@ -1,7 +1,5 @@
package bencode
-import "testing"
-
/*
func TestMarshal(t *testing.T) {
v := meta.Torrent{
@@ -27,124 +25,3 @@ func TestMarshal(t *testing.T) {
t.Logf("%q\n", string(out))
}
*/
-
-func TestParseString(t *testing.T) {
- in := "4:testZZZ"
- s, l := parseString([]byte(in))
- if s != "test" || l != 6 {
- t.Error("want test, got", s)
- }
-}
-
-func TestParseInt(t *testing.T) {
- in := "i12345e999"
- i, l := parseInt([]byte(in))
- if i != 12345 || l != 7 {
- t.Error("want 12345, got", i)
- }
-}
-
-/*
-var testCase = []struct {
- Torrent string
- InfoHash string
-}{
- {
- Torrent: "../testdata/OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent",
- InfoHash: "e840038dea1998c39614dcd28594501df02bd32d",
- },
- {
- Torrent: "../testdata/OpenBSD_songs_ogg-2016-03-25-0127.torrent",
- InfoHash: "1aa5af9f6f533961a65169bdeeb801e611724d32",
- },
- {
- Torrent: "../testdata/debian-8.5.0-amd64-netinst.iso.torrent",
- InfoHash: "47b9ad52c009f3bd562ffc6da40e5c55d3fb47f3",
- },
-}
-
-func TestUnmarshal(t *testing.T) {
- for _, tc := range testCase {
- t.Log("Testing", tc.Torrent)
- var tor meta.Torrent
- body, err := ioutil.ReadFile(tc.Torrent)
- if err != nil {
- t.Error(err)
- }
- err = Unmarshal(body, &tor)
- if err != nil {
- t.Error(err)
- }
- h := hex.EncodeToString(tor.InfoHash)
- if h != tc.InfoHash {
- t.Error("got", h, "want", tc.InfoHash)
- }
- }
-}
-
-func TestUnmarshalPartial(t *testing.T) {
- for _, tc := range testCase {
- t.Log("Testing", tc.Torrent)
- var tor = struct {
- Announce string // `bencode:"announce"`
- }{}
- body, err := ioutil.ReadFile(tc.Torrent)
- if err != nil {
- t.Error(err)
- }
- err = Unmarshal(body, &tor)
- if err != nil {
- t.Error(err)
- }
- t.Log(tor.Announce)
- }
-}
-*/
-
-func TestUnmarshalBool(t *testing.T) {
- var b struct{ A bool }
- in := `d1:Ai1ee`
- _, err := Unmarshal([]byte(in), &b)
- if err != nil {
- t.Error(err)
- }
- if b.A != true {
- t.Error("want true, got", b.A)
- }
-}
-
-func TestUnmarshalInt64(t *testing.T) {
- var b struct{ A int64 }
- in := `d1:Ai42ee`
- _, err := Unmarshal([]byte(in), &b)
- if err != nil {
- t.Error(err)
- }
- if b.A != 42 {
- t.Error("want true, got", b.A)
- }
-}
-
-func TestUnmarshalSlice(t *testing.T) {
- var b []byte
- in := `4:test`
- _, err := Unmarshal([]byte(in), &b)
- if err != nil {
- t.Error(err)
- }
- if string(b) != "test" {
- t.Error("want test, got", string(b))
- }
-}
-
-func TestUnmarshalArray(t *testing.T) {
- var b [4]byte
- in := `4:test`
- _, err := Unmarshal([]byte(in), &b)
- if err != nil {
- t.Error(err)
- }
- if string(b[:]) != "test" {
- t.Error("want test, got", string(b[:]))
- }
-}