github.com/batchcorp/thrift-iterator@v0.0.0-20220918180557-4c4a158fc6e9/test/level_1/binary_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 "github.com/stretchr/testify/require" 6 "github.com/batchcorp/thrift-iterator/test" 7 ) 8 9 func Test_decode_binary(t *testing.T) { 10 should := require.New(t) 11 for _, c := range test.Combinations { 12 buf, proto := c.CreateProtocol() 13 proto.WriteBinary([]byte("hello")) 14 iter := c.CreateIterator(buf.Bytes()) 15 should.Equal("hello", string(iter.ReadBinary())) 16 } 17 } 18 19 func Test_unmarshal_binary(t *testing.T) { 20 should := require.New(t) 21 for _, c := range test.UnmarshalCombinations { 22 buf, proto := c.CreateProtocol() 23 proto.WriteBinary([]byte("hello")) 24 var val []byte 25 should.NoError(c.Unmarshal(buf.Bytes(), &val)) 26 should.Equal("hello", string(val)) 27 } 28 } 29 30 func Test_encode_binary(t *testing.T) { 31 should := require.New(t) 32 for _, c := range test.Combinations { 33 stream := c.CreateStream() 34 stream.WriteBinary([]byte(`hello world!`)) 35 iter := c.CreateIterator(stream.Buffer()) 36 should.Equal([]byte(`hello world!`), iter.ReadBinary()) 37 } 38 } 39 40 func Test_marshal_binary(t *testing.T) { 41 should := require.New(t) 42 for _, c := range test.MarshalCombinations { 43 val := []byte("hello") 44 output, err := c.Marshal(val) 45 should.NoError(err) 46 iter := c.CreateIterator(output) 47 should.Equal("hello", string(iter.ReadBinary())) 48 } 49 }