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

Side by Side Diff: pkg/analysis_server/test/analysis_notification_occurrences_test.dart

Issue 406583002: Use futures uniformly rather than a mix of futures and CPS in tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.domain.analysis.notification.occurrences; 5 library test.domain.analysis.notification.occurrences;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/computer/computer_occurrences.dart'; 10 import 'package:analysis_server/src/computer/computer_occurrences.dart';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 } 76 }
77 } 77 }
78 if (exists == true) { 78 if (exists == true) {
79 fail( 79 fail(
80 'Expected to find (offset=$offset; length=$length) in\n' 80 'Expected to find (offset=$offset; length=$length) in\n'
81 '${occurrencesList.join('\n')}'); 81 '${occurrencesList.join('\n')}');
82 } 82 }
83 } 83 }
84 84
85 Future prepareOccurrences(then()) { 85 Future prepareOccurrences() {
86 addAnalysisSubscription(AnalysisService.OCCURRENCES, testFile); 86 addAnalysisSubscription(AnalysisService.OCCURRENCES, testFile);
87 return waitForTasksFinished().then((_) { 87 return waitForTasksFinished();
88 then();
89 });
90 } 88 }
91 89
92 void processNotification(Notification notification) { 90 void processNotification(Notification notification) {
93 if (notification.event == ANALYSIS_OCCURRENCES) { 91 if (notification.event == ANALYSIS_OCCURRENCES) {
94 String file = notification.getParameter(FILE); 92 String file = notification.getParameter(FILE);
95 if (file == testFile) { 93 if (file == testFile) {
96 occurrencesList = <Occurrences>[]; 94 occurrencesList = <Occurrences>[];
97 List<Map<String, Object>> jsonList = 95 List<Map<String, Object>> jsonList =
98 notification.getParameter(OCCURRENCES); 96 notification.getParameter(OCCURRENCES);
99 for (Map<String, Object> json in jsonList) { 97 for (Map<String, Object> json in jsonList) {
(...skipping 10 matching lines...) Expand all
110 } 108 }
111 109
112 test_afterAnalysis() { 110 test_afterAnalysis() {
113 addTestFile(''' 111 addTestFile('''
114 main() { 112 main() {
115 var vvv = 42; 113 var vvv = 42;
116 print(vvv); 114 print(vvv);
117 } 115 }
118 '''); 116 ''');
119 return waitForTasksFinished().then((_) { 117 return waitForTasksFinished().then((_) {
120 return prepareOccurrences(() { 118 return prepareOccurrences().then((_) {
121 assertHasRegion('vvv ='); 119 assertHasRegion('vvv =');
122 expect(testOccurences.element.kind, ElementKind.LOCAL_VARIABLE); 120 expect(testOccurences.element.kind, ElementKind.LOCAL_VARIABLE);
123 expect(testOccurences.element.name, 'vvv'); 121 expect(testOccurences.element.name, 'vvv');
124 assertHasOffset('vvv = 42'); 122 assertHasOffset('vvv = 42');
125 assertHasOffset('vvv);'); 123 assertHasOffset('vvv);');
126 }); 124 });
127 }); 125 });
128 } 126 }
129 127
130 test_classType() { 128 test_classType() {
131 addTestFile(''' 129 addTestFile('''
132 main() { 130 main() {
133 int a = 1; 131 int a = 1;
134 int b = 2; 132 int b = 2;
135 int c = 3; 133 int c = 3;
136 } 134 }
137 int VVV = 4; 135 int VVV = 4;
138 '''); 136 ''');
139 return prepareOccurrences(() { 137 return prepareOccurrences().then((_) {
140 assertHasRegion('int a'); 138 assertHasRegion('int a');
141 expect(testOccurences.element.kind, ElementKind.CLASS); 139 expect(testOccurences.element.kind, ElementKind.CLASS);
142 expect(testOccurences.element.name, 'int'); 140 expect(testOccurences.element.name, 'int');
143 assertHasOffset('int a'); 141 assertHasOffset('int a');
144 assertHasOffset('int b'); 142 assertHasOffset('int b');
145 assertHasOffset('int c'); 143 assertHasOffset('int c');
146 assertHasOffset('int VVV'); 144 assertHasOffset('int VVV');
147 }); 145 });
148 } 146 }
149 147
150 test_field() { 148 test_field() {
151 addTestFile(''' 149 addTestFile('''
152 class A { 150 class A {
153 int fff; 151 int fff;
154 A(this.fff); // constructor 152 A(this.fff); // constructor
155 main() { 153 main() {
156 fff = 42; 154 fff = 42;
157 print(fff); // print 155 print(fff); // print
158 } 156 }
159 } 157 }
160 '''); 158 ''');
161 return prepareOccurrences(() { 159 return prepareOccurrences().then((_) {
162 assertHasRegion('fff;'); 160 assertHasRegion('fff;');
163 expect(testOccurences.element.kind, ElementKind.FIELD); 161 expect(testOccurences.element.kind, ElementKind.FIELD);
164 assertHasOffset('fff); // constructor'); 162 assertHasOffset('fff); // constructor');
165 assertHasOffset('fff = 42;'); 163 assertHasOffset('fff = 42;');
166 assertHasOffset('fff); // print'); 164 assertHasOffset('fff); // print');
167 }); 165 });
168 } 166 }
169 167
170 test_localVariable() { 168 test_localVariable() {
171 addTestFile(''' 169 addTestFile('''
172 main() { 170 main() {
173 var vvv = 42; 171 var vvv = 42;
174 vvv += 5; 172 vvv += 5;
175 print(vvv); 173 print(vvv);
176 } 174 }
177 '''); 175 ''');
178 return prepareOccurrences(() { 176 return prepareOccurrences().then((_) {
179 assertHasRegion('vvv ='); 177 assertHasRegion('vvv =');
180 expect(testOccurences.element.kind, ElementKind.LOCAL_VARIABLE); 178 expect(testOccurences.element.kind, ElementKind.LOCAL_VARIABLE);
181 expect(testOccurences.element.name, 'vvv'); 179 expect(testOccurences.element.name, 'vvv');
182 assertHasOffset('vvv = 42'); 180 assertHasOffset('vvv = 42');
183 assertHasOffset('vvv += 5'); 181 assertHasOffset('vvv += 5');
184 assertHasOffset('vvv);'); 182 assertHasOffset('vvv);');
185 }); 183 });
186 } 184 }
187 185
188 test_memberField() { 186 test_memberField() {
189 addTestFile(''' 187 addTestFile('''
190 class A<T> { 188 class A<T> {
191 T fff; 189 T fff;
192 } 190 }
193 main() { 191 main() {
194 var a = new A<int>(); 192 var a = new A<int>();
195 var b = new A<String>(); 193 var b = new A<String>();
196 a.fff = 1; 194 a.fff = 1;
197 b.fff = 2; 195 b.fff = 2;
198 } 196 }
199 '''); 197 ''');
200 return prepareOccurrences(() { 198 return prepareOccurrences().then((_) {
201 assertHasRegion('fff;'); 199 assertHasRegion('fff;');
202 expect(testOccurences.element.kind, ElementKind.FIELD); 200 expect(testOccurences.element.kind, ElementKind.FIELD);
203 assertHasOffset('fff = 1;'); 201 assertHasOffset('fff = 1;');
204 assertHasOffset('fff = 2;'); 202 assertHasOffset('fff = 2;');
205 }); 203 });
206 } 204 }
207 205
208 test_memberMethod() { 206 test_memberMethod() {
209 addTestFile(''' 207 addTestFile('''
210 class A<T> { 208 class A<T> {
211 T mmm() {} 209 T mmm() {}
212 } 210 }
213 main() { 211 main() {
214 var a = new A<int>(); 212 var a = new A<int>();
215 var b = new A<String>(); 213 var b = new A<String>();
216 a.mmm(); // a 214 a.mmm(); // a
217 b.mmm(); // b 215 b.mmm(); // b
218 } 216 }
219 '''); 217 ''');
220 return prepareOccurrences(() { 218 return prepareOccurrences().then((_) {
221 assertHasRegion('mmm() {}'); 219 assertHasRegion('mmm() {}');
222 expect(testOccurences.element.kind, ElementKind.METHOD); 220 expect(testOccurences.element.kind, ElementKind.METHOD);
223 assertHasOffset('mmm(); // a'); 221 assertHasOffset('mmm(); // a');
224 assertHasOffset('mmm(); // b'); 222 assertHasOffset('mmm(); // b');
225 }); 223 });
226 } 224 }
227 225
228 test_topLevelVariable() { 226 test_topLevelVariable() {
229 addTestFile(''' 227 addTestFile('''
230 var VVV = 1; 228 var VVV = 1;
231 main() { 229 main() {
232 VVV = 2; 230 VVV = 2;
233 print(VVV); 231 print(VVV);
234 } 232 }
235 '''); 233 ''');
236 return prepareOccurrences(() { 234 return prepareOccurrences().then((_) {
237 assertHasRegion('VVV = 1;'); 235 assertHasRegion('VVV = 1;');
238 expect(testOccurences.element.kind, ElementKind.TOP_LEVEL_VARIABLE); 236 expect(testOccurences.element.kind, ElementKind.TOP_LEVEL_VARIABLE);
239 assertHasOffset('VVV = 2;'); 237 assertHasOffset('VVV = 2;');
240 assertHasOffset('VVV);'); 238 assertHasOffset('VVV);');
241 }); 239 });
242 } 240 }
243 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698