MCPcopy Create free account
hub / github.com/stretchr/testify / assertOpts

Function assertOpts

mock/mock.go:1204–1265  ·  view source on GitHub ↗
(expected, actual interface{})

Source from the content-addressed store, hash-verified

1202}
1203
1204func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) {
1205 expectedOpts := reflect.ValueOf(expected)
1206 actualOpts := reflect.ValueOf(actual)
1207
1208 var expectedFuncs []*runtime.Func
1209 var expectedNames []string
1210 for i := 0; i < expectedOpts.Len(); i++ {
1211 f := runtimeFunc(expectedOpts.Index(i).Interface())
1212 expectedFuncs = append(expectedFuncs, f)
1213 expectedNames = append(expectedNames, funcName(f))
1214 }
1215 var actualFuncs []*runtime.Func
1216 var actualNames []string
1217 for i := 0; i < actualOpts.Len(); i++ {
1218 f := runtimeFunc(actualOpts.Index(i).Interface())
1219 actualFuncs = append(actualFuncs, f)
1220 actualNames = append(actualNames, funcName(f))
1221 }
1222
1223 if expectedOpts.Len() != actualOpts.Len() {
1224 expectedFmt = fmt.Sprintf("%v", expectedNames)
1225 actualFmt = fmt.Sprintf("%v", actualNames)
1226 return
1227 }
1228
1229 for i := 0; i < expectedOpts.Len(); i++ {
1230 if !isFuncSame(expectedFuncs[i], actualFuncs[i]) {
1231 expectedFmt = expectedNames[i]
1232 actualFmt = actualNames[i]
1233 return
1234 }
1235
1236 expectedOpt := expectedOpts.Index(i).Interface()
1237 actualOpt := actualOpts.Index(i).Interface()
1238
1239 ot := reflect.TypeOf(expectedOpt)
1240 var expectedValues []reflect.Value
1241 var actualValues []reflect.Value
1242 if ot.NumIn() == 0 {
1243 return
1244 }
1245
1246 for i := 0; i < ot.NumIn(); i++ {
1247 vt := ot.In(i).Elem()
1248 expectedValues = append(expectedValues, reflect.New(vt))
1249 actualValues = append(actualValues, reflect.New(vt))
1250 }
1251
1252 reflect.ValueOf(expectedOpt).Call(expectedValues)
1253 reflect.ValueOf(actualOpt).Call(actualValues)
1254
1255 for i := 0; i < ot.NumIn(); i++ {
1256 if expectedArg, actualArg := expectedValues[i].Interface(), actualValues[i].Interface(); !assert.ObjectsAreEqual(expectedArg, actualArg) {
1257 expectedFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], expectedArg, expectedArg)
1258 actualFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], actualArg, actualArg)
1259 return
1260 }
1261 }

Callers 1

DiffMethod · 0.85

Calls 6

ObjectsAreEqualFunction · 0.92
runtimeFuncFunction · 0.85
funcNameFunction · 0.85
isFuncSameFunction · 0.85
CallMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected