Skip to content

Commit

Permalink
resolve conversations for serialization.Set v2
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-li committed Sep 22, 2024
1 parent a714bd5 commit 2e175d5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 96 deletions.
76 changes: 0 additions & 76 deletions marshal/tests/funcs/default.go

This file was deleted.

17 changes: 2 additions & 15 deletions marshal/tests/funcs/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@ import (
)

func New(in interface{}) interface{} {
return getNew(reflect.ValueOf(in))
}

func getNew(orig reflect.Value) reflect.Value {
if orig.Kind() != reflect.Ptr {
return reflect.Zero(orig.Type())
}
if orig.IsNil() {
return reflect.Zero(orig.Type())
} else if orig.IsZero() {
return reflect.Zero(orig.Type())
}
newVal := reflect.New(orig.Type().Elem())
newVal.Elem().Set(getNew(orig.Elem()))
return newVal
out := reflect.New(reflect.TypeOf(in)).Interface()
return out
}
11 changes: 6 additions & 5 deletions marshal/tests/serialization/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ func (s Set) runMarshal(t *testing.T, f func(interface{}) ([]byte, error), val i
}()

if err != nil {
tt.Fatalf("marshal unexpectedly failed with error: %w", err)
tt.Fatalf("marshal unexpectedly failed with error: %s", err.Error())
}

if !funcs.EqualData(s.Data, result) {
expected := s.Data
if !funcs.EqualData(expected, result) {
tt.Errorf("expect %s but got %s", utils.StringData(s.Data), utils.StringData(result))
}
})
Expand All @@ -74,7 +75,7 @@ func (s Set) runMarshal(t *testing.T, f func(interface{}) ([]byte, error), val i
func (s Set) runUnmarshal(t *testing.T, f func([]byte, interface{}) error, expected interface{}) {
t.Run("unmarshal", func(tt *testing.T) {
if s.IssueUnmarshal != "" {
t.Skipf("skipped bacause there is unsolved issue: %s", s.IssueUnmarshal)
tt.Skipf("skipped bacause there is unsolved issue: %s", s.IssueUnmarshal)
}

result := funcs.New(expected)
Expand All @@ -90,11 +91,11 @@ func (s Set) runUnmarshal(t *testing.T, f func([]byte, interface{}) error, expec
}()

if err != nil {
tt.Fatalf("unmarshal unexpectedly failed with error: %w", err)
tt.Fatalf("unmarshal unexpectedly failed with error: %s", err.Error())
}

if outValPtr := utils.StringPointer(result); inValPtr != "" && outValPtr != "" && inValPtr != outValPtr {
tt.Fatalf("for (%T) unmarshal function rewrites existing pointer", expected)
tt.Fatal("unmarshal function rewrote target pointer")
}

if !funcs.EqualVals(expected, utils.DeReference(result)) {
Expand Down

0 comments on commit 2e175d5

Please sign in to comment.