aboutsummaryrefslogtreecommitdiff
path: root/bencode
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-07-09 15:17:37 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-07-09 15:17:37 +0200
commit13b1d4b9a06147cfd1140d42dc6b9ed2ba7a8a90 (patch)
treecf134c619fe839764563717d3910be6cdb06c602 /bencode
parentdff1ff318d9ccb7e1c7aac6f9f3f86b139f86b49 (diff)
int64
Diffstat (limited to 'bencode')
-rw-r--r--bencode/bencode.go4
-rw-r--r--bencode/bencode_test.go14
2 files changed, 15 insertions, 3 deletions
diff --git a/bencode/bencode.go b/bencode/bencode.go
index 14d8953..934e1b9 100644
--- a/bencode/bencode.go
+++ b/bencode/bencode.go
@@ -33,7 +33,7 @@ func marshalField(out io.Writer, v reflect.Value) error {
switch v.Kind() {
case reflect.String:
marshalString(out, v.String())
- case reflect.Int:
+ case reflect.Int, reflect.Int64:
marshalInt(out, v.Int())
case reflect.Slice:
marshalList(out, v)
@@ -51,7 +51,7 @@ func marshalField(out io.Writer, v reflect.Value) error {
func isZero(v reflect.Value) bool {
switch v.Kind() {
- case reflect.Int:
+ case reflect.Int, reflect.Int64:
return v.Int() == 0
case reflect.String, reflect.Slice:
return v.Len() == 0
diff --git a/bencode/bencode_test.go b/bencode/bencode_test.go
index 5965afa..329baad 100644
--- a/bencode/bencode_test.go
+++ b/bencode/bencode_test.go
@@ -101,7 +101,7 @@ func TestUnmarshalPartial(t *testing.T) {
}
*/
-func TestBoolUnmarshal(t *testing.T) {
+func TestUnmarshalBool(t *testing.T) {
var b struct{ A bool }
in := `d1:Ai1ee`
err := Unmarshal([]byte(in), &b)
@@ -112,3 +112,15 @@ func TestBoolUnmarshal(t *testing.T) {
t.Error("expected 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("expected true, got", b.A)
+ }
+}