aboutsummaryrefslogtreecommitdiff
path: root/bencode/bencode_test.go
blob: a7c534cf7ca69f158b6876ba8e26063f7c712c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package bencode

import (
	"testing"
	"time"

	"dim13.org/btr/torrent"
)

func TestMarshal(t *testing.T) {
	v := torrent.Torrent{
		Announce:     "test",
		AnnounceList: []string{"test1", "test2", "test3"},
		CreationDate: time.Now(),
		Info: torrent.Info{
			Length: 1000,
			Files: []torrent.File{
				{Path: []string{"A"}},
				{Path: []string{"B"}},
			},
		},
	}
	out, err := Marshal(v)
	if err != nil {
		t.Error(err)
	}
	t.Logf("%q\n", string(out))
}

func TestUnmarshalString(t *testing.T) {
	in := "4:testZZZ"
	s := unmarshalString([]byte(in))
	if s != "test" {
		t.Error("expected test, got", s)
	}
}

func TestUnmarshalInt(t *testing.T) {
	in := "i12345e999"
	i := unmarshalInt([]byte(in))
	if i != 12345 {
		t.Error("expected 12345, got", i)
	}
}