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(); |
15 | 16 |
16 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected, | 17 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected, |
17 Function isDone, String id) | 18 Function isDone, String id) |
18 : this.callback = callback, | 19 : this.callback = callback, |
19 minExpectedCalls = minExpected, | 20 minExpectedCalls = minExpected, |
20 maxExpectedCalls = (maxExpected == 0 && minExpected > 0) | 21 maxExpectedCalls = (maxExpected == 0 && minExpected > 0) |
21 ? minExpected | 22 ? minExpected |
22 : maxExpected, | 23 : maxExpected, |
23 this.isDone = isDone, | 24 this.isDone = isDone, |
24 this.testCase = currentTestCase, | 25 this.testCase = currentTestCase, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 113 |
113 invoke2(arg1, arg2) { | 114 invoke2(arg1, arg2) { |
114 return _guardAsync( | 115 return _guardAsync( |
115 () { | 116 () { |
116 if (shouldCallBack()) { | 117 if (shouldCallBack()) { |
117 return callback(arg1, arg2); | 118 return callback(arg1, arg2); |
118 } | 119 } |
119 }, | 120 }, |
120 after, testCase); | 121 after, testCase); |
121 } | 122 } |
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 } | |
133 } | 123 } |
OLD | NEW |