OLD | NEW |
1 part of unittest; | 1 part of unittest; |
2 | 2 |
| 3 const _PLACE_HOLDER = const _ArgPlaceHolder(); |
| 4 |
| 5 class _ArgPlaceHolder { |
| 6 const _ArgPlaceHolder(); |
| 7 } |
| 8 |
3 /** Simulates spread arguments using named arguments. */ | 9 /** Simulates spread arguments using named arguments. */ |
4 // TODO(sigmund): remove this class and simply use a closure with named | 10 // TODO(sigmund): remove this class and simply use a closure with named |
5 // arguments (if still applicable). | 11 // arguments (if still applicable). |
6 class _SpreadArgsHelper { | 12 class _SpreadArgsHelper implements Function { |
7 final Function callback; | 13 final Function callback; |
8 final int minExpectedCalls; | 14 final int minExpectedCalls; |
9 final int maxExpectedCalls; | 15 final int maxExpectedCalls; |
10 final Function isDone; | 16 final Function isDone; |
11 final String id; | 17 final String id; |
12 int actualCalls = 0; | 18 int actualCalls = 0; |
13 final TestCase testCase; | 19 final TestCase testCase; |
14 bool complete; | 20 bool complete; |
15 | 21 |
16 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected, | 22 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected, |
17 Function isDone, String id) | 23 String id, {bool isDone()}) |
18 : this.callback = callback, | 24 : this.callback = callback, |
19 minExpectedCalls = minExpected, | 25 minExpectedCalls = minExpected, |
20 maxExpectedCalls = (maxExpected == 0 && minExpected > 0) | 26 maxExpectedCalls = (maxExpected == 0 && minExpected > 0) |
21 ? minExpected | 27 ? minExpected |
22 : maxExpected, | 28 : maxExpected, |
23 this.isDone = isDone, | 29 this.isDone = isDone, |
24 this.testCase = currentTestCase, | 30 this.testCase = currentTestCase, |
25 this.id = _makeCallbackId(id, callback) { | 31 this.id = _makeCallbackId(id, callback) { |
26 ensureInitialized(); | 32 ensureInitialized(); |
27 if (testCase == null) { | 33 if (testCase == null) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return; | 89 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return; |
84 if (isDone != null && !isDone()) return; | 90 if (isDone != null && !isDone()) return; |
85 | 91 |
86 // Mark this callback as complete and remove it from the testcase | 92 // Mark this callback as complete and remove it from the testcase |
87 // oustanding callback count; if that hits zero the testcase is done. | 93 // oustanding callback count; if that hits zero the testcase is done. |
88 complete = true; | 94 complete = true; |
89 testCase._markCallbackComplete(); | 95 testCase._markCallbackComplete(); |
90 } | 96 } |
91 } | 97 } |
92 | 98 |
93 invoke0() { | 99 call([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER, |
| 100 a3 = _PLACE_HOLDER, a4 = _PLACE_HOLDER, a5 = _PLACE_HOLDER]) { |
| 101 |
| 102 var args = [a0, a1, a2, a3, a4, a5]; |
| 103 args.removeWhere((a) => a == _PLACE_HOLDER); |
| 104 |
94 return _guardAsync( | 105 return _guardAsync( |
95 () { | 106 () { |
96 if (shouldCallBack()) { | 107 if (shouldCallBack()) { |
97 return callback(); | 108 return Function.apply(callback, args); |
98 } | 109 } |
99 }, | 110 }, |
100 after, testCase); | 111 after, testCase); |
101 } | |
102 | |
103 invoke1(arg1) { | |
104 return _guardAsync( | |
105 () { | |
106 if (shouldCallBack()) { | |
107 return callback(arg1); | |
108 } | |
109 }, | |
110 after, testCase); | |
111 } | |
112 | |
113 invoke2(arg1, arg2) { | |
114 return _guardAsync( | |
115 () { | |
116 if (shouldCallBack()) { | |
117 return callback(arg1, arg2); | |
118 } | |
119 }, | |
120 after, testCase); | |
121 } | 112 } |
122 | 113 |
123 _guardAsync(Function tryBody, Function finallyBody, TestCase testCase) { | 114 _guardAsync(Function tryBody, Function finallyBody, TestCase testCase) { |
124 assert(testCase != null); | 115 assert(testCase != null); |
125 try { | 116 try { |
126 return tryBody(); | 117 return tryBody(); |
127 } catch (e, trace) { | 118 } catch (e, trace) { |
128 _registerException(testCase, e, trace); | 119 _registerException(testCase, e, trace); |
129 } finally { | 120 } finally { |
130 if (finallyBody != null) finallyBody(); | 121 if (finallyBody != null) finallyBody(); |
131 } | 122 } |
132 } | 123 } |
133 } | 124 } |
OLD | NEW |