Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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