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

Unified Diff: pkg/unittest/lib/mock.dart

Issue 12212003: Some fixes/improvements to getter/setter mocking. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/unittest/test/mock_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/mock.dart
===================================================================
--- pkg/unittest/lib/mock.dart (revision 18082)
+++ pkg/unittest/lib/mock.dart (working copy)
@@ -24,6 +24,9 @@
* [thenCall] and [alwaysCall] allow you to proxy mocked methods, chaining
* to some other implementation. This provides a way to implement 'spies'.
*
+ * For getters and setters, use "get foo" and "set foo"-style arguments
+ * to [callsTo].
+ *
* You can disable logging for a particular [Behavior] easily:
*
* m.when(callsTo('bar')).logging = false;
@@ -269,6 +272,10 @@
* Returns a [CallMatcher] for the specified signature. [method] can be
* null to match anything, or a literal [String], a predicate [Function],
* or a [Matcher]. The various arguments can be scalar values or [Matcher]s.
+ * To match getters and setters, use "get " and "set " prefixes on the names.
+ * For example, for a property "foo", you could use "get foo" and "set foo"
+ * as literal string arguments to callsTo to match the getter and setter
+ * of "foo".
*/
CallMatcher callsTo([method,
arg0 = _noArg,
@@ -1286,9 +1293,12 @@
var args = invocation.positionalArguments;
if (invocation.isGetter) {
method = 'get $method';
- } else if (method.startsWith('get:')) {
- // TODO(gram): Remove this when VM handles the isGetter version above.
- method = 'get ${method.substring(4)}';
+ } else if (invocation.isSetter) {
+ method = 'set $method';
+ // Remove the trailing '='.
+ if (method[method.length-1] == '=') {
+ method = method.substring(0, method.length - 1);
+ }
}
bool matchedMethodName = false;
MatchState matchState = new MatchState();
« no previous file with comments | « no previous file | pkg/unittest/test/mock_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698