github.com/batchcorp/thrift-iterator@v0.0.0-20220918180557-4c4a158fc6e9/test/level_0/bool_test.go (about)

     1  package test
     2  
     3  import (
     4  	"github.com/stretchr/testify/require"
     5  	"github.com/batchcorp/thrift-iterator/test"
     6  	"testing"
     7  )
     8  
     9  func Test_decode_bool(t *testing.T) {
    10  	should := require.New(t)
    11  	for _, c := range test.Combinations {
    12  		buf, proto := c.CreateProtocol()
    13  		proto.WriteBool(true)
    14  		iter := c.CreateIterator(buf.Bytes())
    15  		should.Equal(true, iter.ReadBool())
    16  
    17  		buf, proto = c.CreateProtocol()
    18  		proto.WriteBool(false)
    19  		iter = c.CreateIterator(buf.Bytes())
    20  		should.Equal(false, iter.ReadBool())
    21  	}
    22  }
    23  
    24  func Test_unmarshal_bool(t *testing.T) {
    25  	should := require.New(t)
    26  	for _, c := range test.UnmarshalCombinations {
    27  		buf, proto := c.CreateProtocol()
    28  		var val1 bool
    29  		proto.WriteBool(true)
    30  		should.NoError(c.Unmarshal(buf.Bytes(), &val1))
    31  		should.Equal(true, val1)
    32  
    33  		buf, proto = c.CreateProtocol()
    34  		var val2 bool = true
    35  		proto.WriteBool(false)
    36  		should.NoError(c.Unmarshal(buf.Bytes(), &val2))
    37  		should.Equal(false, val2)
    38  	}
    39  }
    40  
    41  func Test_encode_bool(t *testing.T) {
    42  	should := require.New(t)
    43  	for _, c := range test.Combinations {
    44  		stream := c.CreateStream()
    45  		stream.WriteBool(true)
    46  		iter := c.CreateIterator(stream.Buffer())
    47  		should.Equal(true, iter.ReadBool())
    48  
    49  		stream = c.CreateStream()
    50  		stream.WriteBool(false)
    51  		iter = c.CreateIterator(stream.Buffer())
    52  		should.Equal(false, iter.ReadBool())
    53  	}
    54  }
    55  
    56  func Test_marshal_bool(t *testing.T) {
    57  	should := require.New(t)
    58  	for _, c := range test.MarshalCombinations {
    59  		output, err := c.Marshal(true)
    60  		should.NoError(err)
    61  		iter := c.CreateIterator(output)
    62  		should.Equal(true, iter.ReadBool())
    63  
    64  		output, err = c.Marshal(false)
    65  		should.NoError(err)
    66  		iter = c.CreateIterator(output)
    67  		should.Equal(false, iter.ReadBool())
    68  	}
    69  }