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.46
0.0.47
22 changes: 11 additions & 11 deletions internal/reflect/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@ func (r *random) newPrimitive(kind reflect.Kind) any {
case reflect.Bool:
return r.rand.Intn(r.length) != 0
case reflect.Int:
return r.rand.Intn(r.length) + 1
return r.rand.Intn(2<<r.length) + 1
case reflect.Int8:
return int8(r.rand.Intn(r.length) + 1) // #nosec G115 -- intentional use.
return int8(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Int16:
return int16(r.rand.Intn(r.length) + 1) // #nosec G115 -- intentional use.
return int16(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Int32:
return int32(r.rand.Intn(r.length) + 1) // #nosec G115 -- intentional use.
return int32(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Int64:
return int64(r.rand.Intn(r.length) + 1) // #nosec G115 -- intentional use.
return int64(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Uint:
return uint(r.rand.Intn(r.length) + 1) // #nosec G115 -- intentional use.
return uint(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Uint8:
return uint8(r.rand.Intn(r.length) + 1) // #nosec G115 -- intentional use.
return uint8(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Uint16:
return uint16(r.rand.Intn(r.length) + 1) // #nosec G115 -- intentional use.
return uint16(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Uint32:
return uint32(r.rand.Intn(r.length) + 1) // #nosec G115 -- intentional use.
return uint32(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Uint64:
return uint64(r.rand.Intn(r.length) + 1) // #nosec G115 -- intentional use.
return uint64(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Uintptr:
return uintptr(r.rand.Intn(r.length) + 1)
return uintptr(r.rand.Intn(2<<r.length) + 1)
case reflect.Float32:
return float32(r.rand.Float64())
case reflect.Float64:
Expand Down
17 changes: 16 additions & 1 deletion test/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,25 @@ func DeepCopy(t Test, p DeepCopyParams) {
// `DeepCopyObject` or the `DeepCopy` method - in this order.
func deepCopy(value any) (any, error) {
rv := reflect.ValueOf(value)
if !rv.IsValid() /* || rv.IsNil() */ {
if !rv.IsValid() {
return nil, errNoDeepCopyMethod
}

if rv.Kind() == reflect.Ptr && rv.IsNil() {
elem := rv.Type().Elem()
zeroValue := reflect.Zero(elem)

if method, ok := elem.MethodByName("DeepCopyObject"); ok {
return zeroValue.Method(method.Index).
Call(nil)[0].Interface(), nil
}

if method, ok := elem.MethodByName("DeepCopy"); ok {
return zeroValue.Method(method.Index).
Call(nil)[0].Interface(), nil
}
}

method := rv.MethodByName("DeepCopyObject")
if method.IsValid() {
return method.Call(nil)[0].Interface(), nil
Expand Down
Loading
Loading