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

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

Issue 187653007: Revert https://code.google.com/p/dart/source/detail?r=33346 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 | « pkg/unittest/lib/src/spread_args_helper.dart ('k') | pkg/unittest/test/missing_tick_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/unittest.dart
===================================================================
--- pkg/unittest/lib/unittest.dart (revision 33351)
+++ pkg/unittest/lib/unittest.dart (working copy)
@@ -325,9 +325,23 @@
* bound.
*/
Function expectAsync(Function callback,
- {int count: 1, int max: 0, String id}) =>
- new _SpreadArgsHelper(callback, count, max, id);
+ {int count: 1, int max: 0, String id}) {
+ var minArgs = _minArgs(callback);
+ switch(minArgs) {
+ case 0:
+ return new _SpreadArgsHelper(callback, count, max, null, id).invoke0;
+ case 1:
+ return new _SpreadArgsHelper(callback, count, max, null, id).invoke1;
+ case 2:
+ return new _SpreadArgsHelper(callback, count, max, null, id).invoke2;
+ default:
+ // _minArgs throws an argument exception if the arg count is > 2.
+ // this is just for paranoia
+ throw new StateError('Should never get here');
+ }
+}
+
/**
* *Deprecated*
*
@@ -368,9 +382,23 @@
* identify the callback in error messages (for example if it is called
* after the test case is complete).
*/
-Function expectAsyncUntil(Function callback, bool isDone(), {String id}) =>
- new _SpreadArgsHelper(callback, 0, -1, id, isDone: isDone);
+Function expectAsyncUntil(Function callback, Function isDone, {String id}) {
+ var minArgs = _minArgs(callback);
+ switch(minArgs) {
+ case 0:
+ return new _SpreadArgsHelper(callback, 0, -1, isDone, id).invoke0;
+ case 1:
+ return new _SpreadArgsHelper(callback, 0, -1, isDone, id).invoke1;
+ case 2:
+ return new _SpreadArgsHelper(callback, 0, -1, isDone, id).invoke2;
+ default:
+ // _minArgs throws an argument exception if the arg count is > 2.
+ // this is just for paranoia
+ throw new StateError('Should never get here');
+ }
+}
+
/**
* *Deprecated*
*
@@ -742,3 +770,18 @@
return frame.package != 'unittest' || frame.member != 'TestCase._runTest';
})).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore);
}
+
+typedef _Func0();
+typedef _Func1(a);
+typedef _Func2(a, b);
+
+/**
+ * Throws an [ArgumentError] if the callback has more than 2 required arguments.
+ */
+int _minArgs(Function callback) {
+ if (callback is _Func0) return 0;
+ if (callback is _Func1) return 1;
+ if (callback is _Func2) return 2;
+ throw new ArgumentError(
+ 'The callback argument has more than 2 required arguments.');
+}
« no previous file with comments | « pkg/unittest/lib/src/spread_args_helper.dart ('k') | pkg/unittest/test/missing_tick_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698