github.com/batchcorp/thrift-iterator@v0.0.0-20220918180557-4c4a158fc6e9/test/level_2/map_of_map_test.go (about) 1 package test 2 3 import ( 4 "github.com/apache/thrift/lib/go/thrift" 5 "github.com/batchcorp/thrift-iterator/general" 6 "github.com/batchcorp/thrift-iterator/test" 7 "github.com/stretchr/testify/require" 8 "testing" 9 ) 10 11 func Test_skip_map_of_map(t *testing.T) { 12 should := require.New(t) 13 for _, c := range test.Combinations { 14 buf, proto := c.CreateProtocol() 15 proto.WriteMapBegin(thrift.I64, thrift.MAP, 1) 16 proto.WriteI64(1) 17 18 proto.WriteMapBegin(thrift.STRING, thrift.I64, 1) 19 proto.WriteString("k1") 20 proto.WriteI64(1) 21 proto.WriteMapEnd() 22 23 proto.WriteMapEnd() 24 iter := c.CreateIterator(buf.Bytes()) 25 should.Equal(buf.Bytes(), iter.SkipMap(nil)) 26 } 27 } 28 29 func Test_unmarshal_general_map_of_map(t *testing.T) { 30 should := require.New(t) 31 for _, c := range test.Combinations { 32 buf, proto := c.CreateProtocol() 33 proto.WriteMapBegin(thrift.I64, thrift.MAP, 1) 34 proto.WriteI64(1) 35 36 proto.WriteMapBegin(thrift.STRING, thrift.I64, 1) 37 proto.WriteString("k1") 38 proto.WriteI64(1) 39 proto.WriteMapEnd() 40 41 proto.WriteMapEnd() 42 var val general.Map 43 should.NoError(c.Unmarshal(buf.Bytes(), &val)) 44 should.Equal(general.Map{ 45 "k1": int64(1), 46 }, val[int64(1)]) 47 } 48 } 49 50 func Test_marshal_general_map_of_map(t *testing.T) { 51 should := require.New(t) 52 for _, c := range test.Combinations { 53 m := general.Map{ 54 int64(1): general.Map{ 55 "k1": int64(1), 56 }, 57 } 58 59 output, err := c.Marshal(m) 60 should.NoError(err) 61 output1, err := c.Marshal(&m) 62 should.NoError(err) 63 should.Equal(output, output1) 64 var val general.Map 65 should.NoError(c.Unmarshal(output, &val)) 66 should.Equal(general.Map{ 67 "k1": int64(1), 68 }, val[int64(1)]) 69 } 70 } 71 72 func Test_marshal_map_of_map(t *testing.T) { 73 should := require.New(t) 74 for _, c := range test.MarshalCombinations { 75 m := map[int64]map[string]int64{ 76 1: {"k1": 1}, 77 } 78 79 output, err := c.Marshal(m) 80 should.NoError(err) 81 output1, err := c.Marshal(&m) 82 should.NoError(err) 83 should.Equal(output, output1) 84 var val general.Map 85 should.NoError(c.Unmarshal(output, &val)) 86 should.Equal(general.Map{ 87 "k1": int64(1), 88 }, val[int64(1)]) 89 } 90 }