]> Sergey Matveev's repositories - btrtrc.git/blob - bencode/bytes_test.go
Fix test failure using missinggo filecache on Windows
[btrtrc.git] / bencode / bytes_test.go
1 package bencode
2
3 import (
4         "testing"
5
6         qt "github.com/frankban/quicktest"
7 )
8
9 func TestBytesMarshalNil(t *testing.T) {
10         var b Bytes
11         Marshal(b)
12 }
13
14 type structWithBytes struct {
15         A Bytes
16         B Bytes
17 }
18
19 func TestMarshalNilStructBytes(t *testing.T) {
20         _, err := Marshal(structWithBytes{B: Bytes("i42e")})
21         c := qt.New(t)
22         c.Assert(err, qt.IsNotNil)
23 }
24
25 type structWithOmitEmptyBytes struct {
26         A Bytes `bencode:",omitempty"`
27         B Bytes `bencode:",omitempty"`
28 }
29
30 func TestMarshalNilStructBytesOmitEmpty(t *testing.T) {
31         c := qt.New(t)
32         b, err := Marshal(structWithOmitEmptyBytes{B: Bytes("i42e")})
33         c.Assert(err, qt.IsNil)
34         t.Logf("%q", b)
35         var s structWithBytes
36         err = Unmarshal(b, &s)
37         c.Assert(err, qt.IsNil)
38         c.Check(s.B, qt.DeepEquals, Bytes("i42e"))
39 }