Skip to content
Open
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
14 changes: 14 additions & 0 deletions diff_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ func (d *Differ) structValues(t string, path []string, a reflect.Value) error {
return ErrTypeMismatch
}

// empty struct
// add to changelog and return
if a.NumField() == 0 {
var from, to interface{}

from, to = nil, exportInterface(a)
if t == DELETE {
from, to = to, nil
}

d.cl.Add(t, path, from, to)
return nil
}

x := reflect.New(a.Type()).Elem()

for i := 0; i < a.NumField(); i++ {
Expand Down
14 changes: 14 additions & 0 deletions diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,20 @@ func TestDiff(t *testing.T) {
diff.Changelog{},
nil,
},
{
"map-empty-struct-value",
map[string]struct{}{
"one": {},
},
map[string]struct{}{
"two": {},
},
diff.Changelog{
diff.Change{Type: diff.DELETE, Path: []string{"one"}, From: struct{}{}, To: nil},
diff.Change{Type: diff.CREATE, Path: []string{"two"}, From: nil, To: struct{}{}},
},
nil,
},
}

for _, tc := range cases {
Expand Down