github.com/jxskiss/gopkg@v0.17.3/reflectx/equality_test.go (about) 1 package reflectx 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 type testtype1 struct { 10 A string 11 B int64 12 } 13 14 type testtype2 struct { 15 A string 16 B int64 17 } 18 19 type testtype3 struct { 20 A string 21 B int8 22 } 23 24 type recurtype1 struct { 25 A string 26 b int32 27 self *recurtype1 28 } 29 30 type recurtype2 struct { 31 A string 32 b int32 33 self *recurtype2 34 } 35 36 type recurtype3 struct { 37 A *testtype1 38 B *recurtype3 39 } 40 41 type recurtype4 struct { 42 A *testtype2 43 B *recurtype3 44 } 45 46 func TestIsIdenticalType(t *testing.T) { 47 equal, msg := IsIdenticalType(&testtype1{}, &testtype2{}) 48 t.Log(msg) 49 assert.True(t, equal) 50 51 equal, msg = IsIdenticalType(&testtype1{}, &testtype3{}) 52 t.Log(msg) 53 assert.False(t, equal) 54 55 equal, msg = IsIdenticalType(&testtype2{}, &testtype3{}) 56 t.Log(msg) 57 assert.False(t, equal) 58 } 59 60 func TestIsIdenticalType_Recursive(t *testing.T) { 61 equal, msg := IsIdenticalType(&recurtype1{}, &recurtype2{}) 62 t.Log(msg) 63 assert.True(t, equal) 64 65 equal, msg = IsIdenticalType(&recurtype3{}, &recurtype4{}) 66 t.Log(msg) 67 assert.True(t, equal) 68 } 69 70 type thriftType1 struct { 71 EntityID *int64 `thrift:"Entity,1"` 72 HtMLLink *string `thrift:"HtmlLink,2"` 73 } 74 75 type thriftType2 struct { 76 EntityId *int64 `thrift:"Entity,1"` 77 HtmlLink *string `thrift:"HtmlLink,2"` 78 } 79 80 func TestIsIdenticalThriftType(t *testing.T) { 81 equal, msg := IsIdenticalThriftType(&thriftType1{}, &thriftType2{}) 82 t.Log(msg) 83 assert.True(t, equal) 84 }