github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/reflect2/test/struct_ptr_test.go (about)

     1  package test
     2  
     3  import (
     4  	"testing"
     5  	"github.com/v2pro/plz/countlog"
     6  	"github.com/v2pro/plz/reflect2"
     7  	"github.com/v2pro/plz/test/must"
     8  	"github.com/v2pro/plz/test"
     9  )
    10  
    11  func Test_struct_ptr(t *testing.T) {
    12  	type TestObject struct {
    13  		Field1 *int
    14  	}
    15  	t.Run("PackEFace", test.Case(func(ctx *countlog.Context) {
    16  		valType := reflect2.TypeOf(TestObject{})
    17  		ptr := valType.UnsafeNew()
    18  		must.Equal(&TestObject{}, valType.PackEFace(ptr))
    19  	}))
    20  	t.Run("Indirect", test.Case(func(ctx *countlog.Context) {
    21  		valType := reflect2.TypeOf(TestObject{})
    22  		must.Equal(TestObject{}, valType.Indirect(&TestObject{}))
    23  	}))
    24  }