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 part of unittest; | 5 part of unittest; |
6 | 6 |
7 /** | 7 /** |
8 * The error formatter for mocking is a bit different from the default one | 8 * The error formatter for mocking is a bit different from the default one |
9 * for unit testing; instead of the third argument being a 'reason' | 9 * for unit testing; instead of the third argument being a 'reason' |
10 * it is instead a [signature] describing the method signature filter | 10 * it is instead a [signature] describing the method signature filter |
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 } | 1269 } |
1270 } | 1270 } |
1271 | 1271 |
1272 /** | 1272 /** |
1273 * This is the handler for method calls. We loo through the list | 1273 * This is the handler for method calls. We loo through the list |
1274 * of [Behavior]s, and find the first match that still has return | 1274 * of [Behavior]s, and find the first match that still has return |
1275 * values available, and then do the action specified by that | 1275 * values available, and then do the action specified by that |
1276 * return value. If we find no [Behavior] to apply an exception is | 1276 * return value. If we find no [Behavior] to apply an exception is |
1277 * thrown. | 1277 * thrown. |
1278 */ | 1278 */ |
1279 noSuchMethod(String method, List args) { | 1279 noSuchMethod(InvocationMirror invocation) { |
1280 if (method.startsWith('get:')) { | 1280 String method = invocation.memberName; |
1281 method = 'get ${method.substring(4)}'; | 1281 // Remove this when InvocationMirror works correctly. |
| 1282 if (method.startsWith("get:")) method = method.substring(4); |
| 1283 |
| 1284 if (invocation.isGetter) { |
| 1285 method = 'get $method'; |
1282 } | 1286 } |
| 1287 List args = invocation.positionalArguments; |
| 1288 // TODO: Handle named arguments too. |
| 1289 |
1283 bool matchedMethodName = false; | 1290 bool matchedMethodName = false; |
1284 MatchState matchState = new MatchState(); | 1291 MatchState matchState = new MatchState(); |
1285 for (String k in _behaviors.keys) { | 1292 for (String k in _behaviors.keys) { |
1286 Behavior b = _behaviors[k]; | 1293 Behavior b = _behaviors[k]; |
1287 if (b.matcher.nameFilter.matches(method, matchState)) { | 1294 if (b.matcher.nameFilter.matches(method, matchState)) { |
1288 matchedMethodName = true; | 1295 matchedMethodName = true; |
1289 } | 1296 } |
1290 if (b.matches(method, args)) { | 1297 if (b.matches(method, args)) { |
1291 List actions = b.actions; | 1298 List actions = b.actions; |
1292 if (actions == null || actions.length == 0) { | 1299 if (actions == null || actions.length == 0) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 } | 1459 } |
1453 } | 1460 } |
1454 } | 1461 } |
1455 | 1462 |
1456 /** Clear both logs and behavior. */ | 1463 /** Clear both logs and behavior. */ |
1457 void reset() { | 1464 void reset() { |
1458 resetBehavior(); | 1465 resetBehavior(); |
1459 clearLogs(); | 1466 clearLogs(); |
1460 } | 1467 } |
1461 } | 1468 } |
OLD | NEW |