An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

## deepequal

[![GitHub](https://img.shields.io/github/license/romnn/deepequal)](https://github.com/romnn/deepequal)
[![GoDoc](https://godoc.org/github.com/romnn/deepequal?status.svg)](https://godoc.org/github.com/romnn/deepequal)
[![Test Coverage](https://codecov.io/gh/romnn/deepequal/branch/master/graph/badge.svg)](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)