github.com/batchcorp/thrift-iterator@v0.0.0-20220918180557-4c4a158fc6e9/test/level_0/enum_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  	"github.com/batchcorp/thrift-iterator/test/level_0/enum_test"
     8  )
     9  
    10  func Test_unmarshal_enum(t *testing.T) {
    11  	should := require.New(t)
    12  	for _, c := range test.UnmarshalCombinations {
    13  		buf, proto := c.CreateProtocol()
    14  		proto.WriteI32(1)
    15  		var val enum_test.Player
    16  		should.NoError(c.Unmarshal(buf.Bytes(), &val))
    17  		should.Equal(enum_test.Player_FLASH, val)
    18  	}
    19  }
    20  
    21  func Test_marshal_enum(t *testing.T) {
    22  	should := require.New(t)
    23  	for _, c := range test.MarshalCombinations {
    24  		output, err := c.Marshal(enum_test.Player_FLASH)
    25  		should.NoError(err)
    26  		iter := c.CreateIterator(output)
    27  		should.Equal(int32(1), iter.ReadInt32())
    28  	}
    29  }