• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D28-Jan-201812 32

.travis.ymlH A D28-Jan-2018192 1410

CHANGES.mdH A D28-Jan-2018166 105

LICENSEH A D28-Jan-20181 KiB2217

README.mdH A D28-Jan-20181.7 KiB5238

deep.goH A D28-Jan-20188.1 KiB353242

deep_test.goH A D28-Jan-201814.7 KiB822734

README.md

1# Deep Variable Equality for Humans
2
3[![Go Report Card](https://goreportcard.com/badge/github.com/go-test/deep)](https://goreportcard.com/report/github.com/go-test/deep) [![Build Status](https://travis-ci.org/go-test/deep.svg?branch=master)](https://travis-ci.org/go-test/deep) [![Coverage Status](https://coveralls.io/repos/github/go-test/deep/badge.svg?branch=master)](https://coveralls.io/github/go-test/deep?branch=master) [![GoDoc](https://godoc.org/github.com/go-test/deep?status.svg)](https://godoc.org/github.com/go-test/deep)
4
5This package provides a single function: `deep.Equal`. It's like [reflect.DeepEqual](http://golang.org/pkg/reflect/#DeepEqual) but much friendlier to humans (or any sentient being) for two reason:
6
7* `deep.Equal` returns a list of differences
8* `deep.Equal` does not compare unexported fields (by default)
9
10`reflect.DeepEqual` is good (like all things Golang!), but it's a game of [Hunt the Wumpus](https://en.wikipedia.org/wiki/Hunt_the_Wumpus). For large maps, slices, and structs, finding the difference is difficult.
11
12`deep.Equal` doesn't play games with you, it lists the differences:
13
14```go
15package main_test
16
17import (
18	"testing"
19	"github.com/go-test/deep"
20)
21
22type T struct {
23	Name    string
24	Numbers []float64
25}
26
27func TestDeepEqual(t *testing.T) {
28	// Can you spot the difference?
29	t1 := T{
30		Name:    "Isabella",
31		Numbers: []float64{1.13459, 2.29343, 3.010100010},
32	}
33	t2 := T{
34		Name:    "Isabella",
35		Numbers: []float64{1.13459, 2.29843, 3.010100010},
36	}
37
38	if diff := deep.Equal(t1, t2); diff != nil {
39		t.Error(diff)
40	}
41}
42```
43
44
45```
46$ go test
47--- FAIL: TestDeepEqual (0.00s)
48        main_test.go:25: [Numbers.slice[1]: 2.29343 != 2.29843]
49```
50
51The difference is in `Numbers.slice[1]`: the two values aren't equal using Go `==`.
52