MCPcopy Create free account
hub / github.com/chain/txvm / WithSort

Function WithSort

testutil/deepequal.go:160–185  ·  view source on GitHub ↗
(path []string, less func(a, b interface{}) bool)

Source from the content-addressed store, hash-verified

158}
159
160func WithSort(path []string, less func(a, b interface{}) bool) func(a, b interface{}) {
161 return func(a, b interface{}) {
162 for _, p := range path {
163 mapA, ok := a.(map[string]interface{})
164 if !ok {
165 return
166 }
167 a = mapA[p]
168 mapB, ok := b.(map[string]interface{})
169 if !ok {
170 return
171 }
172 b = mapB[p]
173 }
174 aSlice, ok := a.([]interface{})
175 if !ok {
176 return
177 }
178 bSlice, ok := b.([]interface{})
179 if !ok {
180 return
181 }
182 sort.Slice(aSlice, func(i, j int) bool { return less(aSlice[i], aSlice[j]) })
183 sort.Slice(bSlice, func(i, j int) bool { return less(bSlice[i], bSlice[j]) })
184 }
185}
186
187func IsJSONSubset(t testing.TB, a, b []byte, opts ...func(a, b interface{})) bool {
188 var aval, bval interface{}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected