Consider empty/nil arrays as matching elements

pull/487/head^2
Emil Stanchev 2017-08-25 21:04:03 +02:00 committed by Ernesto Jiménez
parent 6f306a68e1
commit 51464dae67
2 changed files with 4 additions and 7 deletions

View File

@ -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
}

View File

@ -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")
}