@@ -297,27 +297,52 @@ func (m *Mock) findExpectedCall(method string, arguments ...interface{}) (int, *
297
297
return - 1 , expectedCall
298
298
}
299
299
300
+ type matchCandidate struct {
301
+ call * Call
302
+ mismatch string
303
+ diffCount int
304
+ }
305
+
306
+ func (c matchCandidate ) isBetterMatchThan (other matchCandidate ) bool {
307
+ if c .call == nil {
308
+ return false
309
+ }
310
+ if other .call == nil {
311
+ return true
312
+ }
313
+
314
+ if c .diffCount > other .diffCount {
315
+ return false
316
+ }
317
+ if c .diffCount < other .diffCount {
318
+ return true
319
+ }
320
+
321
+ if c .call .Repeatability > other .call .Repeatability {
322
+ return true
323
+ }
324
+ return false
325
+ }
326
+
300
327
func (m * Mock ) findClosestCall (method string , arguments ... interface {}) (* Call , string ) {
301
- var diffCount int
302
- var repeatability int
303
- var closestCall * Call
304
- var err string
328
+ var bestMatch matchCandidate
305
329
306
330
for _ , call := range m .expectedCalls () {
307
331
if call .Method == method {
308
332
309
333
errInfo , tempDiffCount := call .Arguments .Diff (arguments )
310
- if tempDiffCount < diffCount || diffCount == 0 || (tempDiffCount == diffCount && call .Repeatability > repeatability ) {
311
- diffCount = tempDiffCount
312
- repeatability = call .Repeatability
313
- closestCall = call
314
- err = errInfo
334
+ tempCandidate := matchCandidate {
335
+ call : call ,
336
+ mismatch : errInfo ,
337
+ diffCount : tempDiffCount ,
338
+ }
339
+ if tempCandidate .isBetterMatchThan (bestMatch ) {
340
+ bestMatch = tempCandidate
315
341
}
316
-
317
342
}
318
343
}
319
344
320
- return closestCall , err
345
+ return bestMatch . call , bestMatch . mismatch
321
346
}
322
347
323
348
func callString (method string , arguments Arguments , includeArgumentValues bool ) string {
0 commit comments