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(InvocationMirror invocation) { | 1279 noSuchMethod(String method, List args) { |
1280 String method = invocation.methodName; | 1280 if (method.startsWith('get:')) { |
1281 // Remove this when InvocationMirror works correctly. | 1281 method = 'get ${method.substring(4)}'; |
1282 if (method.startsWith("get:")) method = method.substring(4); | |
1283 | |
1284 if (invocation.isGetter) { | |
1285 method = 'get $method'; | |
1286 } | 1282 } |
1287 List args = invocation.positionalArguments; | |
1288 // TODO: Handle named arguments too. | |
1289 | |
1290 bool matchedMethodName = false; | 1283 bool matchedMethodName = false; |
1291 MatchState matchState = new MatchState(); | 1284 MatchState matchState = new MatchState(); |
1292 for (String k in _behaviors.keys) { | 1285 for (String k in _behaviors.keys) { |
1293 Behavior b = _behaviors[k]; | 1286 Behavior b = _behaviors[k]; |
1294 if (b.matcher.nameFilter.matches(method, matchState)) { | 1287 if (b.matcher.nameFilter.matches(method, matchState)) { |
1295 matchedMethodName = true; | 1288 matchedMethodName = true; |
1296 } | 1289 } |
1297 if (b.matches(method, args)) { | 1290 if (b.matches(method, args)) { |
1298 List actions = b.actions; | 1291 List actions = b.actions; |
1299 if (actions == null || actions.length == 0) { | 1292 if (actions == null || actions.length == 0) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 } | 1452 } |
1460 } | 1453 } |
1461 } | 1454 } |
1462 | 1455 |
1463 /** Clear both logs and behavior. */ | 1456 /** Clear both logs and behavior. */ |
1464 void reset() { | 1457 void reset() { |
1465 resetBehavior(); | 1458 resetBehavior(); |
1466 clearLogs(); | 1459 clearLogs(); |
1467 } | 1460 } |
1468 } | 1461 } |
OLD | NEW |