Skip to content

Commit

Permalink
fix: use reflect.DeepEqual to check equality of incomparable structs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
korylprince authored Feb 17, 2022
1 parent cfe7d56 commit 63fa881
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func isEmptyValue(v reflect.Value) bool {
case reflect.Interface, reflect.Ptr:
return v.IsNil()
case reflect.Struct:
return v.Interface() == reflect.Zero(v.Type()).Interface()
return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface())
}
return false
}
5 changes: 3 additions & 2 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var indentRefOmit = `<?xml version="1.0" encoding="UTF-8"?>

type testStruct struct {
UnusedString string `plist:"unused-string"`
UnusedByte []byte `plist:"unused-byte,omitempty"`
}

var encodeTests = []struct {
Expand Down Expand Up @@ -208,7 +209,7 @@ func TestIndent(t *testing.T) {
Size: 4 * 1048576 * 1024 * 1024,
DiskImageBundleType: "com.apple.diskimage.sparsebundle",
BackingStoreVersion: 1,
Unused: testStruct{"unused"},
Unused: testStruct{UnusedString: "unused"},
}
b, err := MarshalIndent(sparseBundleHeader, " ")
if err != nil {
Expand All @@ -235,7 +236,7 @@ func TestOmitNotEmpty(t *testing.T) {
Size: 4 * 1048576 * 1024 * 1024,
DiskImageBundleType: "com.apple.diskimage.sparsebundle",
BackingStoreVersion: 1,
Unused: testStruct{"unused"},
Unused: testStruct{UnusedString: "unused"},
}
b, err := MarshalIndent(sparseBundleHeader, " ")
if err != nil {
Expand Down

0 comments on commit 63fa881

Please sign in to comment.