Skip to content

romnn/deepequal

Repository files navigation

deepequal

GitHub GoDoc Test Coverage

This package is based on the original reflect.DeepEqual, but adds useful error messages pointing out where and how the compared values differ.

import "github.com/romnn/deepequal"

Example

// 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

About

Deep equality with useful error messages

Topics

Resources

License

Stars

Watchers

Forks

Languages