struct_ptr_test.go 603 B

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