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

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

Issue 187323003: pkg/unittest: much cleaner support for arbitrary args in expectAsync functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: tests for too many args 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/pkg.status ('k') | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/src/spread_args_helper.dart
diff --git a/pkg/unittest/lib/src/spread_args_helper.dart b/pkg/unittest/lib/src/spread_args_helper.dart
index 41411b93780f4f2d68f4f6941dad6186b668f4f4..5d555722ce28555a710ebf8ff67c9b45a72586f9 100644
--- a/pkg/unittest/lib/src/spread_args_helper.dart
+++ b/pkg/unittest/lib/src/spread_args_helper.dart
@@ -1,9 +1,15 @@
part of unittest;
+const _PLACE_HOLDER = const _ArgPlaceHolder();
+
+class _ArgPlaceHolder {
+ const _ArgPlaceHolder();
+}
+
/** Simulates spread arguments using named arguments. */
// TODO(sigmund): remove this class and simply use a closure with named
// arguments (if still applicable).
-class _SpreadArgsHelper {
+class _SpreadArgsHelper implements Function {
final Function callback;
final int minExpectedCalls;
final int maxExpectedCalls;
@@ -14,7 +20,7 @@ class _SpreadArgsHelper {
bool complete;
_SpreadArgsHelper(Function callback, int minExpected, int maxExpected,
- Function isDone, String id)
+ String id, {bool isDone()})
: this.callback = callback,
minExpectedCalls = minExpected,
maxExpectedCalls = (maxExpected == 0 && minExpected > 0)
@@ -90,31 +96,16 @@ class _SpreadArgsHelper {
}
}
- invoke0() {
- return _guardAsync(
- () {
- if (shouldCallBack()) {
- return callback();
- }
- },
- after, testCase);
- }
+ call([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER,
+ a3 = _PLACE_HOLDER, a4 = _PLACE_HOLDER, a5 = _PLACE_HOLDER]) {
- invoke1(arg1) {
- return _guardAsync(
- () {
- if (shouldCallBack()) {
- return callback(arg1);
- }
- },
- after, testCase);
- }
+ var args = [a0, a1, a2, a3, a4, a5];
+ args.removeWhere((a) => a == _PLACE_HOLDER);
- invoke2(arg1, arg2) {
return _guardAsync(
() {
if (shouldCallBack()) {
- return callback(arg1, arg2);
+ return Function.apply(callback, args);
}
},
after, testCase);
« no previous file with comments | « pkg/pkg.status ('k') | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698