Skip to content

Commit

Permalink
renamed presence to set marker
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Jun 8, 2023
1 parent 1eba909 commit 473baa0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions differ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestNewDiffer(t *testing.T) {
{Type: "update", Path: &Path{Kind: 1, Path: &Path{}, Name: "ID"}, From: 1, To: 2},
}},
},
{description: "diff with field presence check",
{description: "diff with field setMarker check",
from: &PresRecord{ID: 20, Name: "abc", Bar: 23,
Has: &PresRecordHas{
Name: true,
Expand All @@ -258,7 +258,7 @@ func TestNewDiffer(t *testing.T) {
},
},

options: []Option{WithPresence(true)},
options: []Option{WithSetMarker(true)},
expect: &ChangeLog{Changes: []*Change{
{Type: "update", Path: &Path{Kind: PathKinField, Path: &Path{}, Name: "ID"}, From: 20, To: 21},
{Type: "update", Path: &Path{Kind: PathKinField, Path: &Path{}, Name: "Name"}, From: "abc", To: "xyz"},
Expand Down
6 changes: 3 additions & 3 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package godiff
type ConfigOption func(config *Config)

type Options struct {
presence bool
setMarker bool
shallow bool
nullifyEmpty *bool
depth int
Expand Down Expand Up @@ -35,9 +35,9 @@ func WithTag(tag *Tag) ConfigOption {
}
}

func WithPresence(f bool) Option {
func WithSetMarker(f bool) Option {
return func(options *Options) {
options.presence = f
options.setMarker = f
}
}

Expand Down
4 changes: 2 additions & 2 deletions struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *structDiffer) diff(changeLog *ChangeLog, path *Path, from, to interface
changeLog.AddError(path.Field(field.name), err)
continue
}
if options.presence {
if options.setMarker {
hasPtr := toPtr
if s.marker.CanUseHolder(toPtr) {
hasPtr = fromPtr
Expand All @@ -43,7 +43,7 @@ func (s *structDiffer) diff(changeLog *ChangeLog, path *Path, from, to interface
continue //skip diff, to/dest is not set
}
if field.tag != nil && field.tag.PresenceMarker {
continue //do not compare presence tag
continue //do not compare setMarker tag
}
}

Expand Down

0 comments on commit 473baa0

Please sign in to comment.