You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
This is an understandable request. We are currently looking into whether or not the form of this feature should be a new top-level matcher or an option or change in the behavior of the existing InAnyOrder matcher.
@sebastianbuechler Can you clarify further about the matcher requirements ?
Can the struct have more fields which are not slice/array ? When you say nesting then do you mean any complex nested structure ?
eg:
typeAstruct {
Field1 []string{}
// some customer type which can have slice/array as it's own fieldsField2B// some primitive type fieldsField3int// slice/array of some non primitive typeField4 []C
}
typeBstruct {
Field1 []D
}
typeCstruct {
Field1int
}
typeDstruct {
Field1string
}
// so are you expecting structs mentioned below should match ?A1:=A{
Field1: { "1", "2" },
Field2: B{
Field1: []D{
{ Field1: "a" }
{ Field2: "b" }
}
},
Field3: 4,
Field4: []C{
{ Field1: 1 }
{ Field1: 2 }
}
}
A2:=A{
Field1: { "2", "1" },
Field2: B{
Field1: []D{
{ Field1: "b" }
{ Field2: "a" }
}
},
Field3: 4,
Field4: []C{
{ Field1: 1 }
{ Field1: 2 }
}
}
One can always write a custom matcher for complex object but matching complex structs by ignoring order of slice in them can be helpful as many times using a slice is more appropriate to keep a collection. But slices have property to match only if all elements are equal with order , users end up writing customer matchers.
So having a matcher for complex structure which just works by ignoring any ordering in slice/array fields can be helpful if provided by library.
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:
The text was updated successfully, but these errors were encountered: