Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: pkg/unittest/mock.dart

Issue 11231074: Change signature of noSuchMethod to take an InvocationMirror. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * The error formatter for mocking is a bit different from the default one 6 * The error formatter for mocking is a bit different from the default one
7 * for unit testing; instead of the third argument being a 'reason' 7 * for unit testing; instead of the third argument being a 'reason'
8 * it is instead a [signature] describing the method signature filter 8 * it is instead a [signature] describing the method signature filter
9 * that was used to select the logs that were verified. 9 * that was used to select the logs that were verified.
10 */ 10 */
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 if (!_behaviors.containsKey(key)) { 1261 if (!_behaviors.containsKey(key)) {
1262 Behavior b = new Behavior(logFilter); 1262 Behavior b = new Behavior(logFilter);
1263 _behaviors[key] = b; 1263 _behaviors[key] = b;
1264 return b; 1264 return b;
1265 } else { 1265 } else {
1266 return _behaviors[key]; 1266 return _behaviors[key];
1267 } 1267 }
1268 } 1268 }
1269 1269
1270 /** 1270 /**
1271 * This is the handler for method calls. We loo through the list 1271 * This is the handler for method calls. We loo through the list
floitsch 2012/10/23 13:04:35 loop
Lasse Reichstein Nielsen 2012/10/25 06:17:35 Good catch.
1272 * of [Behavior]s, and find the first match that still has return 1272 * of [Behavior]s, and find the first match that still has return
1273 * values available, and then do the action specified by that 1273 * values available, and then do the action specified by that
1274 * return value. If we find no [Behavior] to apply an exception is 1274 * return value. If we find no [Behavior] to apply an exception is
1275 * thrown. 1275 * thrown.
1276 */ 1276 */
1277 noSuchMethod(String method, List args) { 1277 noSuchMethod(InvocationMirror invocation) {
1278 if (method.startsWith('get:')) { 1278 String method = invocation.getterName;
1279 method = 'get ${method.substring(4)}'; 1279 if (invocation.isGetter) {
1280 method = 'get $method';
1280 } 1281 }
1282 List args = invocation.positionalArguments;
1283 // TODO: Handle named arguments too.
1281 bool matchedMethodName = false; 1284 bool matchedMethodName = false;
1282 MatchState matchState = new MatchState(); 1285 MatchState matchState = new MatchState();
1283 for (String k in _behaviors.getKeys()) { 1286 for (String k in _behaviors.getKeys()) {
1284 Behavior b = _behaviors[k]; 1287 Behavior b = _behaviors[k];
1285 if (b.matcher.nameFilter.matches(method, matchState)) { 1288 if (b.matcher.nameFilter.matches(method, matchState)) {
1286 matchedMethodName = true; 1289 matchedMethodName = true;
1287 } 1290 }
1288 if (b.matches(method, args)) { 1291 if (b.matches(method, args)) {
1289 List actions = b.actions; 1292 List actions = b.actions;
1290 if (actions == null || actions.length == 0) { 1293 if (actions == null || actions.length == 0) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 } 1453 }
1451 } 1454 }
1452 } 1455 }
1453 1456
1454 /** Clear both logs and behavior. */ 1457 /** Clear both logs and behavior. */
1455 void reset() { 1458 void reset() {
1456 resetBehavior(); 1459 resetBehavior();
1457 clearLogs(); 1460 clearLogs();
1458 } 1461 }
1459 } 1462 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698