OLD | NEW |
1 part of unittest; | 1 part of unittest; |
2 | 2 |
3 /** Simulates spread arguments using named arguments. */ | 3 /** Simulates spread arguments using named arguments. */ |
4 // TODO(sigmund): remove this class and simply use a closure with named | 4 // TODO(sigmund): remove this class and simply use a closure with named |
5 // arguments (if still applicable). | 5 // arguments (if still applicable). |
6 class _SpreadArgsHelper { | 6 class _SpreadArgsHelper { |
7 final Function callback; | 7 final Function callback; |
8 final int minExpectedCalls; | 8 final int minExpectedCalls; |
9 final int maxExpectedCalls; | 9 final int maxExpectedCalls; |
10 final Function isDone; | 10 final Function isDone; |
11 final String id; | 11 final String id; |
12 int actualCalls = 0; | 12 int actualCalls = 0; |
13 final TestCase testCase; | 13 final TestCase testCase; |
14 bool complete; | 14 bool complete; |
15 static const sentinel = const _Sentinel(); | |
16 | 15 |
17 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected, | 16 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected, |
18 Function isDone, String id) | 17 Function isDone, String id) |
19 : this.callback = callback, | 18 : this.callback = callback, |
20 minExpectedCalls = minExpected, | 19 minExpectedCalls = minExpected, |
21 maxExpectedCalls = (maxExpected == 0 && minExpected > 0) | 20 maxExpectedCalls = (maxExpected == 0 && minExpected > 0) |
22 ? minExpected | 21 ? minExpected |
23 : maxExpected, | 22 : maxExpected, |
24 this.isDone = isDone, | 23 this.isDone = isDone, |
25 this.testCase = currentTestCase, | 24 this.testCase = currentTestCase, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 112 |
114 invoke2(arg1, arg2) { | 113 invoke2(arg1, arg2) { |
115 return _guardAsync( | 114 return _guardAsync( |
116 () { | 115 () { |
117 if (shouldCallBack()) { | 116 if (shouldCallBack()) { |
118 return callback(arg1, arg2); | 117 return callback(arg1, arg2); |
119 } | 118 } |
120 }, | 119 }, |
121 after, testCase); | 120 after, testCase); |
122 } | 121 } |
| 122 |
| 123 _guardAsync(Function tryBody, Function finallyBody, TestCase testCase) { |
| 124 assert(testCase != null); |
| 125 try { |
| 126 return tryBody(); |
| 127 } catch (e, trace) { |
| 128 _registerException(testCase, e, trace); |
| 129 } finally { |
| 130 if (finallyBody != null) finallyBody(); |
| 131 } |
| 132 } |
123 } | 133 } |
OLD | NEW |