Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.47
0.0.48
2 changes: 2 additions & 0 deletions internal/reflect/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var (
TypeOf = reflect.TypeOf
// ValueOf alias for `reflect.ValueOf`.
ValueOf = reflect.ValueOf
// New alias for `reflect.New`.
New = reflect.New
// Zero alias for `reflect.Zero`.
Zero = reflect.Zero
// Ptr alias for `reflect.Ptr`.
Expand Down
25 changes: 18 additions & 7 deletions test/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,26 @@ func DeepCopy(t Test, p DeepCopyParams) {

// Then
rv := reflect.ValueOf(value)
if !rv.IsNil() {
// Only check NotSame for pointer types
if rv.Kind() == reflect.Ptr {
assert.NotSame(t, value, result)
}
assert.Equal(t, value, result)
} else {
if rv.IsNil() {
assert.Nil(t, result)

return // Different pointer types cannot be equal.
}

// Wrap result in pointer if original value is pointer.
if rv.Kind() == reflect.Ptr {
// Create a new pointer to the result value.
rvr := reflect.ValueOf(result)
if rvr.Kind() != reflect.Ptr {
presult := reflect.New(rvr.Type())
presult.Elem().Set(rvr)
result = presult.Interface()
}

// Only check not Same for two pointer types.
assert.NotSame(t, value, result)
}
assert.Equal(t, value, result)
}

// deepCopy performs a deep copy of the given value using the either the
Expand Down
106 changes: 85 additions & 21 deletions test/pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,19 +892,19 @@ var deepCopyTestCases = map[string]DeepCopyParams{
Value: (*structDeepCopy)(nil),
},
},
"struct-deep-copy-value": {
"struct-deep-copy-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &structDeepCopy{Value: 3},
Value: &structDeepCopy{Value: 4},
},
},
"struct-deep-copy-object-nil": {
DeepCopyParams: test.DeepCopyParams{
Value: (*structDeepCopyObject)(nil),
},
},
"struct-deep-copy-object-value": {
"struct-deep-copy-object-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &structDeepCopyObject{Value: 4},
Value: &structDeepCopyObject{Value: 6},
},
},
"slice-deep-copy-nil": {
Expand All @@ -915,9 +915,18 @@ var deepCopyTestCases = map[string]DeepCopyParams{
"slice-deep-copy-value": {
DeepCopyParams: test.DeepCopyParams{
Value: sliceDeepCopy{
structDeepCopy{Value: 5},
structDeepCopy{Value: 6},
structDeepCopy{Value: 7},
structDeepCopy{Value: 8},
structDeepCopy{Value: 9},
},
},
},
"slice-deep-copy-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &sliceDeepCopy{
structDeepCopy{Value: 10},
structDeepCopy{Value: 11},
structDeepCopy{Value: 12},
},
},
},
Expand All @@ -929,9 +938,18 @@ var deepCopyTestCases = map[string]DeepCopyParams{
"slice-deep-copy-object-value": {
DeepCopyParams: test.DeepCopyParams{
Value: sliceDeepCopyObject{
structDeepCopyObject{Value: 8},
structDeepCopyObject{Value: 9},
structDeepCopyObject{Value: 10},
structDeepCopyObject{Value: 13},
structDeepCopyObject{Value: 14},
structDeepCopyObject{Value: 15},
},
},
},
"slice-deep-copy-object-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &sliceDeepCopyObject{
structDeepCopyObject{Value: 16},
structDeepCopyObject{Value: 17},
structDeepCopyObject{Value: 18},
},
},
},
Expand All @@ -943,9 +961,18 @@ var deepCopyTestCases = map[string]DeepCopyParams{
"slice-ptr-deep-copy-value": {
DeepCopyParams: test.DeepCopyParams{
Value: slicePtrDeepCopy{
&structDeepCopy{Value: 11},
&structDeepCopy{Value: 12},
&structDeepCopy{Value: 13},
&structDeepCopy{Value: 19},
&structDeepCopy{Value: 20},
&structDeepCopy{Value: 21},
},
},
},
"slice-ptr-deep-copy-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &slicePtrDeepCopy{
&structDeepCopy{Value: 22},
&structDeepCopy{Value: 23},
&structDeepCopy{Value: 24},
},
},
},
Expand All @@ -957,9 +984,18 @@ var deepCopyTestCases = map[string]DeepCopyParams{
"slice-ptr-deep-copy-object-value": {
DeepCopyParams: test.DeepCopyParams{
Value: slicePtrDeepCopyObject{
&structDeepCopyObject{Value: 14},
&structDeepCopyObject{Value: 15},
&structDeepCopyObject{Value: 16},
&structDeepCopyObject{Value: 25},
&structDeepCopyObject{Value: 26},
&structDeepCopyObject{Value: 27},
},
},
},
"slice-ptr-deep-copy-object-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &slicePtrDeepCopyObject{
&structDeepCopyObject{Value: 28},
&structDeepCopyObject{Value: 29},
&structDeepCopyObject{Value: 30},
},
},
},
Expand All @@ -971,7 +1007,14 @@ var deepCopyTestCases = map[string]DeepCopyParams{
"map-deep-copy-value": {
DeepCopyParams: test.DeepCopyParams{
Value: mapDeepCopy{
"key": structDeepCopy{Value: 17},
"key": structDeepCopy{Value: 31},
},
},
},
"map-deep-copy-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &mapDeepCopy{
"key": structDeepCopy{Value: 32},
},
},
},
Expand All @@ -982,8 +1025,15 @@ var deepCopyTestCases = map[string]DeepCopyParams{
},
"map-deep-copy-object-value": {
DeepCopyParams: test.DeepCopyParams{
Value: mapDeepCopyObject{
"key": structDeepCopyObject{Value: 19},
Value: &mapDeepCopyObject{
"key": structDeepCopyObject{Value: 33},
},
},
},
"map-deep-copy-object-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &mapDeepCopyObject{
"key": structDeepCopyObject{Value: 34},
},
},
},
Expand All @@ -995,7 +1045,14 @@ var deepCopyTestCases = map[string]DeepCopyParams{
"map-ptr-deep-copy-value": {
DeepCopyParams: test.DeepCopyParams{
Value: mapPtrDeepCopy{
"key": &structDeepCopy{Value: 18},
"key": &structDeepCopy{Value: 35},
},
},
},
"map-ptr-deep-copy-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &mapPtrDeepCopy{
"key": &structDeepCopy{Value: 36},
},
},
},
Expand All @@ -1006,8 +1063,15 @@ var deepCopyTestCases = map[string]DeepCopyParams{
},
"map-ptr-deep-copy-object-value": {
DeepCopyParams: test.DeepCopyParams{
Value: mapPtrDeepCopyObject{
"key": &structDeepCopyObject{Value: 20},
Value: &mapPtrDeepCopyObject{
"key": &structDeepCopyObject{Value: 37},
},
},
},
"map-ptr-deep-copy-object-value*": {
DeepCopyParams: test.DeepCopyParams{
Value: &mapPtrDeepCopyObject{
"key": &structDeepCopyObject{Value: 38},
},
},
},
Expand Down
Loading