| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * A simple mocking/spy library. | 6 * A simple mocking/spy library. |
| 7 * | 7 * |
| 8 * ## Installing ## | 8 * ## Installing ## |
| 9 * | 9 * |
| 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` | 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 281 } |
| 282 d.add(')'); | 282 d.add(')'); |
| 283 return d.toString(); | 283 return d.toString(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 /** | 286 /** |
| 287 * Given a [method] name and list of [arguments], return true | 287 * Given a [method] name and list of [arguments], return true |
| 288 * if it matches this [CallMatcher. | 288 * if it matches this [CallMatcher. |
| 289 */ | 289 */ |
| 290 bool matches(String method, List arguments) { | 290 bool matches(String method, List arguments) { |
| 291 var matchState = new MatchState(); | 291 var matchState = {}; |
| 292 if (!nameFilter.matches(method, matchState)) { | 292 if (!nameFilter.matches(method, matchState)) { |
| 293 return false; | 293 return false; |
| 294 } | 294 } |
| 295 var numArgs = (arguments == null) ? 0 : arguments.length; | 295 var numArgs = (arguments == null) ? 0 : arguments.length; |
| 296 if (numArgs < argMatchers.length) { | 296 if (numArgs < argMatchers.length) { |
| 297 throw new Exception("Less arguments than matchers for $method."); | 297 throw new Exception("Less arguments than matchers for $method."); |
| 298 } | 298 } |
| 299 for (var i = 0; i < argMatchers.length; i++) { | 299 for (var i = 0; i < argMatchers.length; i++) { |
| 300 if (!argMatchers[i].matches(arguments[i], matchState)) { | 300 if (!argMatchers[i].matches(arguments[i], matchState)) { |
| 301 return false; | 301 return false; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 Matcher actionMatcher, | 534 Matcher actionMatcher, |
| 535 bool destructive = false]) { | 535 bool destructive = false]) { |
| 536 if (mockNameFilter == null) { | 536 if (mockNameFilter == null) { |
| 537 mockNameFilter = anything; | 537 mockNameFilter = anything; |
| 538 } else { | 538 } else { |
| 539 mockNameFilter = wrapMatcher(mockNameFilter); | 539 mockNameFilter = wrapMatcher(mockNameFilter); |
| 540 } | 540 } |
| 541 Function entryFilter = _makePredicate(logFilter); | 541 Function entryFilter = _makePredicate(logFilter); |
| 542 String filterName = _qualifiedName(mockNameFilter, logFilter.toString()); | 542 String filterName = _qualifiedName(mockNameFilter, logFilter.toString()); |
| 543 LogEntryList rtn = new LogEntryList(filterName); | 543 LogEntryList rtn = new LogEntryList(filterName); |
| 544 MatchState matchState = new MatchState(); | 544 var matchState = {}; |
| 545 for (var i = 0; i < logs.length; i++) { | 545 for (var i = 0; i < logs.length; i++) { |
| 546 LogEntry entry = logs[i]; | 546 LogEntry entry = logs[i]; |
| 547 if (mockNameFilter.matches(entry.mockName, matchState) && | 547 if (mockNameFilter.matches(entry.mockName, matchState) && |
| 548 entryFilter(entry)) { | 548 entryFilter(entry)) { |
| 549 if (actionMatcher == null || | 549 if (actionMatcher == null || |
| 550 actionMatcher.matches(entry, matchState)) { | 550 actionMatcher.matches(entry, matchState)) { |
| 551 rtn.add(entry); | 551 rtn.add(entry); |
| 552 if (destructive) { | 552 if (destructive) { |
| 553 int startIndex = i--; | 553 int startIndex = i--; |
| 554 logs.removeRange(startIndex, startIndex + 1); | 554 logs.removeRange(startIndex, startIndex + 1); |
| (...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 } | 1544 } |
| 1545 } | 1545 } |
| 1546 } | 1546 } |
| 1547 | 1547 |
| 1548 /** Clear both logs and behavior. */ | 1548 /** Clear both logs and behavior. */ |
| 1549 void reset() { | 1549 void reset() { |
| 1550 resetBehavior(); | 1550 resetBehavior(); |
| 1551 clearLogs(); | 1551 clearLogs(); |
| 1552 } | 1552 } |
| 1553 } | 1553 } |
| OLD | NEW |