Index: packages/unittest/lib/src/expected_function.dart |
diff --git a/packages/unittest/lib/src/expected_function.dart b/packages/unittest/lib/src/expected_function.dart |
index 7373c7550829fdb9b010a9a71de3ef77bf9f65a4..5a92d14a4e466f7a91fc7a1ec9e9c82b1ce50b35 100644 |
--- a/packages/unittest/lib/src/expected_function.dart |
+++ b/packages/unittest/lib/src/expected_function.dart |
@@ -30,7 +30,7 @@ typedef bool _IsDoneCallback(); |
/// |
/// The wrapper function is accessible via [func]. It supports up to six |
/// optional and/or required positional arguments, but no named arguments. |
-class ExpectedFunction { |
+class ExpectedFunction<T> { |
/// The wrapped callback. |
final Function _callback; |
@@ -125,43 +125,60 @@ class ExpectedFunction { |
/// Returns a function that has the same number of positional arguments as the |
/// wrapped function (up to a total of 6). |
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; |
+ 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; |
throw new ArgumentError( |
'The wrapped function has more than 6 required arguments'); |
} |
+ T max0() => max6(); |
+ |
// This indirection is critical. It ensures the returned function has an |
// argument count of zero. |
- _max0() => _max6(); |
- |
- _max1([a0 = _PLACEHOLDER]) => _max6(a0); |
- |
- _max2([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER]) => _max6(a0, a1); |
- |
- _max3([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER, a2 = _PLACEHOLDER]) => |
- _max6(a0, a1, a2); |
- |
- _max4([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER, a2 = _PLACEHOLDER, |
- a3 = _PLACEHOLDER]) => _max6(a0, a1, a2, a3); |
- |
- _max5([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER, a2 = _PLACEHOLDER, |
- a3 = _PLACEHOLDER, a4 = _PLACEHOLDER]) => _max6(a0, a1, a2, a3, a4); |
- |
- _max6([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER, a2 = _PLACEHOLDER, |
- a3 = _PLACEHOLDER, a4 = _PLACEHOLDER, a5 = _PLACEHOLDER]) => |
+ T max1([Object a0 = _PLACEHOLDER]) => max6(a0); |
+ |
+ T max2([Object a0 = _PLACEHOLDER, Object a1 = _PLACEHOLDER]) => max6(a0, a1); |
+ |
+ T max3( |
+ [Object a0 = _PLACEHOLDER, |
+ Object a1 = _PLACEHOLDER, |
+ Object a2 = _PLACEHOLDER]) => |
+ max6(a0, a1, a2); |
+ |
+ T max4( |
+ [Object a0 = _PLACEHOLDER, |
+ Object a1 = _PLACEHOLDER, |
+ Object a2 = _PLACEHOLDER, |
+ Object a3 = _PLACEHOLDER]) => |
+ max6(a0, a1, a2, a3); |
+ |
+ T max5( |
+ [Object a0 = _PLACEHOLDER, |
+ Object a1 = _PLACEHOLDER, |
+ Object a2 = _PLACEHOLDER, |
+ Object a3 = _PLACEHOLDER, |
+ Object a4 = _PLACEHOLDER]) => |
+ max6(a0, a1, a2, a3, a4); |
+ |
+ T max6( |
+ [Object a0 = _PLACEHOLDER, |
+ Object a1 = _PLACEHOLDER, |
+ Object a2 = _PLACEHOLDER, |
+ Object a3 = _PLACEHOLDER, |
+ Object a4 = _PLACEHOLDER, |
+ Object a5 = _PLACEHOLDER]) => |
_run([a0, a1, a2, a3, a4, a5].where((a) => a != _PLACEHOLDER)); |
/// Runs the wrapped function with [args] and returns its return value. |
/// |
/// This will pass any errors on to [_testCase] and return `null`. |
- _run(Iterable args) { |
+ T _run(Iterable args) { |
try { |
_actualCalls++; |
if (_testCase.isComplete) { |
@@ -177,10 +194,10 @@ class ExpectedFunction { |
return null; |
} else if (_maxExpectedCalls >= 0 && _actualCalls > _maxExpectedCalls) { |
throw new TestFailure('Callback ${_id}called more times than expected ' |
- '($_maxExpectedCalls).$_reason'); |
+ '($_maxExpectedCalls).$_reason'); |
} |
- return Function.apply(_callback, args.toList()); |
+ return Function.apply(_callback, args.toList()) as T; |
} catch (error, stackTrace) { |
_testCase.registerException(error, stackTrace); |
return null; |