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..5adf21f16e89633799bb356ac5cc5e9bd094868c 100644 |
--- a/pkg/unittest/lib/src/spread_args_helper.dart |
+++ b/pkg/unittest/lib/src/spread_args_helper.dart |
@@ -1,5 +1,11 @@ |
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). |
@@ -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,44 @@ class _SpreadArgsHelper { |
} |
} |
- invoke0() { |
- return _guardAsync( |
- () { |
- if (shouldCallBack()) { |
- return callback(); |
- } |
- }, |
- after, testCase); |
- } |
+ //TODO(kevmoo) DOCUMENT! |
kevmoo
2014/03/11 03:46:47
I'm going to document this quick before I commit
|
+ Function get func { |
+ if (callback is _Func6) return _max6; |
+ if (callback is _Func5) return _max5; |
+ if (callback is _Func4) return _max4; |
+ if (callback is _Func3) return _max3; |
+ if (callback is _Func2) return _max2; |
+ if (callback is _Func1) return _max1; |
+ if (callback is _Func0) return _max0; |
- invoke1(arg1) { |
- return _guardAsync( |
- () { |
- if (shouldCallBack()) { |
- return callback(arg1); |
- } |
- }, |
- after, testCase); |
+ throw new ArgumentError( |
+ 'The callback argument has more than 6 required arguments'); |
} |
- invoke2(arg1, arg2) { |
+ _max0() => _max6(); |
+ |
+ _max1([a0 = _PLACE_HOLDER]) => _max6(a0); |
+ |
+ _max2([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER]) => _max6(a0, a1); |
+ |
+ _max3([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER]) => |
+ _max6(a0, a1, a2); |
+ |
+ _max4([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER, |
+ a3 = _PLACE_HOLDER]) => _max6(a0, a1, a2, a3); |
+ |
+ _max5([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER, |
+ a3 = _PLACE_HOLDER, a4 = _PLACE_HOLDER]) => _max6(a0, a1, a2, a3, a4); |
+ |
+ _max6([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER, |
+ a3 = _PLACE_HOLDER, a4 = _PLACE_HOLDER, a5 = _PLACE_HOLDER]) { |
+ var args = [a0, a1, a2, a3, a4, a5]; |
+ args.removeWhere((a) => a == _PLACE_HOLDER); |
+ |
return _guardAsync( |
() { |
if (shouldCallBack()) { |
- return callback(arg1, arg2); |
+ return Function.apply(callback, args); |
} |
}, |
after, testCase); |
@@ -131,3 +150,11 @@ class _SpreadArgsHelper { |
} |
} |
} |
+ |
+typedef _Func0(); |
+typedef _Func1(a); |
+typedef _Func2(a, b); |
+typedef _Func3(a, b, c); |
+typedef _Func4(a, b, c, d); |
+typedef _Func5(a, b, c, d, e); |
+typedef _Func6(a, b, c, d, e, f); |