From 51464dae670079c4a78e1cacb6d29e650bbedb51 Mon Sep 17 00:00:00 2001 From: Emil Stanchev Date: Fri, 25 Aug 2017 21:04:03 +0200 Subject: [PATCH] Consider empty/nil arrays as matching elements --- assert/assertions.go | 5 +---- assert/assertions_test.go | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 3a80032..3f1f6f7 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -736,10 +736,7 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) // // Returns whether the assertion was successful (true) or not (false). func ElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface{}) (ok bool) { - if listA == nil || listB == nil { - if listA != listB { - return Fail(t, fmt.Sprintf("only one value is nil"), msgAndArgs...) - } + if isEmpty(listA) && isEmpty(listB) { return true } diff --git a/assert/assertions_test.go b/assert/assertions_test.go index ca56a57..8c64edf 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -648,10 +648,10 @@ func TestElementsMatch(t *testing.T) { if !ElementsMatch(mockT, [3]string{"hello", "hello", "world"}, [3]string{"hello", "world", "hello"}) { t.Error("ElementsMatch should return true") } - - if ElementsMatch(mockT, []int{}, nil) { - t.Error("ElementsMatch should return false") + if !ElementsMatch(mockT, []int{}, nil) { + t.Error("ElementsMatch should return true") } + if ElementsMatch(mockT, []int{1}, []int{1, 1}) { t.Error("ElementsMatch should return false") }