aboutsummaryrefslogtreecommitdiff
path: root/bencode/bencode_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'bencode/bencode_test.go')
-rw-r--r--bencode/bencode_test.go34
1 files changed, 29 insertions, 5 deletions
diff --git a/bencode/bencode_test.go b/bencode/bencode_test.go
index a194fb6..2120654 100644
--- a/bencode/bencode_test.go
+++ b/bencode/bencode_test.go
@@ -32,7 +32,7 @@ func TestParseString(t *testing.T) {
in := "4:testZZZ"
s, l := parseString([]byte(in))
if s != "test" || l != 6 {
- t.Error("expected test, got", s)
+ t.Error("want test, got", s)
}
}
@@ -40,7 +40,7 @@ func TestParseInt(t *testing.T) {
in := "i12345e999"
i, l := parseInt([]byte(in))
if i != 12345 || l != 7 {
- t.Error("expected 12345, got", i)
+ t.Error("want 12345, got", i)
}
}
@@ -77,7 +77,7 @@ func TestUnmarshal(t *testing.T) {
}
h := hex.EncodeToString(tor.InfoHash)
if h != tc.InfoHash {
- t.Error("got", h, "expected", tc.InfoHash)
+ t.Error("got", h, "want", tc.InfoHash)
}
}
}
@@ -109,7 +109,7 @@ func TestUnmarshalBool(t *testing.T) {
t.Error(err)
}
if b.A != true {
- t.Error("expected true, got", b.A)
+ t.Error("want true, got", b.A)
}
}
@@ -121,6 +121,30 @@ func TestUnmarshalInt64(t *testing.T) {
t.Error(err)
}
if b.A != 42 {
- t.Error("expected true, got", b.A)
+ 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[:]))
}
}