copier.go103
1:1file-length-limit
copier.go:1:1
package copier1:1format
copier.go:1:1
package copier- Fix (safe): run `strider fmt copier.go`
1:9package-comments
copier.go:1:9
package copier13:1doc-comment-period
copier.go:13:1
// These flags define options for tag handlingconst (31:2doc-comment-period
copier.go:31:2
// Some default converter types for a nicer syntax String string = ""32:2exported-declaration-comment
copier.go:32:2
// Some default converter types for a nicer syntax String string = "" Bool bool = false33:2exported-declaration-comment
copier.go:33:2
String string = "" Bool bool = false Int int = 034:2exported-declaration-comment
copier.go:34:2
Bool bool = false Int int = 0 Float32 float32 = 035:2exported-declaration-comment
copier.go:35:2
Int int = 0 Float32 float32 = 0 Float64 float64 = 036:2exported-declaration-comment
copier.go:36:2
Float32 float32 = 0 Float64 float64 = 0)39:1doc-comment-period
copier.go:39:1
// Option sets copy optionstype Option struct {57:19confusing-naming
copier.go:57:19
func (opt Option) converters() map[converterPair]TypeConverter { var converters = map[converterPair]TypeConverter{}73:1top-level-declaration-order
copier.go:73:1
type TypeConverter struct { SrcType interface{}73:6exported-declaration-comment
copier.go:73:6
type TypeConverter struct { SrcType interface{}74:10use-any
copier.go:74:10
type TypeConverter struct { SrcType interface{} DstType interface{}75:10use-any
copier.go:75:10
SrcType interface{} DstType interface{} Fn func(src interface{}) (dst interface{}, err error)76:19use-any
copier.go:76:19
DstType interface{} Fn func(src interface{}) (dst interface{}, err error)}76:37use-any
copier.go:76:37
DstType interface{} Fn func(src interface{}) (dst interface{}, err error)}84:19confusing-naming
copier.go:84:19
func (opt Option) fieldNameMapping() map[converterPair]FieldNameMapping { var mapping = map[converterPair]FieldNameMapping{}99:6exported-declaration-comment
copier.go:99:6
type FieldNameMapping struct { SrcType interface{}100:10use-any
copier.go:100:10
type FieldNameMapping struct { SrcType interface{} DstType interface{}101:10use-any
copier.go:101:10
SrcType interface{} DstType interface{} Mapping map[string]string118:1doc-comment-period
copier.go:118:1
// Copy copy thingsfunc Copy(toValue interface{}, fromValue interface{}) (err error) {119:19use-any
copier.go:119:19
// Copy copy thingsfunc Copy(toValue interface{}, fromValue interface{}) (err error) { return copier(toValue, fromValue, Option{})119:42use-any
copier.go:119:42
// Copy copy thingsfunc Copy(toValue interface{}, fromValue interface{}) (err error) { return copier(toValue, fromValue, Option{})123:1doc-comment-period
copier.go:123:1
// CopyWithOption copy with optionfunc CopyWithOption(toValue interface{}, fromValue interface{}, opt Option) (err error) {124:29use-any
copier.go:124:29
// CopyWithOption copy with optionfunc CopyWithOption(toValue interface{}, fromValue interface{}, opt Option) (err error) { return copier(toValue, fromValue, opt)124:52use-any
copier.go:124:52
// CopyWithOption copy with optionfunc CopyWithOption(toValue interface{}, fromValue interface{}, opt Option) (err error) { return copier(toValue, fromValue, opt)128:6cognitive-complexity
copier.go:128:6
func copier(toValue interface{}, fromValue interface{}, opt Option) (err error) { var (128:6cyclomatic-complexity
copier.go:128:6
func copier(toValue interface{}, fromValue interface{}, opt Option) (err error) { var (128:6function-length
copier.go:128:6
func copier(toValue interface{}, fromValue interface{}, opt Option) (err error) { var (128:21use-any
copier.go:128:21
func copier(toValue interface{}, fromValue interface{}, opt Option) (err error) { var (128:44use-any
copier.go:128:44
func copier(toValue interface{}, fromValue interface{}, opt Option) (err error) { var (164:5optimize-operands-order
copier.go:164:5
// Just set it if possible to assign for normal types if from.Kind() != reflect.Slice && from.Kind() != reflect.Struct && from.Kind() != reflect.Map && (from.Type().AssignableTo(to.Type()) || from.Type().ConvertibleTo(to.Type())) { if !isPtrFrom || !opt.DeepCopy {172:3no-naked-return
copier.go:172:3
} return }175:5optimize-operands-order
copier.go:175:5
if from.Kind() != reflect.Slice && fromType.Kind() == reflect.Map && toType.Kind() == reflect.Map { if !fromType.Key().ConvertibleTo(toType.Key()) {215:5modifies-parameter
copier.go:215:5
elemType = reflect.PtrTo(elemType) toValue = toValue.Addr() }218:3no-naked-return
copier.go:218:3
} return }224:4no-naked-return
copier.go:224:4
if from.IsNil() && to.IsNil() { return }252:4no-naked-return
copier.go:252:4
return }258:3no-naked-return
copier.go:258:3
// skip not supported type return }262:56optimize-operands-order
copier.go:262:56
if len(converters) > 0 { if ok, e := set(to, from, opt.DeepCopy, converters); e == nil && ok { // converter supported264:4no-naked-return
copier.go:264:4
// converter supported return }293:61optimize-operands-order
copier.go:293:61
if len(converters) > 0 { if ok, e := set(dest, source, opt.DeepCopy, converters); e == nil && ok { if isSlice {295:6task-comment
copier.go:295:6
if isSlice { // FIXME: maybe should check the other types? if to.Type().Elem().Kind() == reflect.Ptr {299:7max-control-nesting
copier.go:299:7
} else { if to.Len() < i+1 { reflect.Append(to, dest)352:7max-control-nesting
copier.go:352:7
// only initialize parent embedded struct pointer in the path for idx := range f.Index[:len(f.Index)-1] { destField := dest.FieldByIndex(f.Index[:idx+1])355:8max-control-nesting
copier.go:355:8
if destField.Kind() != reflect.Ptr { continue359:8max-control-nesting
copier.go:359:8
if !destField.IsNil() { continue362:8max-control-nesting
copier.go:362:8
} if !destField.CanSet() { destFieldNotSet = true379:7max-control-nesting
copier.go:379:7
if toField.IsValid() { if toField.CanSet() { isSet, err := set(toField, fromField, opt.DeepCopy, converters)381:8max-control-nesting
copier.go:381:8
isSet, err := set(toField, fromField, opt.DeepCopy, converters) if err != nil { return err384:8max-control-nesting
copier.go:384:8
} if !isSet { if err := copier(toField.Addr().Interface(), fromField.Interface(), opt); err != nil {385:9max-control-nesting
copier.go:385:9
if !isSet { if err := copier(toField.Addr().Interface(), fromField.Interface(), opt); err != nil { return err389:8max-control-nesting
copier.go:389:8
} if fieldFlags != 0 { // Note that a copy was made397:7max-control-nesting
copier.go:397:7
var toMethod reflect.Value if dest.CanAddr() { toMethod = dest.Addr().MethodByName(destFieldName)403:7max-control-nesting
copier.go:403:7
if toMethod.IsValid() && toMethod.Type().NumIn() == 1 && fromField.Type().AssignableTo(toMethod.Type().In(0)) { toMethod.Call([]reflect.Value{fromField})422:8optimize-operands-order
copier.go:422:8
if fromMethod.IsValid() && fromMethod.Type().NumIn() == 0 && fromMethod.Type().NumOut() == 1 && !shouldIgnore(fromMethod, flgs.BitFlags[name], opt.IgnoreEmpty) { if toField := fieldByName(dest, destFieldName, opt.CaseSensitive); toField.IsValid() && toField.CanSet() {422:8optimize-operands-order
copier.go:422:8
if fromMethod.IsValid() && fromMethod.Type().NumIn() == 0 && fromMethod.Type().NumOut() == 1 && !shouldIgnore(fromMethod, flgs.BitFlags[name], opt.IgnoreEmpty) { if toField := fieldByName(dest, destFieldName, opt.CaseSensitive); toField.IsValid() && toField.CanSet() {425:7max-control-nesting
copier.go:425:7
values := fromMethod.Call([]reflect.Value{}) if len(values) >= 1 { set(toField, values[0], opt.DeepCopy, converters)426:8discarded-error-result
copier.go:426:8
if len(values) >= 1 { set(toField, values[0], opt.DeepCopy, converters) }445:7max-control-nesting
copier.go:445:7
err = copier(to.Index(i).Addr().Interface(), dest.Addr().Interface(), opt) if err != nil { continue455:6max-control-nesting
copier.go:455:6
isSet, err := set(to.Index(i), dest, opt.DeepCopy, converters) if err != nil { return err458:6max-control-nesting
copier.go:458:6
} if !isSet { // ignore error while copy slice element461:7max-control-nesting
copier.go:461:7
err = copier(to.Index(i).Addr().Interface(), dest.Interface(), opt) if err != nil { continue474:2no-naked-return
copier.go:474:2
return}524:5no-package-var
copier.go:524:5
var deepFieldsLock sync.RWMutexvar deepFieldsMap = make(map[reflect.Type][]reflect.StructField)525:5no-package-var
copier.go:525:5
var deepFieldsLock sync.RWMutexvar deepFieldsMap = make(map[reflect.Type][]reflect.StructField)527:6cognitive-complexity
copier.go:527:6
func deepFields(reflectType reflect.Type) []reflect.StructField { deepFieldsLock.RLock()535:5modifies-parameter
copier.go:535:5
var res []reflect.StructField if reflectType, _ = indirectType(reflectType); reflectType.Kind() == reflect.Struct { fields := make([]reflect.StructField, 0, reflectType.NumField())562:3modifies-parameter
copier.go:562:3
for reflectValue.Kind() == reflect.Ptr { reflectValue = reflectValue.Elem() }569:3modifies-parameter
copier.go:569:3
for reflectType.Kind() == reflect.Ptr || reflectType.Kind() == reflect.Slice { reflectType = reflectType.Elem() isPtr = true575:6cognitive-complexity
copier.go:575:6
func set(to, from reflect.Value, deepCopy bool, converters map[converterPair]TypeConverter) (bool, error) { if !from.IsValid() {575:6cyclomatic-complexity
copier.go:575:6
func set(to, from reflect.Value, deepCopy bool, converters map[converterPair]TypeConverter) (bool, error) { if !from.IsValid() {575:6function-length
copier.go:575:6
func set(to, from reflect.Value, deepCopy bool, converters map[converterPair]TypeConverter) (bool, error) { if !from.IsValid() {575:34flag-parameter
copier.go:575:34
func set(to, from reflect.Value, deepCopy bool, converters map[converterPair]TypeConverter) (bool, error) { if !from.IsValid() {581:4no-else-after-return
copier.go:581:4
return false, err } else if ok { return true, nil587:6optimize-operands-order
copier.go:587:6
// set `to` to nil if from is nil if from.Kind() == reflect.Ptr && from.IsNil() { to.Set(reflect.Zero(to.Type()))590:5no-else-after-return
copier.go:590:5
return true, nil } else if to.IsNil() { // `from` -> `to`596:6nil-error-return
copier.go:596:6
if err != nil { return true, nil }605:13optimize-operands-order
copier.go:605:13
to.Set(reflect.New(to.Type().Elem())) } else if from.Kind() != reflect.Ptr && from.IsZero() { to.Set(reflect.Zero(to.Type()))610:3modifies-parameter
copier.go:610:3
// depointer `to` to = to.Elem() }621:6optimize-operands-order
copier.go:621:6
} if from.Kind() == reflect.Ptr && from.IsNil() { to.Set(reflect.Zero(to.Type()))625:60optimize-operands-order
copier.go:625:60
} if _, ok := to.Addr().Interface().(sql.Scanner); !ok && (toKind == reflect.Struct || toKind == reflect.Map || toKind == reflect.Slice) { return false, nil646:4modifies-parameter
copier.go:646:4
// depointer `from` from = indirect(from) }663:4nil-error-return
copier.go:663:4
if err != nil { return false, nil }718:3single-case-switch
copier.go:718:3
for _, t := range strings.Split(tag, ",") { switch t { case "-":721:4no-naked-return
copier.go:721:4
flg = tagIgnore return case "must":736:2no-naked-return
copier.go:736:2
} return}740:6cognitive-complexity
copier.go:740:6
// getTagFlags Parses struct tags for bit flags, field name.func getFlags(dest, src reflect.Value, toType, fromType reflect.Type, opt Option) (flags, error) { flgs := flags{740:6cyclomatic-complexity
copier.go:740:6
// getTagFlags Parses struct tags for bit flags, field name.func getFlags(dest, src reflect.Value, toType, fromType reflect.Type, opt Option) (flags, error) { flgs := flags{772:6no-else-after-return
copier.go:772:6
return flags{}, err } else if name != "" { flgs.DestNames.FieldNameToTag[field.Name] = name796:6no-else-after-return
copier.go:796:6
return flags{}, err } else if name != "" { flgs.SrcNames.FieldNameToTag[field.Name] = name811:4single-case-switch
copier.go:811:4
if flgs&hasCopied == 0 { switch { case flgs&tagMust != 0 && flgs&tagNoPanic != 0:814:5no-naked-return
copier.go:814:5
err = fmt.Errorf("field %s has must tag but was not copied", name) return case flgs&(tagMust) != 0:820:2no-naked-return
copier.go:820:2
} return}823:6cognitive-complexity
copier.go:823:6
func getFieldName(fieldName string, flgs flags, fieldNameMapping map[string]string) (srcFieldName string, destFieldName string) { // get dest field name828:3no-naked-return
copier.go:828:3
destFieldName = name return }860:2no-naked-return
copier.go:860:2
} return}866:3no-naked-return
copier.go:866:3
i, ok = v.Interface().(driver.Valuer) return }870:2no-naked-return
copier.go:870:2
i, ok = v.Addr().Interface().(driver.Valuer) return}873:6cognitive-complexity
copier.go:873:6
func fieldByName(v reflect.Value, name string, caseSensitive bool) reflect.Value { if caseSensitive {873:48flag-parameter
copier.go:873:48
func fieldByName(v reflect.Value, name string, caseSensitive bool) reflect.Value { if caseSensitive {copier_benchmark_test.go10
1:1format
copier_benchmark_test.go:1:1
package copier_test- Fix (safe): run `strider fmt copier_benchmark_test.go`
14:3discarded-error-result
copier_benchmark_test.go:14:3
for x := 0; x < b.N; x++ { copier.Copy(&Employee{}, &user) }31:44range-value-address
copier_benchmark_test.go:31:44
for _, note := range user.Notes { employee.Notes = append(employee.Notes, ¬e) }39:21add-constant
copier_benchmark_test.go:39:21
var fakeAge int32 = 12 user := User{Name: "Jinzhu", Nickname: "jinzhu", Age: 18, FakeAge: &fakeAge, Role: "Admin", Notes: []string{"hello world", "welcome"}, flags: []byte{'x'}} for x := 0; x < b.N; x++ {39:41add-constant
copier_benchmark_test.go:39:41
var fakeAge int32 = 12 user := User{Name: "Jinzhu", Nickname: "jinzhu", Age: 18, FakeAge: &fakeAge, Role: "Admin", Notes: []string{"hello world", "welcome"}, flags: []byte{'x'}} for x := 0; x < b.N; x++ {39:85add-constant
copier_benchmark_test.go:39:85
var fakeAge int32 = 12 user := User{Name: "Jinzhu", Nickname: "jinzhu", Age: 18, FakeAge: &fakeAge, Role: "Admin", Notes: []string{"hello world", "welcome"}, flags: []byte{'x'}} for x := 0; x < b.N; x++ {39:110add-constant
copier_benchmark_test.go:39:110
var fakeAge int32 = 12 user := User{Name: "Jinzhu", Nickname: "jinzhu", Age: 18, FakeAge: &fakeAge, Role: "Admin", Notes: []string{"hello world", "welcome"}, flags: []byte{'x'}} for x := 0; x < b.N; x++ {39:125add-constant
copier_benchmark_test.go:39:125
var fakeAge int32 = 12 user := User{Name: "Jinzhu", Nickname: "jinzhu", Age: 18, FakeAge: &fakeAge, Role: "Admin", Notes: []string{"hello world", "welcome"}, flags: []byte{'x'}} for x := 0; x < b.N; x++ {41:14discarded-error-result
copier_benchmark_test.go:41:14
for x := 0; x < b.N; x++ { data, _ := json.Marshal(user) var employee Employee43:3discarded-error-result
copier_benchmark_test.go:43:3
var employee Employee json.Unmarshal(data, &employee)copier_case_insensitive_test.go22
1:1format
copier_case_insensitive_test.go:1:1
package copier- Fix (safe): run `strider fmt copier_case_insensitive_test.go`
7:1doc-comment-period
copier_case_insensitive_test.go:7:1
// Test case for issue where case-insensitive field matching// fails when there are both exported and unexported fields with similar names9:6test-parallelism
copier_case_insensitive_test.go:9:6
// fails when there are both exported and unexported fields with similar namesfunc TestCaseInsensitiveFieldMatching(t *testing.T) { // Simulate protobuf generated struct with both unexported 'state' and exported 'State' fields11:7exported-declaration-comment
copier_case_insensitive_test.go:11:7
// Simulate protobuf generated struct with both unexported 'state' and exported 'State' fields type ProtoStruct struct { state uint3214:3confusing-naming
copier_case_insensitive_test.go:14:3
PageNumber int32 `json:"pageNumber"` State int32 `json:"state"` }17:7exported-declaration-comment
copier_case_insensitive_test.go:17:7
type SourceStruct struct { PageNumber int32 `json:"pageNumber"`36:12error-strings
copier_case_insensitive_test.go:36:12
if dest.State != source.State { t.Errorf("State field not copied correctly. Expected: %d, Got: %d", source.State, dest.State) }44:12error-strings
copier_case_insensitive_test.go:44:12
if dest.PageNumber != source.PageNumber { t.Errorf("PageNumber field not copied correctly. Expected: %d, Got: %d", source.PageNumber, dest.PageNumber) }48:1doc-comment-period
copier_case_insensitive_test.go:48:1
// Test that exact case matching still worksfunc TestExactCaseMatching(t *testing.T) {49:6test-parallelism
copier_case_insensitive_test.go:49:6
// Test that exact case matching still worksfunc TestExactCaseMatching(t *testing.T) { type Source struct {50:7exported-declaration-comment
copier_case_insensitive_test.go:50:7
func TestExactCaseMatching(t *testing.T) { type Source struct { Name string55:7exported-declaration-comment
copier_case_insensitive_test.go:55:7
type Dest struct { Name string69:12error-strings
copier_case_insensitive_test.go:69:12
if dest.Name != source.Name || dest.Age != source.Age { t.Errorf("Fields not copied correctly. Expected: %+v, Got: %+v", source, *dest) }73:6test-parallelism
copier_case_insensitive_test.go:73:6
func TestCaseInsensitiveMatchingWithEmbeddedField(t *testing.T) { type Embedded struct {74:7exported-declaration-comment
copier_case_insensitive_test.go:74:7
func TestCaseInsensitiveMatchingWithEmbeddedField(t *testing.T) { type Embedded struct { Name string78:7exported-declaration-comment
copier_case_insensitive_test.go:78:7
type Dest struct { name string78:7max-public-structs
copier_case_insensitive_test.go:78:7
type Dest struct { name string79:3confusing-naming
copier_case_insensitive_test.go:79:3
type Dest struct { name string Embedded83:7exported-declaration-comment
copier_case_insensitive_test.go:83:7
type Source struct { NAME string83:7max-public-structs
copier_case_insensitive_test.go:83:7
type Source struct { NAME string84:3confusing-naming
copier_case_insensitive_test.go:84:3
type Source struct { NAME string }97:12add-constant
copier_case_insensitive_test.go:97:12
if err != nil { t.Fatalf("Copy failed: %v", err) }copier_converter_test.go47
1:1format
copier_converter_test.go:1:1
package copier_test- Fix (safe): run `strider fmt copier_converter_test.go`
16:6function-length
copier_converter_test.go:16:6
func TestCopyWithTypeConverters(t *testing.T) { type SrcStruct struct {16:6test-parallelism
copier_converter_test.go:16:6
func TestCopyWithTypeConverters(t *testing.T) { type SrcStruct struct {17:7exported-declaration-comment
copier_converter_test.go:17:7
func TestCopyWithTypeConverters(t *testing.T) { type SrcStruct struct { Field1 time.Time24:7exported-declaration-comment
copier_converter_test.go:24:7
type DestStruct struct { Field1 string49:18use-any
copier_converter_test.go:49:18
DstType: copier.String, Fn: func(src interface{}) (interface{}, error) { s, ok := src.(time.Time)49:32use-any
copier_converter_test.go:49:32
DstType: copier.String, Fn: func(src interface{}) (interface{}, error) { s, ok := src.(time.Time)62:18use-any
copier_converter_test.go:62:18
DstType: copier.Int, Fn: func(src interface{}) (interface{}, error) { s, ok := src.(string)62:32use-any
copier_converter_test.go:62:32
DstType: copier.Int, Fn: func(src interface{}) (interface{}, error) { s, ok := src.(string)90:12add-constant
copier_converter_test.go:90:12
if dst.Field3 != "" { t.Fatalf("got %q, wanted %q", dst.Field3, "") }98:6test-parallelism
copier_converter_test.go:98:6
func TestCopyWithConverterAndAnnotation(t *testing.T) { type SrcStruct struct {99:7exported-declaration-comment
copier_converter_test.go:99:7
func TestCopyWithConverterAndAnnotation(t *testing.T) { type SrcStruct struct { Field1 string103:7exported-declaration-comment
copier_converter_test.go:103:7
type DestStruct struct { Field1 string121:18use-any
copier_converter_test.go:121:18
DstType: copier.String, Fn: func(src interface{}) (interface{}, error) { s, ok := src.(string)121:32use-any
copier_converter_test.go:121:32
DstType: copier.String, Fn: func(src interface{}) (interface{}, error) { s, ok := src.(string)125:30add-constant
copier_converter_test.go:125:30
if !ok { return nil, errors.New("src type not matching") }143:6test-parallelism
copier_converter_test.go:143:6
func TestCopyWithConverterStrToStrPointer(t *testing.T) { type SrcStruct struct {144:7exported-declaration-comment
copier_converter_test.go:144:7
func TestCopyWithConverterStrToStrPointer(t *testing.T) { type SrcStruct struct { Field1 string148:7exported-declaration-comment
copier_converter_test.go:148:7
type DestStruct struct { Field1 *string148:7max-public-structs
copier_converter_test.go:148:7
type DestStruct struct { Field1 *string167:18use-any
copier_converter_test.go:167:18
DstType: &ptrStrType, Fn: func(src interface{}) (interface{}, error) { s, _ := src.(string)167:32use-any
copier_converter_test.go:167:32
DstType: &ptrStrType, Fn: func(src interface{}) (interface{}, error) { s, _ := src.(string)172:7nil-value-with-nil-error
copier_converter_test.go:172:7
if s == "" { return nil, nil }181:12add-constant
copier_converter_test.go:181:12
if err != nil { t.Fatalf(`Should be able to copy from src to dst object. %v`, err) return190:6test-parallelism
copier_converter_test.go:190:6
func TestCopyWithConverterRaisingError(t *testing.T) { type SrcStruct struct {191:7exported-declaration-comment
copier_converter_test.go:191:7
func TestCopyWithConverterRaisingError(t *testing.T) { type SrcStruct struct { Field1 string191:7max-public-structs
copier_converter_test.go:191:7
func TestCopyWithConverterRaisingError(t *testing.T) { type SrcStruct struct { Field1 string195:7exported-declaration-comment
copier_converter_test.go:195:7
type DestStruct struct { Field1 *string195:7max-public-structs
copier_converter_test.go:195:7
type DestStruct struct { Field1 *string214:18use-any
copier_converter_test.go:214:18
DstType: &ptrStrType, Fn: func(src interface{}) (interface{}, error) { return nil, errors.New("src type not matching")214:32use-any
copier_converter_test.go:214:32
DstType: &ptrStrType, Fn: func(src interface{}) (interface{}, error) { return nil, errors.New("src type not matching")226:1top-level-declaration-order
copier_converter_test.go:226:1
type IntArray []int226:6exported-declaration-comment
copier_converter_test.go:226:6
type IntArray []int228:19exported-declaration-comment
copier_converter_test.go:228:19
func (a IntArray) Value() (driver.Value, error) { return json.Marshal(a)232:6exported-declaration-comment
copier_converter_test.go:232:6
type Int int234:6exported-declaration-comment
copier_converter_test.go:234:6
type From struct { Data IntArray234:6max-public-structs
copier_converter_test.go:234:6
type From struct { Data IntArray238:6exported-declaration-comment
copier_converter_test.go:238:6
type To struct { Data []byte238:6max-public-structs
copier_converter_test.go:238:6
type To struct { Data []byte242:6exported-declaration-comment
copier_converter_test.go:242:6
type FailedTo struct { Data []Int242:6max-public-structs
copier_converter_test.go:242:6
type FailedTo struct { Data []Int246:6cyclomatic-complexity
copier_converter_test.go:246:6
func TestValuerConv(t *testing.T) { // when the field of struct implement driver.Valuer and cannot convert to dest type directly,246:6test-parallelism
copier_converter_test.go:246:6
func TestValuerConv(t *testing.T) { // when the field of struct implement driver.Valuer and cannot convert to dest type directly,253:5optimize-operands-order
copier_converter_test.go:253:5
if typ1 == typ2 || typ1.ConvertibleTo(typ2) || typ1.AssignableTo(typ2) { // in 1.22 and older, u can not convert typ1 to typ2278:5optimize-operands-order
copier_converter_test.go:278:5
// Testcase2: fallback case when valuer conv failed if len(failedTo.Data) != 3 || failedTo.Data[0] != 1 || failedTo.Data[1] != 2 || failedTo.Data[2] != 3 { t.Errorf("copier failed from %#v to %#v", from, failedTo)278:5optimize-operands-order
copier_converter_test.go:278:5
// Testcase2: fallback case when valuer conv failed if len(failedTo.Data) != 3 || failedTo.Data[0] != 1 || failedTo.Data[1] != 2 || failedTo.Data[2] != 3 { t.Errorf("copier failed from %#v to %#v", from, failedTo)278:5optimize-operands-order
copier_converter_test.go:278:5
// Testcase2: fallback case when valuer conv failed if len(failedTo.Data) != 3 || failedTo.Data[0] != 1 || failedTo.Data[1] != 2 || failedTo.Data[2] != 3 { t.Errorf("copier failed from %#v to %#v", from, failedTo)copier_different_type_test.go33
1:1format
copier_different_type_test.go:1:1
package copier_test- Fix (safe): run `strider fmt copier_different_type_test.go`
11:6exported-declaration-comment
copier_different_type_test.go:11:6
type TypeStruct1 struct { Field1 string23:6exported-declaration-comment
copier_different_type_test.go:23:6
type TypeStruct2 struct { Field1 int32:6exported-declaration-comment
copier_different_type_test.go:32:6
type TypeStruct3 struct { Field1 interface{}33:9use-any
copier_different_type_test.go:33:9
type TypeStruct3 struct { Field1 interface{} Field2 string43:6exported-declaration-comment
copier_different_type_test.go:43:6
type TypeStruct4 struct { field1 int48:23exported-declaration-comment
copier_different_type_test.go:48:23
func (t *TypeStruct4) Field1(i int) { t.field1 = i52:1top-level-declaration-order
copier_different_type_test.go:52:1
type TypeBaseStruct5 struct { A bool52:6exported-declaration-comment
copier_different_type_test.go:52:6
type TypeBaseStruct5 struct { A bool63:6exported-declaration-comment
copier_different_type_test.go:63:6
type TypeSqlNullStruct6 struct { A sql.NullBool `json:"a"`63:6max-public-structs
copier_different_type_test.go:63:6
type TypeSqlNullStruct6 struct { A sql.NullBool `json:"a"`74:6test-parallelism
copier_different_type_test.go:74:6
func TestCopyDifferentFieldType(t *testing.T) { ts := &TypeStruct1{81:2discarded-error-result
copier_different_type_test.go:81:2
copier.Copy(ts2, ts)84:12error-strings
copier_different_type_test.go:84:12
if ts2.Field2 != ts.Field2 || ts2.Field1 != 0 { t.Errorf("Should be able to copy from ts to ts2") }88:6test-parallelism
copier_different_type_test.go:88:6
func TestCopyDifferentTypeMethod(t *testing.T) { ts := &TypeStruct1{95:2discarded-error-result
copier_different_type_test.go:95:2
copier.Copy(ts4, ts)98:12error-strings
copier_different_type_test.go:98:12
if ts4.Field2 != ts.Field2 || ts4.field1 != 0 { t.Errorf("Should be able to copy from ts to ts4") }102:6cognitive-complexity
copier_different_type_test.go:102:6
func TestAssignableType(t *testing.T) { ts := &TypeStruct1{102:6test-parallelism
copier_different_type_test.go:102:6
func TestAssignableType(t *testing.T) { ts := &TypeStruct1{104:11add-constant
copier_different_type_test.go:104:11
ts := &TypeStruct1{ Field1: "str1", Field2: "str2",105:11add-constant
copier_different_type_test.go:105:11
Field1: "str1", Field2: "str2", Field3: TypeStruct2{136:2discarded-error-result
copier_different_type_test.go:136:2
copier.CopyWithOption(&ts3, &ts, copier.Option{CaseSensitive: true})145:12error-strings
copier_different_type_test.go:145:12
if ts3.Field2 != ts.Field2 { t.Errorf("Field2 should be copied") }178:6cognitive-complexity
copier_different_type_test.go:178:6
func TestCopyFromBaseToSqlNullWithOptionDeepCopy(t *testing.T) { a := TypeBaseStruct5{178:6cyclomatic-complexity
copier_different_type_test.go:178:6
func TestCopyFromBaseToSqlNullWithOptionDeepCopy(t *testing.T) { a := TypeBaseStruct5{178:6test-parallelism
copier_different_type_test.go:178:6
func TestCopyFromBaseToSqlNullWithOptionDeepCopy(t *testing.T) { a := TypeBaseStruct5{181:6redundant-conversion
copier_different_type_test.go:181:6
A: true, B: byte(2), C: 5.5,194:12error-strings
copier_different_type_test.go:194:12
if err != nil { t.Errorf("CopyStructWithOption() error = %v", err) return198:19boolean-literal-comparison
copier_different_type_test.go:198:19
// ę£ę„ b ē»ęä½ēåꮵęÆå¦ē¬¦åé¢ę if !b.A.Valid || b.A.Bool != true { t.Errorf("b.A = %v, want %v", b.A, true)201:31redundant-conversion
copier_different_type_test.go:201:31
} if !b.B.Valid || b.B.Byte != byte(2) { t.Errorf("b.B = %v, want %v", b.B, byte(2))202:38redundant-conversion
copier_different_type_test.go:202:38
if !b.B.Valid || b.B.Byte != byte(2) { t.Errorf("b.B = %v, want %v", b.B, byte(2)) }216:19time-value-equality
copier_different_type_test.go:216:19
} if !b.G.Valid || b.G.Time != a.G { t.Errorf("b.G = %v, want %v", b.G, a.G)220:38add-constant
copier_different_type_test.go:220:38
if !b.H.Valid || b.H.String != "deep" { t.Errorf("b.H = %v, want %v", b.H, "deep") }copier_field_name_mapping_test.go4
1:1format
copier_field_name_mapping_test.go:1:1
package copier_test- Fix (safe): run `strider fmt copier_field_name_mapping_test.go`
9:6test-parallelism
copier_field_name_mapping_test.go:9:6
func TestCustomFieldName(t *testing.T) { type User1 struct {10:7exported-declaration-comment
copier_field_name_mapping_test.go:10:7
func TestCustomFieldName(t *testing.T) { type User1 struct { Id int6416:7exported-declaration-comment
copier_field_name_mapping_test.go:16:7
type User2 struct { Id2 int64copier_issue170_test.go15
1:1format
copier_issue170_test.go:1:1
package copier_test- Fix (safe): run `strider fmt copier_issue170_test.go`
9:6exported-declaration-comment
copier_issue170_test.go:9:6
type A struct { A int12:6exported-declaration-comment
copier_issue170_test.go:12:6
}type B struct { A int17:1top-level-declaration-order
copier_issue170_test.go:17:1
var copied = B{A: 2387483274, b: 128387134}17:5no-package-var
copier_issue170_test.go:17:5
var copied = B{A: 2387483274, b: 128387134}25:19use-any
copier_issue170_test.go:25:19
DstType: B{}, Fn: func(from interface{}) (interface{}, error) { return copied, nil25:33use-any
copier_issue170_test.go:25:33
DstType: B{}, Fn: func(from interface{}) (interface{}, error) { return copied, nil33:6test-parallelism
copier_issue170_test.go:33:6
func Test_Struct_With_Converter(t *testing.T) { aa := A{A: 11}42:6test-parallelism
copier_issue170_test.go:42:6
func Test_Map_With_Converter(t *testing.T) { aa := map[string]*A{64:6test-parallelism
copier_issue170_test.go:64:6
func Test_Slice_With_Converter(t *testing.T) { aa := []*A{83:13add-constant
copier_issue170_test.go:83:13
if !reflect.DeepEqual(*temp, wanted) { t.Fatalf("Got %v, wanted %v", *temp, wanted) }88:6test-parallelism
copier_issue170_test.go:88:6
func Test_Slice_Embedded_With_Converter(t *testing.T) { aa := struct {89:8nested-structs
copier_issue170_test.go:89:8
func Test_Slice_Embedded_With_Converter(t *testing.T) { aa := struct { A []*A95:8nested-structs
copier_issue170_test.go:95:8
bb := struct { A []*B103:12nested-structs
copier_issue170_test.go:103:12
wanted := struct { A []*Bcopier_issue84_test.go11
1:1format
copier_issue84_test.go:1:1
package copier_test- Fix (safe): run `strider fmt copier_issue84_test.go`
10:6exported-declaration-comment
copier_issue84_test.go:10:6
type Embedded struct { Field1 string15:6exported-declaration-comment
copier_issue84_test.go:15:6
type Embedder struct { Embedded20:6exported-declaration-comment
copier_issue84_test.go:20:6
type Timestamps struct { CreatedAt time.Time `json:"created_at"`25:6exported-declaration-comment
copier_issue84_test.go:25:6
type NotWork struct { ID string `json:"id"`33:6exported-declaration-comment
copier_issue84_test.go:33:6
type Work struct { ID string `json:"id"`41:6test-parallelism
copier_issue84_test.go:41:6
func TestIssue84(t *testing.T) { t.Run("test1", func(t *testing.T) {42:17test-parallelism
copier_issue84_test.go:42:17
func TestIssue84(t *testing.T) { t.Run("test1", func(t *testing.T) { var embedder Embedder59:22test-parallelism
copier_issue84_test.go:59:22
}) t.Run("from issue", func(t *testing.T) { notWorkObj := NotWork{82:3discarded-error-result
copier_issue84_test.go:82:3
copier.CopyWithOption(&destObj1, &workObj, copier.Option{IgnoreEmpty: true, DeepCopy: false})84:3discarded-error-result
copier_issue84_test.go:84:3
copier.CopyWithOption(&destObj2, ¬WorkObj, copier.Option{IgnoreEmpty: true, DeepCopy: false}) })copier_tags_test.go40
1:1format
copier_tags_test.go:1:1
package copier_test- Fix (safe): run `strider fmt copier_tags_test.go`
9:6exported-declaration-comment
copier_tags_test.go:9:6
type EmployeeTags struct { Name string `copier:"must"`16:6exported-declaration-comment
copier_tags_test.go:16:6
type EmployeeTags2 struct { Name string `copier:"must,nopanic"`23:6exported-declaration-comment
copier_tags_test.go:23:6
type EmployeeTags3 struct { Name string30:6exported-declaration-comment
copier_tags_test.go:30:6
type User1 struct { Name string37:6exported-declaration-comment
copier_tags_test.go:37:6
type User2 struct { DOB string43:6test-parallelism
copier_tags_test.go:43:6
func TestCopyTagIgnore(t *testing.T) { employee := EmployeeTags{ID: 100}46:2discarded-error-result
copier_tags_test.go:46:2
user := User1{Name: "Dexter Ledesma", DOB: "1 November, 1970", Address: "21 Jump Street", ID: 12345} copier.Copy(&employee, user) if employee.ID == user.ID {55:6test-parallelism
copier_tags_test.go:55:6
func TestCopyTagMust(t *testing.T) { employee := &EmployeeTags{}63:2discarded-error-result
copier_tags_test.go:63:2
}() copier.Copy(employee, user)}66:6test-parallelism
copier_tags_test.go:66:6
func TestCopyTagMustByOption(t *testing.T) { employee := &EmployeeTags3{}69:24test-parallelism
copier_tags_test.go:69:24
user := &User2{DOB: "1 January 1970"} t.Run("must is true", func(t *testing.T) { defer func() {75:3discarded-error-result
copier_tags_test.go:75:3
}() copier.CopyWithOption(employee, user, copier.Option{Must: true}) })78:25test-parallelism
copier_tags_test.go:78:25
t.Run("must is false", func(t *testing.T) { defer func() {84:3discarded-error-result
copier_tags_test.go:84:3
}() copier.CopyWithOption(employee, user, copier.Option{Must: false}) })88:6test-parallelism
copier_tags_test.go:88:6
func TestCopyTagMustAndNoPanic(t *testing.T) { employee := &EmployeeTags2{}90:22add-constant
copier_tags_test.go:90:22
employee := &EmployeeTags2{} user := &User2{DOB: "1 January 1970"} err := copier.Copy(employee, user)97:6test-parallelism
copier_tags_test.go:97:6
func TestCopyTagMustAndNoPanicByOption(t *testing.T) { employee := &EmployeeTags3{}106:6test-parallelism
copier_tags_test.go:106:6
func TestCopyTagOverrideZeroValue(t *testing.T) { options := copier.Option{IgnoreEmpty: true}111:2discarded-error-result
copier_tags_test.go:111:2
copier.CopyWithOption(&user, employee, options) if user.Address != "" {117:6test-parallelism
copier_tags_test.go:117:6
func TestCopyTagOverridePtrToZeroValue(t *testing.T) { options := copier.Option{IgnoreEmpty: true}119:13add-constant
copier_tags_test.go:119:13
options := copier.Option{IgnoreEmpty: true} address := "21 Jump Street" user1 := User1{ID: 100, Address: ""}121:22add-constant
copier_tags_test.go:121:22
user1 := User1{ID: 100, Address: ""} user2 := User2{DOB: "1 November, 1970", Address: &address, ID: 12345}123:2discarded-error-result
copier_tags_test.go:123:2
copier.CopyWithOption(&user2, user1, options) if user2.Address != nil {129:6test-parallelism
copier_tags_test.go:129:6
func TestCopyTagOverrideZeroValueToPtr(t *testing.T) { options := copier.Option{IgnoreEmpty: true}134:2discarded-error-result
copier_tags_test.go:134:2
copier.CopyWithOption(&user2, user1, options) if user1.Address != nil {136:11add-constant
copier_tags_test.go:136:11
if user1.Address != nil { t.Error("Original Address was not overwritten") }140:6test-parallelism
copier_tags_test.go:140:6
func TestCopyTagOverridePtr(t *testing.T) { options := copier.Option{IgnoreEmpty: true}146:2discarded-error-result
copier_tags_test.go:146:2
copier.CopyWithOption(&user, user2, options) if user.Address != nil {152:6test-parallelism
copier_tags_test.go:152:6
func TestCopyTagFieldName(t *testing.T) { t.Run("another name field copy", func(t *testing.T) {153:35test-parallelism
copier_tags_test.go:153:35
func TestCopyTagFieldName(t *testing.T) { t.Run("another name field copy", func(t *testing.T) { type SrcTags struct {154:8exported-declaration-comment
copier_tags_test.go:154:8
t.Run("another name field copy", func(t *testing.T) { type SrcTags struct { FieldA string154:8max-public-structs
copier_tags_test.go:154:8
t.Run("another name field copy", func(t *testing.T) { type SrcTags struct { FieldA string160:8exported-declaration-comment
copier_tags_test.go:160:8
type DestTags struct { Field1 string `copier:"FieldA"`160:8max-public-structs
copier_tags_test.go:160:8
type DestTags struct { Field1 string `copier:"FieldA"`188:36test-parallelism
copier_tags_test.go:188:36
t.Run("validate error flag name", func(t *testing.T) { type SrcTags struct {189:8exported-declaration-comment
copier_tags_test.go:189:8
t.Run("validate error flag name", func(t *testing.T) { type SrcTags struct { field string189:8max-public-structs
copier_tags_test.go:189:8
t.Run("validate error flag name", func(t *testing.T) { type SrcTags struct { field string193:8exported-declaration-comment
copier_tags_test.go:193:8
type DestTags struct { Field1 string `copier:"field"`193:8max-public-structs
copier_tags_test.go:193:8
type DestTags struct { Field1 string `copier:"field"`copier_test.go360
1:1file-length-limit
copier_test.go:1:1
package copier_test1:1format
copier_test.go:1:1
package copier_test- Fix (safe): run `strider fmt copier_test.go`
14:6exported-declaration-comment
copier_test.go:14:6
type User struct { Name string25:18exported-declaration-comment
copier_test.go:25:18
func (user User) DoubleAge() int32 { return 2 * user.Age29:1top-level-declaration-order
copier_test.go:29:1
type Employee struct { _User *User29:6exported-declaration-comment
copier_test.go:29:6
type Employee struct { _User *User30:2unexported-naming
copier_test.go:30:2
type Employee struct { _User *User Name string30:2var-naming
copier_test.go:30:2
type Employee struct { _User *User Name string43:27exported-declaration-comment
copier_test.go:43:27
func (employee *Employee) Role(role string) { employee.SuperRule = "Super " + role47:6cognitive-complexity
copier_test.go:47:6
func checkEmployee(employee Employee, user User, t *testing.T, testCase string) { if employee.Name != user.Name {47:6cyclomatic-complexity
copier_test.go:47:6
func checkEmployee(employee Employee, user User, t *testing.T, testCase string) { if employee.Name != user.Name {49:12error-strings
copier_test.go:49:12
if employee.Name != user.Name { t.Errorf("%v: Name haven't been copied correctly.", testCase) }52:12error-strings
copier_test.go:52:12
if employee.NickName == nil || *employee.NickName != user.Nickname { t.Errorf("%v: NickName haven't been copied correctly.", testCase) }55:12error-strings
copier_test.go:55:12
if employee.Birthday == nil && user.Birthday != nil { t.Errorf("%v: Birthday haven't been copied correctly.", testCase) }58:12error-strings
copier_test.go:58:12
if employee.Birthday != nil && user.Birthday == nil { t.Errorf("%v: Birthday haven't been copied correctly.", testCase) }62:12add-constant
copier_test.go:62:12
!employee.Birthday.Equal(*(user.Birthday)) { t.Errorf("%v: Birthday haven't been copied correctly.", testCase) }62:12error-strings
copier_test.go:62:12
!employee.Birthday.Equal(*(user.Birthday)) { t.Errorf("%v: Birthday haven't been copied correctly.", testCase) }65:12error-strings
copier_test.go:65:12
if employee.Age != int64(user.Age) { t.Errorf("%v: Age haven't been copied correctly.", testCase) }68:12error-strings
copier_test.go:68:12
if user.FakeAge != nil && employee.FakeAge != int(*user.FakeAge) { t.Errorf("%v: FakeAge haven't been copied correctly.", testCase) }88:6test-parallelism
copier_test.go:88:6
func TestCopySameStructWithPointerField(t *testing.T) { var fakeAge int32 = 1293:2discarded-error-result
copier_test.go:93:2
newUser := &User{} copier.Copy(newUser, user) if user.Birthday == newUser.Birthday {95:12error-strings
copier_test.go:95:12
if user.Birthday == newUser.Birthday { t.Errorf("TestCopySameStructWithPointerField: copy Birthday failed since they need to have different address") }99:12error-strings
copier_test.go:99:12
if user.FakeAge == newUser.FakeAge { t.Errorf("TestCopySameStructWithPointerField: copy FakeAge failed since they need to have different address") }105:6optimize-operands-order
copier_test.go:105:6
if user == nil { if employee.Name != "" || employee.NickName != nil || employee.Birthday != nil || employee.Age != 0 || employee.DoubleAge != 0 || employee.FakeAge != 0 || employee.SuperRule != "" || employee.Notes != nil {105:6optimize-operands-order
copier_test.go:105:6
if user == nil { if employee.Name != "" || employee.NickName != nil || employee.Birthday != nil || employee.Age != 0 || employee.DoubleAge != 0 || employee.FakeAge != 0 || employee.SuperRule != "" || employee.Notes != nil {105:6optimize-operands-order
copier_test.go:105:6
if user == nil { if employee.Name != "" || employee.NickName != nil || employee.Birthday != nil || employee.Age != 0 || employee.DoubleAge != 0 || employee.FakeAge != 0 || employee.SuperRule != "" || employee.Notes != nil {105:6optimize-operands-order
copier_test.go:105:6
if user == nil { if employee.Name != "" || employee.NickName != nil || employee.Birthday != nil || employee.Age != 0 || employee.DoubleAge != 0 || employee.FakeAge != 0 || employee.SuperRule != "" || employee.Notes != nil {105:6optimize-operands-order
copier_test.go:105:6
if user == nil { if employee.Name != "" || employee.NickName != nil || employee.Birthday != nil || employee.Age != 0 || employee.DoubleAge != 0 || employee.FakeAge != 0 || employee.SuperRule != "" || employee.Notes != nil {105:6optimize-operands-order
copier_test.go:105:6
if user == nil { if employee.Name != "" || employee.NickName != nil || employee.Birthday != nil || employee.Age != 0 || employee.DoubleAge != 0 || employee.FakeAge != 0 || employee.SuperRule != "" || employee.Notes != nil {115:6test-parallelism
copier_test.go:115:6
func TestCopySliceOfDifferentTypes(t *testing.T) { var ss []string123:12error-strings
copier_test.go:123:12
if !reflect.DeepEqual(ss, anotherSs) { t.Errorf("Copy nil slice to nil slice should get nil slice") }127:6test-parallelism
copier_test.go:127:6
func TestCopyStruct(t *testing.T) { var fakeAge int32 = 12133:12error-strings
copier_test.go:133:12
if err := copier.Copy(employee, &user); err == nil { t.Errorf("Copy to unaddressable value should get error") }136:2discarded-error-result
copier_test.go:136:2
copier.Copy(&employee, &user) checkEmployee(employee, user, t, "Copy From Ptr To Ptr")140:2discarded-error-result
copier_test.go:140:2
employee2 := Employee{} copier.Copy(&employee2, user) checkEmployee(employee2, user, t, "Copy From Struct To Ptr")145:2discarded-error-result
copier_test.go:145:2
ptrToUser := &user copier.Copy(&employee3, &ptrToUser) checkEmployee(employee3, user, t, "Copy From Double Ptr To Ptr")149:2discarded-error-result
copier_test.go:149:2
employee4 := &Employee{} copier.Copy(&employee4, user) checkEmployee(*employee4, user, t, "Copy From Ptr To Double Ptr")153:2discarded-error-result
copier_test.go:153:2
employee5 := &Employee{} copier.Copy(&employee5, &employee) checkEmployee(*employee5, user, t, "Copy From Employee To Employee")157:6test-parallelism
copier_test.go:157:6
func TestCopyFromStructToSlice(t *testing.T) { user := User{Name: "Jinzhu", Age: 18, Role: "Admin", Notes: []string{"hello world"}}158:21add-constant
copier_test.go:158:21
func TestCopyFromStructToSlice(t *testing.T) { user := User{Name: "Jinzhu", Age: 18, Role: "Admin", Notes: []string{"hello world"}} employees := []Employee{}158:46add-constant
copier_test.go:158:46
func TestCopyFromStructToSlice(t *testing.T) { user := User{Name: "Jinzhu", Age: 18, Role: "Admin", Notes: []string{"hello world"}} employees := []Employee{}158:71add-constant
copier_test.go:158:71
func TestCopyFromStructToSlice(t *testing.T) { user := User{Name: "Jinzhu", Age: 18, Role: "Admin", Notes: []string{"hello world"}} employees := []Employee{}162:12error-strings
copier_test.go:162:12
if err := copier.Copy(employees, &user); err != nil && len(employees) != 0 { t.Errorf("Copy to unaddressable value should get error") }165:5discarded-error-result
copier_test.go:165:5
if copier.Copy(&employees, &user); len(employees) != 1 { t.Errorf("Should only have one elem when copy struct to slice")166:12error-strings
copier_test.go:166:12
if copier.Copy(&employees, &user); len(employees) != 1 { t.Errorf("Should only have one elem when copy struct to slice") } else {172:5discarded-error-result
copier_test.go:172:5
employees2 := &[]Employee{} if copier.Copy(&employees2, user); len(*employees2) != 1 { t.Errorf("Should only have one elem when copy struct to slice")173:12error-strings
copier_test.go:173:12
if copier.Copy(&employees2, user); len(*employees2) != 1 { t.Errorf("Should only have one elem when copy struct to slice") } else {179:5discarded-error-result
copier_test.go:179:5
employees3 := []*Employee{} if copier.Copy(&employees3, user); len(employees3) != 1 { t.Errorf("Should only have one elem when copy struct to slice")180:12add-constant
copier_test.go:180:12
if copier.Copy(&employees3, user); len(employees3) != 1 { t.Errorf("Should only have one elem when copy struct to slice") } else {180:12error-strings
copier_test.go:180:12
if copier.Copy(&employees3, user); len(employees3) != 1 { t.Errorf("Should only have one elem when copy struct to slice") } else {186:5discarded-error-result
copier_test.go:186:5
employees4 := &[]*Employee{} if copier.Copy(&employees4, user); len(*employees4) != 1 { t.Errorf("Should only have one elem when copy struct to slice")187:12error-strings
copier_test.go:187:12
if copier.Copy(&employees4, user); len(*employees4) != 1 { t.Errorf("Should only have one elem when copy struct to slice") } else {193:6test-parallelism
copier_test.go:193:6
func TestCopyFromSliceToSlice(t *testing.T) { users := []User{199:5discarded-error-result
copier_test.go:199:5
if copier.Copy(&employees, users); len(employees) != 2 { t.Errorf("Should have two elems when copy slice to slice")200:12error-strings
copier_test.go:200:12
if copier.Copy(&employees, users); len(employees) != 2 { t.Errorf("Should have two elems when copy slice to slice") } else {207:5discarded-error-result
copier_test.go:207:5
employees2 := &[]Employee{} if copier.Copy(&employees2, &users); len(*employees2) != 2 { t.Errorf("Should have two elems when copy slice to slice")208:12error-strings
copier_test.go:208:12
if copier.Copy(&employees2, &users); len(*employees2) != 2 { t.Errorf("Should have two elems when copy slice to slice") } else {215:5discarded-error-result
copier_test.go:215:5
employees3 := []*Employee{} if copier.Copy(&employees3, users); len(employees3) != 2 { t.Errorf("Should have two elems when copy slice to slice")216:12add-constant
copier_test.go:216:12
if copier.Copy(&employees3, users); len(employees3) != 2 { t.Errorf("Should have two elems when copy slice to slice") } else {216:12error-strings
copier_test.go:216:12
if copier.Copy(&employees3, users); len(employees3) != 2 { t.Errorf("Should have two elems when copy slice to slice") } else {223:5discarded-error-result
copier_test.go:223:5
employees4 := &[]*Employee{} if copier.Copy(&employees4, users); len(*employees4) != 2 { t.Errorf("Should have two elems when copy slice to slice")224:12error-strings
copier_test.go:224:12
if copier.Copy(&employees4, users); len(*employees4) != 2 { t.Errorf("Should have two elems when copy slice to slice") } else {231:6test-parallelism
copier_test.go:231:6
func TestCopyFromSliceToSlice2(t *testing.T) { users := []*User{{Name: "Jinzhu", Age: 18, Role: "Admin", Notes: []string{"hello world"}}, nil}235:5discarded-error-result
copier_test.go:235:5
if copier.Copy(&employees, users); len(employees) != 2 { t.Errorf("Should have two elems when copy slice to slice")236:12error-strings
copier_test.go:236:12
if copier.Copy(&employees, users); len(employees) != 2 { t.Errorf("Should have two elems when copy slice to slice") } else {243:5discarded-error-result
copier_test.go:243:5
employees2 := &[]Employee{} if copier.Copy(&employees2, &users); len(*employees2) != 2 { t.Errorf("Should have two elems when copy slice to slice")244:12error-strings
copier_test.go:244:12
if copier.Copy(&employees2, &users); len(*employees2) != 2 { t.Errorf("Should have two elems when copy slice to slice") } else {251:5discarded-error-result
copier_test.go:251:5
employees3 := []*Employee{} if copier.Copy(&employees3, users); len(employees3) != 2 { t.Errorf("Should have two elems when copy slice to slice")252:12error-strings
copier_test.go:252:12
if copier.Copy(&employees3, users); len(employees3) != 2 { t.Errorf("Should have two elems when copy slice to slice") } else {259:5discarded-error-result
copier_test.go:259:5
employees4 := &[]*Employee{} if copier.Copy(&employees4, users); len(*employees4) != 2 { t.Errorf("Should have two elems when copy slice to slice")260:12error-strings
copier_test.go:260:12
if copier.Copy(&employees4, users); len(*employees4) != 2 { t.Errorf("Should have two elems when copy slice to slice") } else {267:6test-parallelism
copier_test.go:267:6
func TestCopyFromSliceToSlice3(t *testing.T) { type CollectionAlias struct {268:7exported-declaration-comment
copier_test.go:268:7
func TestCopyFromSliceToSlice3(t *testing.T) { type CollectionAlias struct { CollectionName string `json:"collection_name"`276:4add-constant
copier_test.go:276:4
{"collection", "collection_alias2"}, {"collection", "collection_alias3"}, }280:2discarded-error-result
copier_test.go:280:2
mockedResult := []*CollectionAlias{} copier.Copy(&mockedResult, &expectedResult)287:6identical-binary-operands
copier_test.go:287:6
for idx := range mockedResult { if mockedResult[idx].Name != mockedResult[idx].Name || mockedResult[idx].CollectionName != mockedResult[idx].CollectionName { t.Fatalf("failed to copy results")287:58identical-binary-operands
copier_test.go:287:58
for idx := range mockedResult { if mockedResult[idx].Name != mockedResult[idx].Name || mockedResult[idx].CollectionName != mockedResult[idx].CollectionName { t.Fatalf("failed to copy results")293:6test-parallelism
copier_test.go:293:6
func TestEmbeddedAndBase(t *testing.T) { type Base struct {294:7exported-declaration-comment
copier_test.go:294:7
func TestEmbeddedAndBase(t *testing.T) { type Base struct { BaseField1 int300:7exported-declaration-comment
copier_test.go:300:7
type Embed struct { EmbedField1 int318:2discarded-error-result
copier_test.go:318:2
copier.Copy(&base, &embedded)331:2discarded-error-result
copier_test.go:331:2
copier.Copy(&embedded, &base) if embedded.BaseField1 != 11 || embedded.User.Name != "testName1" {337:6cognitive-complexity
copier_test.go:337:6
func TestStructField(t *testing.T) { type Detail struct {337:6cyclomatic-complexity
copier_test.go:337:6
func TestStructField(t *testing.T) { type Detail struct {337:6function-length
copier_test.go:337:6
func TestStructField(t *testing.T) { type Detail struct {337:6test-parallelism
copier_test.go:337:6
func TestStructField(t *testing.T) { type Detail struct {338:7exported-declaration-comment
copier_test.go:338:7
func TestStructField(t *testing.T) { type Detail struct { Info1 string338:7max-public-structs
copier_test.go:338:7
func TestStructField(t *testing.T) { type Detail struct { Info1 string343:7exported-declaration-comment
copier_test.go:343:7
type SimilarDetail struct { Info1 string343:7max-public-structs
copier_test.go:343:7
type SimilarDetail struct { Info1 string348:7exported-declaration-comment
copier_test.go:348:7
type UserWithDetailsPtr struct { Details []*Detail348:7max-public-structs
copier_test.go:348:7
type UserWithDetailsPtr struct { Details []*Detail354:7exported-declaration-comment
copier_test.go:354:7
} type UserWithDetails struct { Details []Detail354:7max-public-structs
copier_test.go:354:7
} type UserWithDetails struct { Details []Detail360:7exported-declaration-comment
copier_test.go:360:7
} type UserWithSimilarDetailsPtr struct { Detail *SimilarDetail360:7max-public-structs
copier_test.go:360:7
} type UserWithSimilarDetailsPtr struct { Detail *SimilarDetail363:7exported-declaration-comment
copier_test.go:363:7
} type UserWithSimilarDetails struct { Detail SimilarDetail363:7max-public-structs
copier_test.go:363:7
} type UserWithSimilarDetails struct { Detail SimilarDetail366:7exported-declaration-comment
copier_test.go:366:7
} type EmployeeWithDetails struct { Detail Detail366:7max-public-structs
copier_test.go:366:7
} type EmployeeWithDetails struct { Detail Detail369:7exported-declaration-comment
copier_test.go:369:7
} type EmployeeWithDetailsPtr struct { Detail *Detail369:7max-public-structs
copier_test.go:369:7
} type EmployeeWithDetailsPtr struct { Detail *Detail372:7exported-declaration-comment
copier_test.go:372:7
} type EmployeeWithSimilarDetails struct { Detail SimilarDetail372:7max-public-structs
copier_test.go:372:7
} type EmployeeWithSimilarDetails struct { Detail SimilarDetail375:7exported-declaration-comment
copier_test.go:375:7
} type EmployeeWithSimilarDetailsPtr struct { Detail *SimilarDetail375:7max-public-structs
copier_test.go:375:7
} type EmployeeWithSimilarDetailsPtr struct { Detail *SimilarDetail388:6optimize-operands-order
copier_test.go:388:6
if (source.Info2 != nil || target.Info2 != nil) && (*source.Info2 != *target.Info2) { t.Errorf("info2 is diff: source: %v, target: %v", *source.Info2, *target.Info2)393:40test-parallelism
copier_test.go:393:40
t.Run("Should work without deepCopy", func(t *testing.T) { t.Run("Should work with same type and both ptr field", func(t *testing.T) {394:58test-parallelism
copier_test.go:394:58
t.Run("Should work without deepCopy", func(t *testing.T) { t.Run("Should work with same type and both ptr field", func(t *testing.T) { info2 := "world"398:32add-constant
copier_test.go:398:32
Detail: &Detail{Info1: "hello", Info2: &info2}, Details: []*Detail{{Info1: "hello", Info2: &info2}}, }401:4discarded-error-result
copier_test.go:401:4
to := UserWithDetailsPtr{} copier.Copy(&to, from)419:62test-parallelism
copier_test.go:419:62
t.Run("Should work with same type and both not ptr field", func(t *testing.T) { info2 := "world"426:4discarded-error-result
copier_test.go:426:4
to := UserWithDetails{} copier.Copy(&to, from)444:63test-parallelism
copier_test.go:444:63
t.Run("Should work with different type and both ptr field", func(t *testing.T) { info2 := "world"445:13add-constant
copier_test.go:445:13
t.Run("Should work with different type and both ptr field", func(t *testing.T) { info2 := "world" from := UserWithDetailsPtr{Detail: &Detail{Info1: "hello", Info2: &info2}}448:4discarded-error-result
copier_test.go:448:4
to := EmployeeWithDetailsPtr{} copier.Copy(&to, from)450:16add-constant
copier_test.go:450:16
newValue := "new value" to.Detail.Info2 = &newValue464:67test-parallelism
copier_test.go:464:67
t.Run("Should work with different type and both not ptr field", func(t *testing.T) { info2 := "world"468:4discarded-error-result
copier_test.go:468:4
to := EmployeeWithDetails{} copier.Copy(&to, from)484:65test-parallelism
copier_test.go:484:65
t.Run("Should work with from ptr field and to not ptr field", func(t *testing.T) { info2 := "world"488:4discarded-error-result
copier_test.go:488:4
to := EmployeeWithDetails{} copier.Copy(&to, from)494:14add-constant
copier_test.go:494:14
if to.Detail.Info1 == "" { t.Errorf("should not be empty") }497:14add-constant
copier_test.go:497:14
if to.Detail.Info1 != from.Detail.Info1 { t.Errorf("should be the same") }500:14add-constant
copier_test.go:500:14
if to.Detail.Info2 == from.Detail.Info2 { t.Errorf("should be different") }504:65test-parallelism
copier_test.go:504:65
t.Run("Should work with from not ptr field and to ptr field", func(t *testing.T) { info2 := "world"508:4discarded-error-result
copier_test.go:508:4
to := EmployeeWithDetailsPtr{} copier.Copy(&to, from)524:73test-parallelism
copier_test.go:524:73
t.Run("Should work with from a nil ptr slice field to a slice field", func(t *testing.T) { notes := []string{"hello", "world"}546:37test-parallelism
copier_test.go:546:37
t.Run("Should work with deepCopy", func(t *testing.T) { t.Run("Should work with same type and both ptr field", func(t *testing.T) {547:58test-parallelism
copier_test.go:547:58
t.Run("Should work with deepCopy", func(t *testing.T) { t.Run("Should work with same type and both ptr field", func(t *testing.T) { info2 := "world"554:4discarded-error-result
copier_test.go:554:4
to := UserWithDetailsPtr{} copier.CopyWithOption(&to, from, optionsDeepCopy)564:14add-constant
copier_test.go:564:14
if len(from.Details) != len(to.Details) { t.Fatalf("slice should be copied") }571:62test-parallelism
copier_test.go:571:62
}) t.Run("Should work with same type and both not ptr field", func(t *testing.T) { info2 := "world"578:4discarded-error-result
copier_test.go:578:4
to := UserWithDetails{} copier.CopyWithOption(&to, from, optionsDeepCopy)596:63test-parallelism
copier_test.go:596:63
t.Run("Should work with different type and both ptr field", func(t *testing.T) { info2 := "world"600:4discarded-error-result
copier_test.go:600:4
to := EmployeeWithDetailsPtr{} copier.CopyWithOption(&to, from, optionsDeepCopy)616:67test-parallelism
copier_test.go:616:67
t.Run("Should work with different type and both not ptr field", func(t *testing.T) { info2 := "world"620:4discarded-error-result
copier_test.go:620:4
to := EmployeeWithDetails{} copier.CopyWithOption(&to, from, optionsDeepCopy)636:65test-parallelism
copier_test.go:636:65
t.Run("Should work with from ptr field and to not ptr field", func(t *testing.T) { info2 := "world"640:4discarded-error-result
copier_test.go:640:4
to := EmployeeWithDetails{} copier.CopyWithOption(&to, from, optionsDeepCopy)656:65test-parallelism
copier_test.go:656:65
t.Run("Should work with from not ptr field and to ptr field", func(t *testing.T) { info2 := "world"660:4discarded-error-result
copier_test.go:660:4
to := EmployeeWithDetailsPtr{} copier.CopyWithOption(&to, from, optionsDeepCopy)676:73test-parallelism
copier_test.go:676:73
t.Run("Should work with from a nil ptr slice field to a slice field", func(t *testing.T) { notes := []string{"hello", "world"}709:6cognitive-complexity
copier_test.go:709:6
func TestMapInterface(t *testing.T) { type Inner struct {709:6cyclomatic-complexity
copier_test.go:709:6
func TestMapInterface(t *testing.T) { type Inner struct {709:6function-length
copier_test.go:709:6
func TestMapInterface(t *testing.T) { type Inner struct {709:6test-parallelism
copier_test.go:709:6
func TestMapInterface(t *testing.T) { type Inner struct {710:7exported-declaration-comment
copier_test.go:710:7
func TestMapInterface(t *testing.T) { type Inner struct { IntPtr *int710:7max-public-structs
copier_test.go:710:7
func TestMapInterface(t *testing.T) { type Inner struct { IntPtr *int715:7exported-declaration-comment
copier_test.go:715:7
type Outer struct { Inner Inner715:7max-public-structs
copier_test.go:715:7
type Outer struct { Inner Inner719:7exported-declaration-comment
copier_test.go:719:7
type DriverOptions struct { GenOptions map[string]interface{}719:7max-public-structs
copier_test.go:719:7
type DriverOptions struct { GenOptions map[string]interface{}720:25use-any
copier_test.go:720:25
type DriverOptions struct { GenOptions map[string]interface{} }723:40test-parallelism
copier_test.go:723:40
t.Run("Should work without deepCopy", func(t *testing.T) { intVal := 5732:27use-any
copier_test.go:732:27
from := DriverOptions{ GenOptions: map[string]interface{}{ "key": outer,738:13error-strings
copier_test.go:738:13
if err := copier.Copy(&to, &from); nil != err { t.Errorf("Unexpected error: %v", err) return742:24unchecked-type-assertion
copier_test.go:742:24
*to.GenOptions["key"].(Outer).Inner.IntPtr = 6744:20add-constant
copier_test.go:744:20
if to.GenOptions["key"].(Outer).Inner.IntPtr != from.GenOptions["key"].(Outer).Inner.IntPtr { t.Errorf("should be the same")744:26unchecked-type-assertion
copier_test.go:744:26
if to.GenOptions["key"].(Outer).Inner.IntPtr != from.GenOptions["key"].(Outer).Inner.IntPtr { t.Errorf("should be the same")744:73unchecked-type-assertion
copier_test.go:744:73
if to.GenOptions["key"].(Outer).Inner.IntPtr != from.GenOptions["key"].(Outer).Inner.IntPtr { t.Errorf("should be the same")749:37test-parallelism
copier_test.go:749:37
t.Run("Should work with deepCopy", func(t *testing.T) { intVal := 5758:27use-any
copier_test.go:758:27
from := DriverOptions{ GenOptions: map[string]interface{}{ "key": outer,766:13error-strings
copier_test.go:766:13
}); nil != err { t.Errorf("Unexpected error: %v", err) return770:24unchecked-type-assertion
copier_test.go:770:24
*to.GenOptions["key"].(Outer).Inner.IntPtr = 6772:26unchecked-type-assertion
copier_test.go:772:26
if to.GenOptions["key"].(Outer).Inner.IntPtr == from.GenOptions["key"].(Outer).Inner.IntPtr { t.Errorf("should be different")772:73unchecked-type-assertion
copier_test.go:772:73
if to.GenOptions["key"].(Outer).Inner.IntPtr == from.GenOptions["key"].(Outer).Inner.IntPtr { t.Errorf("should be different")777:44test-parallelism
copier_test.go:777:44
t.Run("Test copy map with nil interface", func(t *testing.T) { from := map[string]interface{}{"eventId": nil}778:22use-any
copier_test.go:778:22
t.Run("Test copy map with nil interface", func(t *testing.T) { from := map[string]interface{}{"eventId": nil} to := map[string]interface{}{"eventId": nil}779:20use-any
copier_test.go:779:20
from := map[string]interface{}{"eventId": nil} to := map[string]interface{}{"eventId": nil} copier.CopyWithOption(&to, &from, copier.Option{IgnoreEmpty: true, DeepCopy: true})780:3discarded-error-result
copier_test.go:780:3
to := map[string]interface{}{"eventId": nil} copier.CopyWithOption(&to, &from, copier.Option{IgnoreEmpty: true, DeepCopy: true}) if v, ok := to["eventId"]; !ok || v != nil {781:18add-constant
copier_test.go:781:18
copier.CopyWithOption(&to, &from, copier.Option{IgnoreEmpty: true, DeepCopy: true}) if v, ok := to["eventId"]; !ok || v != nil { t.Errorf("failed to deep copy map with nil, got %v", v)790:3discarded-error-result
copier_test.go:790:3
copier.CopyWithOption(&to, &from, copier.Option{IgnoreEmpty: true, DeepCopy: true}) if v, ok := to["eventId"]; !ok || v != 1 {801:47test-parallelism
copier_test.go:801:47
t.Run("Test copy map with nested slice map", func(t *testing.T) { var out map[string]interface{}802:22use-any
copier_test.go:802:22
t.Run("Test copy map with nested slice map", func(t *testing.T) { var out map[string]interface{} value := map[string]interface{}{803:23use-any
copier_test.go:803:23
var out map[string]interface{} value := map[string]interface{}{ "list": []map[string]interface{}{804:25use-any
copier_test.go:804:25
value := map[string]interface{}{ "list": []map[string]interface{}{ {809:15use-any
copier_test.go:809:15
}, "list2": []interface{}{ map[string]interface{}{810:16use-any
copier_test.go:810:16
"list2": []interface{}{ map[string]interface{}{ "shop_id": 123,825:6test-parallelism
copier_test.go:825:6
func TestInterface(t *testing.T) { type Inner struct {826:7exported-declaration-comment
copier_test.go:826:7
func TestInterface(t *testing.T) { type Inner struct { IntPtr *int826:7max-public-structs
copier_test.go:826:7
func TestInterface(t *testing.T) { type Inner struct { IntPtr *int830:7exported-declaration-comment
copier_test.go:830:7
type Outer struct { Inner Inner830:7max-public-structs
copier_test.go:830:7
type Outer struct { Inner Inner834:7exported-declaration-comment
copier_test.go:834:7
type DriverOptions struct { GenOptions interface{}834:7max-public-structs
copier_test.go:834:7
type DriverOptions struct { GenOptions interface{}835:14use-any
copier_test.go:835:14
type DriverOptions struct { GenOptions interface{} }838:8add-constant
copier_test.go:838:8
t.Run("Should work without deepCopy", func(t *testing.T) { intVal := 5838:40test-parallelism
copier_test.go:838:40
t.Run("Should work without deepCopy", func(t *testing.T) { intVal := 5850:13add-constant
copier_test.go:850:13
if err := copier.Copy(&to, from); nil != err { t.Errorf("Unexpected error: %v", err) return850:13error-strings
copier_test.go:850:13
if err := copier.Copy(&to, from); nil != err { t.Errorf("Unexpected error: %v", err) return854:17unchecked-type-assertion
copier_test.go:854:17
*to.GenOptions.(Outer).Inner.IntPtr = 6856:19unchecked-type-assertion
copier_test.go:856:19
if to.GenOptions.(Outer).Inner.IntPtr != from.GenOptions.(Outer).Inner.IntPtr { t.Errorf("should be the same")856:59unchecked-type-assertion
copier_test.go:856:59
if to.GenOptions.(Outer).Inner.IntPtr != from.GenOptions.(Outer).Inner.IntPtr { t.Errorf("should be the same")861:8add-constant
copier_test.go:861:8
t.Run("Should work with deepCopy", func(t *testing.T) { intVal := 5861:37test-parallelism
copier_test.go:861:37
t.Run("Should work with deepCopy", func(t *testing.T) { intVal := 5875:13error-strings
copier_test.go:875:13
}); nil != err { t.Errorf("Unexpected error: %v", err) return879:17unchecked-type-assertion
copier_test.go:879:17
*to.GenOptions.(Outer).Inner.IntPtr = 6881:19unchecked-type-assertion
copier_test.go:881:19
if to.GenOptions.(Outer).Inner.IntPtr == from.GenOptions.(Outer).Inner.IntPtr { t.Errorf("should be different")881:59unchecked-type-assertion
copier_test.go:881:59
if to.GenOptions.(Outer).Inner.IntPtr == from.GenOptions.(Outer).Inner.IntPtr { t.Errorf("should be different")887:6cognitive-complexity
copier_test.go:887:6
func TestSlice(t *testing.T) { type ElemOption struct {887:6cyclomatic-complexity
copier_test.go:887:6
func TestSlice(t *testing.T) { type ElemOption struct {887:6function-length
copier_test.go:887:6
func TestSlice(t *testing.T) { type ElemOption struct {887:6test-parallelism
copier_test.go:887:6
func TestSlice(t *testing.T) { type ElemOption struct {888:7exported-declaration-comment
copier_test.go:888:7
func TestSlice(t *testing.T) { type ElemOption struct { Value int888:7max-public-structs
copier_test.go:888:7
func TestSlice(t *testing.T) { type ElemOption struct { Value int892:7exported-declaration-comment
copier_test.go:892:7
type A struct { X []int892:7max-public-structs
copier_test.go:892:7
type A struct { X []int897:7exported-declaration-comment
copier_test.go:897:7
type B struct { X []int897:7max-public-structs
copier_test.go:897:7
type B struct { X []int902:41test-parallelism
copier_test.go:902:41
t.Run("Should work with simple slice", func(t *testing.T) { from := []int{1, 2}907:13error-strings
copier_test.go:907:13
if err := copier.Copy(&to, from); nil != err { t.Errorf("Unexpected error: %v", err) return923:40test-parallelism
copier_test.go:923:40
t.Run("Should work with empty slice", func(t *testing.T) { from := []int{}928:13error-strings
copier_test.go:928:13
if err := copier.Copy(&to, from); nil != err { t.Errorf("Unexpected error: %v", err) return937:40test-parallelism
copier_test.go:937:40
t.Run("Should work without deepCopy", func(t *testing.T) { x := []int{1, 2}947:13error-strings
copier_test.go:947:13
if err := copier.Copy(&to, from); nil != err { t.Errorf("Unexpected error: %v", err) return977:37test-parallelism
copier_test.go:977:37
t.Run("Should work with deepCopy", func(t *testing.T) { x := []int{1, 2}989:13error-strings
copier_test.go:989:13
}); nil != err { t.Errorf("Unexpected error: %v", err) return1016:6cognitive-complexity
copier_test.go:1016:6
func TestAnonymousFields(t *testing.T) { t.Run("Should work with unexported ptr fields", func(t *testing.T) {1016:6cyclomatic-complexity
copier_test.go:1016:6
func TestAnonymousFields(t *testing.T) { t.Run("Should work with unexported ptr fields", func(t *testing.T) {1016:6function-length
copier_test.go:1016:6
func TestAnonymousFields(t *testing.T) { t.Run("Should work with unexported ptr fields", func(t *testing.T) {1016:6test-parallelism
copier_test.go:1016:6
func TestAnonymousFields(t *testing.T) { t.Run("Should work with unexported ptr fields", func(t *testing.T) {1017:50test-parallelism
copier_test.go:1017:50
func TestAnonymousFields(t *testing.T) { t.Run("Should work with unexported ptr fields", func(t *testing.T) { type nested struct {1035:13error-strings
copier_test.go:1035:13
if err != nil { t.Errorf("Unexpected error: %v", err) return1045:46test-parallelism
copier_test.go:1045:46
}) t.Run("Should work with unexported fields", func(t *testing.T) { type nested struct {1063:13error-strings
copier_test.go:1063:13
if err != nil { t.Errorf("Unexpected error: %v", err) return1074:48test-parallelism
copier_test.go:1074:48
t.Run("Should work with exported ptr fields", func(t *testing.T) { type Nested struct {1075:8exported-declaration-comment
copier_test.go:1075:8
t.Run("Should work with exported ptr fields", func(t *testing.T) { type Nested struct { A string1075:8max-public-structs
copier_test.go:1075:8
t.Run("Should work with exported ptr fields", func(t *testing.T) { type Nested struct { A string1085:17add-constant
copier_test.go:1085:17
fieldValue := "a" from := parentA{Nested: &Nested{A: fieldValue}}1093:13error-strings
copier_test.go:1093:13
if err != nil { t.Errorf("Unexpected error: %v", err) return1097:19add-constant
copier_test.go:1097:19
from.Nested.A = "b"1104:73test-parallelism
copier_test.go:1104:73
t.Run("Should work with exported ptr fields with same name src field", func(t *testing.T) { type Nested struct {1105:8exported-declaration-comment
copier_test.go:1105:8
t.Run("Should work with exported ptr fields with same name src field", func(t *testing.T) { type Nested struct { A string1105:8max-public-structs
copier_test.go:1105:8
t.Run("Should work with exported ptr fields with same name src field", func(t *testing.T) { type Nested struct { A string1123:13error-strings
copier_test.go:1123:13
if err != nil { t.Errorf("Unexpected error: %v", err) return1134:44test-parallelism
copier_test.go:1134:44
t.Run("Should work with exported fields", func(t *testing.T) { type Nested struct {1135:8exported-declaration-comment
copier_test.go:1135:8
t.Run("Should work with exported fields", func(t *testing.T) { type Nested struct { A string1135:8max-public-structs
copier_test.go:1135:8
t.Run("Should work with exported fields", func(t *testing.T) { type Nested struct { A string1153:13error-strings
copier_test.go:1153:13
if err != nil { t.Errorf("Unexpected error: %v", err) return1160:13add-constant
copier_test.go:1160:13
if to.Nested.A != fieldValue { t.Errorf("should not change") }1186:6test-parallelism
copier_test.go:1186:6
func TestCopyFieldsWithSameNameButDifferentTypes(t *testing.T) { obj1 := structSameName1{A: "123", B: 2, C: time.Now()}1195:12error-strings
copier_test.go:1195:12
if obj2.A != obj1.A { t.Errorf("Field A should be copied") }1199:6exported-declaration-comment
copier_test.go:1199:6
type Foo1 struct { Name string1199:6max-public-structs
copier_test.go:1199:6
type Foo1 struct { Name string1204:6exported-declaration-comment
copier_test.go:1204:6
type Foo2 struct { Name string1204:6max-public-structs
copier_test.go:1204:6
type Foo2 struct { Name string1208:6exported-declaration-comment
copier_test.go:1208:6
type StructWithMap1 struct { Map map[int]Foo11208:6max-public-structs
copier_test.go:1208:6
type StructWithMap1 struct { Map map[int]Foo11212:6exported-declaration-comment
copier_test.go:1212:6
type StructWithMap2 struct { Map map[int32]Foo21212:6max-public-structs
copier_test.go:1212:6
type StructWithMap2 struct { Map map[int32]Foo21216:6test-parallelism
copier_test.go:1216:6
func TestCopyMapOfStruct(t *testing.T) { obj1 := StructWithMap1{Map: map[int]Foo1{2: {Name: "A pure foo"}}}1226:13error-strings
copier_test.go:1226:13
if !ok || v1.Name != v2.Name { t.Errorf("Map should be copied") }1231:6test-parallelism
copier_test.go:1231:6
func TestCopyMapOfInt(t *testing.T) { map1 := map[int]int{3: 6, 4: 8}1236:11add-constant
copier_test.go:1236:11
if err != nil { t.Error("Should not raise error") }1242:13error-strings
copier_test.go:1242:13
if !ok || v1 != int(v2) { t.Errorf("Map should be copied") }1247:6cognitive-complexity
copier_test.go:1247:6
func TestCopyMapOfSliceValue(t *testing.T) { // case1: map's value is a simple slice1247:6cyclomatic-complexity
copier_test.go:1247:6
func TestCopyMapOfSliceValue(t *testing.T) { // case1: map's value is a simple slice1247:6test-parallelism
copier_test.go:1247:6
func TestCopyMapOfSliceValue(t *testing.T) { // case1: map's value is a simple slice1265:6optimize-operands-order
copier_test.go:1265:6
v2, ok := dst1[k] if !ok || len(v1) != len(v2) || k != key { t.Errorf("Map should be copied")1266:13add-constant
copier_test.go:1266:13
if !ok || len(v1) != len(v2) || k != key { t.Errorf("Map should be copied") }1266:13error-strings
copier_test.go:1266:13
if !ok || len(v1) != len(v2) || k != key { t.Errorf("Map should be copied") }1270:14error-strings
copier_test.go:1270:14
if v2[i] != value { t.Errorf("Map's slice value shoud be copied") }1276:13error-strings
copier_test.go:1276:13
if !ok || len(v1) != len(v3) { t.Errorf("Map should be copied") }1280:14error-strings
copier_test.go:1280:14
if v3[i] != value { t.Errorf("Map's slice value shoud be copied") }1296:3discarded-error-result
copier_test.go:1296:3
for i := range ms { copier.CopyWithOption(&ms[i], s, copier.Option{IgnoreEmpty: false, DeepCopy: true})1296:25range-value-address
copier_test.go:1296:25
for i := range ms { copier.CopyWithOption(&ms[i], s, copier.Option{IgnoreEmpty: false, DeepCopy: true})1299:13error-strings
copier_test.go:1299:13
if len(ms[i]) != len(s) { t.Errorf("Number of map's keys should be equal") }1303:14error-strings
copier_test.go:1303:14
if k != key1 { t.Errorf("Map's key should be copied") }1305:7optimize-operands-order
copier_test.go:1305:7
} if len(sliceMap) != len(s[key1]) || len(sliceMap) != 1 { t.Errorf("Map's slice value should be copied")1306:14error-strings
copier_test.go:1306:14
if len(sliceMap) != len(s[key1]) || len(sliceMap) != 1 { t.Errorf("Map's slice value should be copied") }1309:7optimize-operands-order
copier_test.go:1309:7
m := sliceMap[0] if len(m) != len(s[key1][0]) || len(m) != 1 { t.Errorf("Map's slice value should be copied recursively")1310:14error-strings
copier_test.go:1310:14
if len(m) != len(s[key1][0]) || len(m) != 1 { t.Errorf("Map's slice value should be copied recursively") }1314:15error-strings
copier_test.go:1314:15
if k != key2 || v != value { t.Errorf("Map's slice value should be copied recursively") }1321:6cyclomatic-complexity
copier_test.go:1321:6
func TestCopyMapOfPtrValue(t *testing.T) { intV := 31321:6test-parallelism
copier_test.go:1321:6
func TestCopyMapOfPtrValue(t *testing.T) { intV := 31338:6optimize-operands-order
copier_test.go:1338:6
v2, ok := dst1[k] if !ok || v2 == nil || v1 == nil || *v2 != *v1 || *v2 != intV { t.Errorf("Map should be copied")1338:6optimize-operands-order
copier_test.go:1338:6
v2, ok := dst1[k] if !ok || v2 == nil || v1 == nil || *v2 != *v1 || *v2 != intV { t.Errorf("Map should be copied")1338:6optimize-operands-order
copier_test.go:1338:6
v2, ok := dst1[k] if !ok || v2 == nil || v1 == nil || *v2 != *v1 || *v2 != intV { t.Errorf("Map should be copied")1339:13error-strings
copier_test.go:1339:13
if !ok || v2 == nil || v1 == nil || *v2 != *v1 || *v2 != intV { t.Errorf("Map should be copied") }1343:6optimize-operands-order
copier_test.go:1343:6
v3, ok := dst2[k] if !ok || v3 == nil || *v3 != *v1 || *v3 != intV { t.Errorf("Map should be copied")1343:6optimize-operands-order
copier_test.go:1343:6
v3, ok := dst2[k] if !ok || v3 == nil || *v3 != *v1 || *v3 != intV { t.Errorf("Map should be copied")1343:33possible-nil-dereference
copier_test.go:1343:33
v3, ok := dst2[k] if !ok || v3 == nil || *v3 != *v1 || *v3 != intV { t.Errorf("Map should be copied")1344:13error-strings
copier_test.go:1344:13
if !ok || v3 == nil || *v3 != *v1 || *v3 != intV { t.Errorf("Map should be copied") }1349:6test-parallelism
copier_test.go:1349:6
func TestCopyWithOption(t *testing.T) { from := structSameName2{D: "456", E: &someStruct{IntField: 100, UIntField: 1000}}1351:59add-constant
copier_test.go:1351:59
from := structSameName2{D: "456", E: &someStruct{IntField: 100, UIntField: 1000}} to := &structSameName1{A: "123", B: 2, C: time.Now(), D: "123", E: &someStruct{UIntField: 5000}} if err := copier.CopyWithOption(to, &from, copier.Option{IgnoreEmpty: true}); err != nil {1357:12error-strings
copier_test.go:1357:12
if to.A == from.A { t.Errorf("Field A should not be copied") } else if to.D != from.D {1359:12error-strings
copier_test.go:1359:12
} else if to.D != from.D { t.Errorf("Field D should be copied") }1363:6exported-declaration-comment
copier_test.go:1363:6
type ScannerValue struct { V int1363:6max-public-structs
copier_test.go:1363:6
type ScannerValue struct { V int1367:7unused-receiver
copier_test.go:1367:7
func (s *ScannerValue) Scan(src interface{}) error { return errors.New("I failed")1367:24exported-declaration-comment
copier_test.go:1367:24
func (s *ScannerValue) Scan(src interface{}) error { return errors.New("I failed")1367:29unused-parameter
copier_test.go:1367:29
func (s *ScannerValue) Scan(src interface{}) error { return errors.New("I failed")1367:33use-any
copier_test.go:1367:33
func (s *ScannerValue) Scan(src interface{}) error { return errors.New("I failed")1368:20error-strings
copier_test.go:1368:20
func (s *ScannerValue) Scan(src interface{}) error { return errors.New("I failed")}1371:6exported-declaration-comment
copier_test.go:1371:6
type ScannerStruct struct { V *ScannerValue1371:6max-public-structs
copier_test.go:1371:6
type ScannerStruct struct { V *ScannerValue1375:6exported-declaration-comment
copier_test.go:1375:6
type ScannerStructTo struct { V *ScannerValue1375:6max-public-structs
copier_test.go:1375:6
type ScannerStructTo struct { V *ScannerValue1379:6test-parallelism
copier_test.go:1379:6
func TestScanner(t *testing.T) { s := &ScannerStruct{1394:12error-strings
copier_test.go:1394:12
if s.V.V != s2.V.V { t.Errorf("Field V should be copied") }1398:6cognitive-complexity
copier_test.go:1398:6
func TestScanFromPtrToSqlNullable(t *testing.T) { var (1398:6cyclomatic-complexity
copier_test.go:1398:6
func TestScanFromPtrToSqlNullable(t *testing.T) { var (1398:6function-length
copier_test.go:1398:6
func TestScanFromPtrToSqlNullable(t *testing.T) { var (1398:6test-parallelism
copier_test.go:1398:6
func TestScanFromPtrToSqlNullable(t *testing.T) { var (1400:8nested-structs
copier_test.go:1400:8
var ( from struct { S string1409:6nested-structs
copier_test.go:1409:6
to struct { S sql.NullString1428:12error-strings
copier_test.go:1428:12
if from.T1.Valid || from.T2.Valid { t.Errorf("Must be not valid") }1450:2discarded-error-result
copier_test.go:1450:2
from.T1.Scan(now) from.T2.Scan(now)1451:2discarded-error-result
copier_test.go:1451:2
from.T1.Scan(now) from.T2.Scan(now)1459:12error-strings
copier_test.go:1459:12
if to.S.String != from.S { t.Errorf("Field S should be copied") }1463:12error-strings
copier_test.go:1463:12
if to.Sptr.String != *from.Sptr { t.Errorf("Field Sptr should be copied") }1466:5time-value-equality
copier_test.go:1466:5
if from.T1.Time != to.T1 { t.Errorf("Fields T1 fields should be equal")1467:12error-strings
copier_test.go:1467:12
if from.T1.Time != to.T1 { t.Errorf("Fields T1 fields should be equal") }1470:5time-value-equality
copier_test.go:1470:5
if from.T2.Time != *to.T2 { t.Errorf("Fields T2 fields should be equal")1471:12error-strings
copier_test.go:1471:12
if from.T2.Time != *to.T2 { t.Errorf("Fields T2 fields should be equal") }1475:6test-parallelism
copier_test.go:1475:6
func TestDeepCopyInterface(t *testing.T) { m := make(map[string]string)1479:12use-any
copier_test.go:1479:12
from := []interface{}{[]int{7, 8, 9}, 2, 3, m, errors.New("aaaa")} var to []interface{}1480:11use-any
copier_test.go:1480:11
from := []interface{}{[]int{7, 8, 9}, 2, 3, m, errors.New("aaaa")} var to []interface{}1482:2discarded-error-result
copier_test.go:1482:2
copier.CopyWithOption(&to, &from, copier.Option{ IgnoreEmpty: false,1487:9unchecked-type-assertion
copier_test.go:1487:9
from[0].([]int)[0] = 10 from[1] = "3"1489:9unchecked-type-assertion
copier_test.go:1489:9
from[1] = "3" from[3].(map[string]string)["a"] = "bbb"1499:10unchecked-type-assertion
copier_test.go:1499:10
if to[3].(map[string]string)["a"] != "ccc" { t.Errorf("to value failed to be deep copied")1500:12add-constant
copier_test.go:1500:12
if to[3].(map[string]string)["a"] != "ccc" { t.Errorf("to value failed to be deep copied") }1504:6test-parallelism
copier_test.go:1504:6
func TestDeepCopyTime(t *testing.T) { type embedT1 struct {1514:8nested-structs
copier_test.go:1514:8
var ( from struct { T1 time.Time1524:6nested-structs
copier_test.go:1524:6
to struct { T1 time.Time1554:12error-strings
copier_test.go:1554:12
if !to.T1.Equal(from.T1) { t.Errorf("Field T1 should be copied") }1557:12error-strings
copier_test.go:1557:12
if !to.T2.Equal(*from.T2) { t.Errorf("Field T2 should be copied") }1560:12error-strings
copier_test.go:1560:12
if !to.T3.Equal(*from.T3) { t.Errorf("Field T3 should be copied") }1563:12error-strings
copier_test.go:1563:12
if !to.T4.Equal(from.T4) { t.Errorf("Field T4 should be copied") }1566:12error-strings
copier_test.go:1566:12
if !to.T5.Equal(from.T5) { t.Errorf("Field T5 should be copied") }1569:12error-strings
copier_test.go:1569:12
if !to.T6.Equal(from.T6) { t.Errorf("Field T6 should be copied") }1573:6test-parallelism
copier_test.go:1573:6
func TestNestedPrivateData(t *testing.T) { type hasPrivate struct {1610:6test-parallelism
copier_test.go:1610:6
func TestDeepMapCopyTime(t *testing.T) { t1 := time.Now()1613:23use-any
copier_test.go:1613:23
t2 := t1.Add(time.Second) from := []map[string]interface{}{ {1619:26use-any
copier_test.go:1619:26
} to := make([]map[string]interface{}, len(from))1628:17unchecked-type-assertion
copier_test.go:1628:17
} if !to[0]["t1"].(time.Time).Equal(from[0]["t1"].(time.Time)) { t.Errorf("nested time ptr should be copied")1628:44add-constant
copier_test.go:1628:44
} if !to[0]["t1"].(time.Time).Equal(from[0]["t1"].(time.Time)) { t.Errorf("nested time ptr should be copied")1628:49unchecked-type-assertion
copier_test.go:1628:49
} if !to[0]["t1"].(time.Time).Equal(from[0]["t1"].(time.Time)) { t.Errorf("nested time ptr should be copied")1631:17unchecked-type-assertion
copier_test.go:1631:17
} if !to[0]["t2"].(*time.Time).Equal(*from[0]["t2"].(*time.Time)) { t.Errorf("nested time ptr should be copied")1631:46add-constant
copier_test.go:1631:46
} if !to[0]["t2"].(*time.Time).Equal(*from[0]["t2"].(*time.Time)) { t.Errorf("nested time ptr should be copied")1631:51unchecked-type-assertion
copier_test.go:1631:51
} if !to[0]["t2"].(*time.Time).Equal(*from[0]["t2"].(*time.Time)) { t.Errorf("nested time ptr should be copied")1636:6test-parallelism
copier_test.go:1636:6
func TestCopySimpleTime(t *testing.T) { from := time.Now()1649:6test-parallelism
copier_test.go:1649:6
func TestDeepCopySimpleTime(t *testing.T) { from := time.Now()1655:11add-constant
copier_test.go:1655:11
if err != nil { t.Error("should not error") }1662:6exported-declaration-comment
copier_test.go:1662:6
type TimeWrapper struct { time.Time1662:6max-public-structs
copier_test.go:1662:6
type TimeWrapper struct { time.Time1666:6test-parallelism
copier_test.go:1666:6
func TestDeepCopyAnonymousFieldTime(t *testing.T) { from := TimeWrapper{time.Now()}1675:12add-constant
copier_test.go:1675:12
if !from.Time.Equal(to.Time) { t.Errorf("to (%v) value should equal from (%v) value", to.Time, from.Time) }1679:6test-parallelism
copier_test.go:1679:6
func TestSqlNullFiled(t *testing.T) {1718:6test-parallelism
copier_test.go:1718:6
func TestEmptySlice(t *testing.T) { type Str1 string1719:7exported-declaration-comment
copier_test.go:1719:7
func TestEmptySlice(t *testing.T) { type Str1 string type Str2 string1720:7exported-declaration-comment
copier_test.go:1720:7
type Str1 string type Str2 string type Input1 struct {1721:7exported-declaration-comment
copier_test.go:1721:7
type Str2 string type Input1 struct { Val Str11721:7max-public-structs
copier_test.go:1721:7
type Str2 string type Input1 struct { Val Str11724:7exported-declaration-comment
copier_test.go:1724:7
} type Input2 struct { Val Str21724:7max-public-structs
copier_test.go:1724:7
} type Input2 struct { Val Str21748:6test-parallelism
copier_test.go:1748:6
func TestNestedNilPointerStruct(t *testing.T) { type destination struct {1753:7exported-declaration-comment
copier_test.go:1753:7
type NestedSource struct { ID int1753:7max-public-structs
copier_test.go:1753:7
type NestedSource struct { ID interrors.go11
1:9package-comments
errors.go:1:9
package copier6:2exported-declaration-comment
errors.go:6:2
var ( ErrInvalidCopyDestination = errors.New("copy destination must be non-nil and addressable") ErrInvalidCopyFrom = errors.New("copy from must be non-nil and addressable")6:2no-package-var
errors.go:6:2
var ( ErrInvalidCopyDestination = errors.New("copy destination must be non-nil and addressable") ErrInvalidCopyFrom = errors.New("copy from must be non-nil and addressable")7:2exported-declaration-comment
errors.go:7:2
ErrInvalidCopyDestination = errors.New("copy destination must be non-nil and addressable") ErrInvalidCopyFrom = errors.New("copy from must be non-nil and addressable") ErrMapKeyNotMatch = errors.New("map's key type doesn't match")7:2no-package-var
errors.go:7:2
ErrInvalidCopyDestination = errors.New("copy destination must be non-nil and addressable") ErrInvalidCopyFrom = errors.New("copy from must be non-nil and addressable") ErrMapKeyNotMatch = errors.New("map's key type doesn't match")8:2exported-declaration-comment
errors.go:8:2
ErrInvalidCopyFrom = errors.New("copy from must be non-nil and addressable") ErrMapKeyNotMatch = errors.New("map's key type doesn't match") ErrNotSupported = errors.New("not supported")8:2no-package-var
errors.go:8:2
ErrInvalidCopyFrom = errors.New("copy from must be non-nil and addressable") ErrMapKeyNotMatch = errors.New("map's key type doesn't match") ErrNotSupported = errors.New("not supported")9:2exported-declaration-comment
errors.go:9:2
ErrMapKeyNotMatch = errors.New("map's key type doesn't match") ErrNotSupported = errors.New("not supported") ErrFieldNameTagStartNotUpperCase = errors.New("copier field name tag must be start upper case")9:2no-package-var
errors.go:9:2
ErrMapKeyNotMatch = errors.New("map's key type doesn't match") ErrNotSupported = errors.New("not supported") ErrFieldNameTagStartNotUpperCase = errors.New("copier field name tag must be start upper case")10:2exported-declaration-comment
errors.go:10:2
ErrNotSupported = errors.New("not supported") ErrFieldNameTagStartNotUpperCase = errors.New("copier field name tag must be start upper case"))10:2no-package-var
errors.go:10:2
ErrNotSupported = errors.New("not supported") ErrFieldNameTagStartNotUpperCase = errors.New("copier field name tag must be start upper case"))