Skip to content

Commit

Permalink
Merge pull request #83 from rahulkhairwar/refactory-test-copy-non-empty
Browse files Browse the repository at this point in the history
Renamed TestCopyNonEmpty() to TestCopyWithOption(), and added godoc
  • Loading branch information
jinzhu authored Feb 22, 2021
2 parents 1618fbe + 1108297 commit db116d0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
// value is not copied. The program will return an error instead.
tagNoPanic

// Ignore a destation field from being copied to.
// Ignore a destination field from being copied to.
tagIgnore

// Denotes that the value as been copied
Expand All @@ -26,6 +26,8 @@ const (

// Option sets copy options
type Option struct {
// setting this value to true will ignore copying zero values of all the fields, including bools, as well as a
// struct having all it's fields set to their zero values respectively (see IsZero() in reflect/value.go)
IgnoreEmpty bool
DeepCopy bool
}
Expand Down Expand Up @@ -451,7 +453,7 @@ func checkBitFlags(flagsList map[string]uint8) (err error) {
if flags&hasCopied == 0 {
switch {
case flags&tagMust != 0 && flags&tagNoPanic != 0:
err = fmt.Errorf("Field %s has must tag but was not copied", name)
err = fmt.Errorf("field %s has must tag but was not copied", name)
return
case flags&(tagMust) != 0:
panic(fmt.Sprintf("Field %s has must tag but was not copied", name))
Expand Down
2 changes: 1 addition & 1 deletion copier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ func TestCopyMapOfInt(t *testing.T) {
}
}

func TestCopyNonEmpty(t *testing.T) {
func TestCopyWithOption(t *testing.T) {
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 {
Expand Down

0 comments on commit db116d0

Please sign in to comment.