Need help with deep?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

go-test
533 Stars 37 Forks MIT License 87 Commits 7 Opened issues

Description

Golang deep variable equality test that returns human-readable differences

Services available

!
?

Need anything else?

Contributors list

# 63,558
non-blo...
mariadb
MySQL
SQL
39 commits
# 47,513
Erlang
beagleb...
Raspber...
Arduino
4 commits
# 258,713
Shell
languag...
Sublime...
lsp
4 commits
# 8,082
Go
golang
prometh...
gRPC
2 commits
# 272,427
thesaur...
golang
Kuberne...
C++
2 commits
# 3,944
Terrafo...
Go
terrafo...
golang
2 commits
# 453,831
sdl2
C++
golang
2 commits
# 241,833
golang
embedde...
cocoapo...
C
2 commits
# 304,962
Shell
C
golang
1 commit
# 412,506
Go
golang
1 commit

Deep Variable Equality for Humans

Go Report Card Build Status Coverage Status GoDoc

This package provides a single function:

deep.Equal
. It's like reflect.DeepEqual but much friendlier to humans (or any sentient being) for two reason:
  • deep.Equal
    returns a list of differences
  • deep.Equal
    does not compare unexported fields (by default)

reflect.DeepEqual
is good (like all things Golang!), but it's a game of Hunt the Wumpus. For large maps, slices, and structs, finding the difference is difficult.

deep.Equal
doesn't play games with you, it lists the differences:
package main_test

import ( "testing" "github.com/go-test/deep" )

type T struct { Name string Numbers []float64 }

func TestDeepEqual(t *testing.T) { // Can you spot the difference? t1 := T{ Name: "Isabella", Numbers: []float64{1.13459, 2.29343, 3.010100010}, } t2 := T{ Name: "Isabella", Numbers: []float64{1.13459, 2.29843, 3.010100010}, }

if diff := deep.Equal(t1, t2); diff != nil {
    t.Error(diff)
}

}

$ go test
--- FAIL: TestDeepEqual (0.00s)
        main_test.go:25: [Numbers.slice[1]: 2.29343 != 2.29843]

The difference is in

Numbers.slice[1]
: the two values aren't equal using Go
==
.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.