r3labs / diff

A library for diffing golang structures
Mozilla Public License 2.0
895 stars 84 forks source link

fix: report create/delete differences on empty structs #101

Open aexvir opened 1 year ago

aexvir commented 1 year ago

closes #100

to address this issue I've added an eager return inside structValues that, if the struct has no fields, appends a single entry to the changelog for the struct itself; also added tests for this

wants, got := Set{"one": {}}, Set{} 
diff.Diff(wants, got)

diff.Changelog{
    diff.Change{
        Type: diff.DELETE,
        Path: []string{"one"},
        From: struct{}{},
        To: nil,
    },
}