Make semantic deep equal public feature

* Use semantic deep equal when validating
* More test cases for deep equal
This commit is contained in:
Daniel Smith
2015-01-05 13:38:39 -08:00
parent 7f49ba0dcf
commit 0d628b3bff
4 changed files with 45 additions and 16 deletions

View File

@@ -22,15 +22,28 @@ import (
func TestEqualities(t *testing.T) {
e := Equalities{}
type Bar struct {
X int
}
type Baz struct {
Y Bar
}
err := e.AddFuncs(
func(a, b int) bool {
return a+1 == b
},
func(a, b Bar) bool {
return a.X*10 == b.X
},
)
if err != nil {
t.Fatalf("Unexpected: %v", err)
}
type Foo struct {
X int
}
table := []struct {
a, b interface{}
equal bool
@@ -38,6 +51,10 @@ func TestEqualities(t *testing.T) {
{1, 2, true},
{2, 1, false},
{"foo", "foo", true},
{Foo{1}, Foo{2}, true},
{Bar{1}, Bar{10}, true},
{&Bar{1}, &Bar{10}, true},
{Baz{Bar{1}}, Baz{Bar{10}}, true},
{map[string]int{"foo": 1}, map[string]int{"foo": 2}, true},
{map[string]int{}, map[string]int(nil), true},
{[]int{}, []int(nil), true},