https://github.com/romnn/deepequal
Deep equality with useful error messages
https://github.com/romnn/deepequal
assertions deep-equal golang reflection testing
Last synced: 4 months ago
JSON representation
Deep equality with useful error messages
- Host: GitHub
- URL: https://github.com/romnn/deepequal
- Owner: romnn
- License: mit
- Created: 2020-03-04T12:26:42.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-10-22T15:06:33.000Z (about 3 years ago)
- Last Synced: 2025-03-27T16:02:48.239Z (10 months ago)
- Topics: assertions, deep-equal, golang, reflection, testing
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## deepequal
[](https://github.com/romnn/deepequal)
[](https://godoc.org/github.com/romnn/deepequal)
[](https://codecov.io/gh/romnn/deepequal)
This package is based on the original `reflect.DeepEqual`, but adds useful error messages pointing out where and how the compared values differ.
```go
import "github.com/romnn/deepequal"
```
#### Example
```go
// examples/example1/main.go
package main
import (
"log"
"github.com/romnn/deepequal"
)
type person struct {
Name string
Age int
Hobbies []string
}
func main() {
a := person{Name: "A", Age: 22, Hobbies: []string{"Surfing"}}
b := person{Name: "A", Age: 22, Hobbies: []string{}}
if equal, err := deepequal.DeepEqual(a, a); !equal {
log.Fatalf("not equal: %v", err)
}
if equal, err := deepequal.DeepEqual(a, b); equal {
log.Fatalf("unexpected equal: %v", err)
}
}
```
For more examples see the `examples/` directory.
#### Acknowledgement
- Check out the vanilla `reflect` implementation at [golang.org/src/reflect/deepequal.go](https://golang.org/src/reflect/deepequal.go)