Skip to content

Commit

Permalink
Merge pull request #100 from victorkryukov/issue-99-contains-complex-…
Browse files Browse the repository at this point in the history
…types

Fix #99: Contains doesn't work for complex types
  • Loading branch information
Mat Ryer committed Nov 18, 2014
2 parents d6577e0 + d355634 commit 8ce79b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func includeElement(list interface{}, element interface{}) (ok, found bool) {
}

for i := 0; i < listValue.Len(); i++ {
if listValue.Index(i).Interface() == element {
if ObjectsAreEqual(listValue.Index(i).Interface(), element) {
return true, true
}
}
Expand Down
17 changes: 16 additions & 1 deletion assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,20 @@ func TestNotEqual(t *testing.T) {
}
}

type A struct {
Name, Value string
}

func TestContains(t *testing.T) {

mockT := new(testing.T)
list := []string{"Foo", "Bar"}
complexList := []*A{
&A{"b", "c"},
&A{"d", "e"},
&A{"g", "h"},
&A{"j", "k"},
}

if !Contains(mockT, "Hello World", "Hello") {
t.Error("Contains should return true: \"Hello World\" contains \"Hello\"")
Expand All @@ -232,7 +242,12 @@ func TestContains(t *testing.T) {
if Contains(mockT, list, "Salut") {
t.Error("Contains should return false: \"[\"Foo\", \"Bar\"]\" does not contain \"Salut\"")
}

if !Contains(mockT, complexList, &A{"g", "h"}) {
t.Error("Contains should return true: complexList contains {\"g\", \"h\"}")
}
if Contains(mockT, complexList, &A{"g", "e"}) {
t.Error("Contains should return false: complexList contains {\"g\", \"e\"}")
}
}

func TestNotContains(t *testing.T) {
Expand Down

0 comments on commit 8ce79b9

Please sign in to comment.