-
Notifications
You must be signed in to change notification settings - Fork 157
Open
Labels
enhancementNew feature or requestNew feature or request
Description
In PR golang/mock#546 we got a matcher that ignores the order of a slice or array. Sometimes the order can't be controlled properly it makes sense to have this matcher. But it is only capable of ignoring the order if the struct is of type slice or array, and not nested.
I would propose to add a matcher that will return true for unordered nested structs as well. Example unit test:
func TestOrderlessMatcher(t *testing.T) {
testCases := []struct {
expected interface{}
value interface{}
matches bool
}{
{
struct{ List []string }{List: []string{"Value1", "Value2"}},
struct{ List []string }{List: []string{"Value2", "Value1"}},
true,
},
}
for i, testCase := range testCases {
t.Run(fmt.Sprintf("Test #%d", i), func(t *testing.T) {
assert := assert.New(t)
m := matchers.NewOrderlessMatcher(testCase.expected)
assert.Equal(testCase.matches, m.Matches(testCase.value))
})
}
}Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request