Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: pkg/unittest/lib/src/spread_args_helper.dart

Issue 187653007: Revert https://code.google.com/p/dart/source/detail?r=33346 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/pkg.status ('k') | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
9 /** Simulates spread arguments using named arguments. */ 3 /** Simulates spread arguments using named arguments. */
10 // 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
11 // arguments (if still applicable). 5 // arguments (if still applicable).
12 class _SpreadArgsHelper implements Function { 6 class _SpreadArgsHelper {
13 final Function callback; 7 final Function callback;
14 final int minExpectedCalls; 8 final int minExpectedCalls;
15 final int maxExpectedCalls; 9 final int maxExpectedCalls;
16 final Function isDone; 10 final Function isDone;
17 final String id; 11 final String id;
18 int actualCalls = 0; 12 int actualCalls = 0;
19 final TestCase testCase; 13 final TestCase testCase;
20 bool complete; 14 bool complete;
21 15
22 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected, 16 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected,
23 String id, {bool isDone()}) 17 Function isDone, String id)
24 : this.callback = callback, 18 : this.callback = callback,
25 minExpectedCalls = minExpected, 19 minExpectedCalls = minExpected,
26 maxExpectedCalls = (maxExpected == 0 && minExpected > 0) 20 maxExpectedCalls = (maxExpected == 0 && minExpected > 0)
27 ? minExpected 21 ? minExpected
28 : maxExpected, 22 : maxExpected,
29 this.isDone = isDone, 23 this.isDone = isDone,
30 this.testCase = currentTestCase, 24 this.testCase = currentTestCase,
31 this.id = _makeCallbackId(id, callback) { 25 this.id = _makeCallbackId(id, callback) {
32 ensureInitialized(); 26 ensureInitialized();
33 if (testCase == null) { 27 if (testCase == null) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return; 83 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return;
90 if (isDone != null && !isDone()) return; 84 if (isDone != null && !isDone()) return;
91 85
92 // Mark this callback as complete and remove it from the testcase 86 // Mark this callback as complete and remove it from the testcase
93 // oustanding callback count; if that hits zero the testcase is done. 87 // oustanding callback count; if that hits zero the testcase is done.
94 complete = true; 88 complete = true;
95 testCase._markCallbackComplete(); 89 testCase._markCallbackComplete();
96 } 90 }
97 } 91 }
98 92
99 call([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER, 93 invoke0() {
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
105 return _guardAsync( 94 return _guardAsync(
106 () { 95 () {
107 if (shouldCallBack()) { 96 if (shouldCallBack()) {
108 return Function.apply(callback, args); 97 return callback();
109 } 98 }
110 }, 99 },
111 after, testCase); 100 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);
112 } 121 }
113 122
114 _guardAsync(Function tryBody, Function finallyBody, TestCase testCase) { 123 _guardAsync(Function tryBody, Function finallyBody, TestCase testCase) {
115 assert(testCase != null); 124 assert(testCase != null);
116 try { 125 try {
117 return tryBody(); 126 return tryBody();
118 } catch (e, trace) { 127 } catch (e, trace) {
119 _registerException(testCase, e, trace); 128 _registerException(testCase, e, trace);
120 } finally { 129 } finally {
121 if (finallyBody != null) finallyBody(); 130 if (finallyBody != null) finallyBody();
122 } 131 }
123 } 132 }
124 } 133 }
OLDNEW
« no previous file with comments | « pkg/pkg.status ('k') | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698