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

Side by Side Diff: pkg/analysis_server/test/services/completion/dart/library_prefix_contributor_test.dart

Issue 2975253002: Format analyzer, analysis_server, analyzer_plugin, front_end and kernel with the latest dartfmt. (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'package:analysis_server/src/protocol_server.dart'; 5 import 'package:analysis_server/src/protocol_server.dart';
6 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart'; 6 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart';
7 import 'package:analysis_server/src/services/completion/dart/library_prefix_cont ributor.dart'; 7 import 'package:analysis_server/src/services/completion/dart/library_prefix_cont ributor.dart';
8 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
9 import 'package:test_reflective_loader/test_reflective_loader.dart'; 9 import 'package:test_reflective_loader/test_reflective_loader.dart';
10 10
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 } 36 }
37 37
38 @override 38 @override
39 DartCompletionContributor createContributor() { 39 DartCompletionContributor createContributor() {
40 return new LibraryPrefixContributor(); 40 return new LibraryPrefixContributor();
41 } 41 }
42 42
43 test_Block() async { 43 test_Block() async {
44 // Block BlockFunctionBody MethodDeclaration 44 // Block BlockFunctionBody MethodDeclaration
45 addSource( 45 addSource('/testAB.dart', '''
46 '/testAB.dart',
47 '''
48 export "dart:math" hide max; 46 export "dart:math" hide max;
49 class A {int x;} 47 class A {int x;}
50 @deprecated D1() {int x;} 48 @deprecated D1() {int x;}
51 class _B {boo() { partBoo() {}} }'''); 49 class _B {boo() { partBoo() {}} }''');
52 addSource( 50 addSource('/testCD.dart', '''
53 '/testCD.dart',
54 '''
55 String T1; 51 String T1;
56 var _T2; 52 var _T2;
57 class C { } 53 class C { }
58 class D { }'''); 54 class D { }''');
59 addSource( 55 addSource('/testEEF.dart', '''
60 '/testEEF.dart',
61 '''
62 class EE { } 56 class EE { }
63 class F { }'''); 57 class F { }''');
64 addSource('/testG.dart', 'class G { }'); 58 addSource('/testG.dart', 'class G { }');
65 addSource( 59 addSource('/testH.dart', '''
66 '/testH.dart',
67 '''
68 class H { } 60 class H { }
69 int T3; 61 int T3;
70 var _T4;'''); // not imported 62 var _T4;'''); // not imported
71 addTestSource(''' 63 addTestSource('''
72 import "/testAB.dart"; 64 import "/testAB.dart";
73 import "/testCD.dart" hide D; 65 import "/testCD.dart" hide D;
74 import "/testEEF.dart" show EE; 66 import "/testEEF.dart" show EE;
75 import "/testG.dart" as g; 67 import "/testG.dart" as g;
76 int T5; 68 int T5;
77 var _T6; 69 var _T6;
(...skipping 12 matching lines...) Expand all
90 void b() { }} 82 void b() { }}
91 class Z { }'''); 83 class Z { }''');
92 await computeSuggestions(); 84 await computeSuggestions();
93 expect(replacementOffset, completionOffset); 85 expect(replacementOffset, completionOffset);
94 expect(replacementLength, 0); 86 expect(replacementLength, 0);
95 assertSuggestLibraryPrefixes(['g']); 87 assertSuggestLibraryPrefixes(['g']);
96 } 88 }
97 89
98 test_Block_final_final() async { 90 test_Block_final_final() async {
99 // Block BlockFunctionBody MethodDeclaration 91 // Block BlockFunctionBody MethodDeclaration
100 addSource( 92 addSource('/testAB.dart', '''
101 '/testAB.dart',
102 '''
103 export "dart:math" hide max; 93 export "dart:math" hide max;
104 class A {int x;} 94 class A {int x;}
105 @deprecated D1() {int x;} 95 @deprecated D1() {int x;}
106 class _B {boo() { partBoo() {}} }'''); 96 class _B {boo() { partBoo() {}} }''');
107 addSource( 97 addSource('/testCD.dart', '''
108 '/testCD.dart',
109 '''
110 String T1; 98 String T1;
111 var _T2; 99 var _T2;
112 class C { } 100 class C { }
113 class D { }'''); 101 class D { }''');
114 addSource( 102 addSource('/testEEF.dart', '''
115 '/testEEF.dart',
116 '''
117 class EE { } 103 class EE { }
118 class F { }'''); 104 class F { }''');
119 addSource('/testG.dart', 'class G { }'); 105 addSource('/testG.dart', 'class G { }');
120 addSource( 106 addSource('/testH.dart', '''
121 '/testH.dart',
122 '''
123 class H { } 107 class H { }
124 int T3; 108 int T3;
125 var _T4;'''); // not imported 109 var _T4;'''); // not imported
126 addTestSource(''' 110 addTestSource('''
127 import "/testAB.dart"; 111 import "/testAB.dart";
128 import "/testCD.dart" hide D; 112 import "/testCD.dart" hide D;
129 import "/testEEF.dart" show EE; 113 import "/testEEF.dart" show EE;
130 import "/testG.dart" as g; 114 import "/testG.dart" as g;
131 int T5; 115 int T5;
132 var _T6; 116 var _T6;
(...skipping 12 matching lines...) Expand all
145 void b() { }} 129 void b() { }}
146 class Z { }'''); 130 class Z { }''');
147 await computeSuggestions(); 131 await computeSuggestions();
148 expect(replacementOffset, completionOffset); 132 expect(replacementOffset, completionOffset);
149 expect(replacementLength, 0); 133 expect(replacementLength, 0);
150 assertSuggestLibraryPrefixes(['g']); 134 assertSuggestLibraryPrefixes(['g']);
151 } 135 }
152 136
153 test_Block_final_var() async { 137 test_Block_final_var() async {
154 // Block BlockFunctionBody MethodDeclaration 138 // Block BlockFunctionBody MethodDeclaration
155 addSource( 139 addSource('/testAB.dart', '''
156 '/testAB.dart',
157 '''
158 export "dart:math" hide max; 140 export "dart:math" hide max;
159 class A {int x;} 141 class A {int x;}
160 @deprecated D1() {int x;} 142 @deprecated D1() {int x;}
161 class _B {boo() { partBoo() {}} }'''); 143 class _B {boo() { partBoo() {}} }''');
162 addSource( 144 addSource('/testCD.dart', '''
163 '/testCD.dart',
164 '''
165 String T1; 145 String T1;
166 var _T2; 146 var _T2;
167 class C { } 147 class C { }
168 class D { }'''); 148 class D { }''');
169 addSource( 149 addSource('/testEEF.dart', '''
170 '/testEEF.dart',
171 '''
172 class EE { } 150 class EE { }
173 class F { }'''); 151 class F { }''');
174 addSource('/testG.dart', 'class G { }'); 152 addSource('/testG.dart', 'class G { }');
175 addSource( 153 addSource('/testH.dart', '''
176 '/testH.dart',
177 '''
178 class H { } 154 class H { }
179 int T3; 155 int T3;
180 var _T4;'''); // not imported 156 var _T4;'''); // not imported
181 addTestSource(''' 157 addTestSource('''
182 import "/testAB.dart"; 158 import "/testAB.dart";
183 import "/testCD.dart" hide D; 159 import "/testCD.dart" hide D;
184 import "/testEEF.dart" show EE; 160 import "/testEEF.dart" show EE;
185 import "/testG.dart" as g; 161 import "/testG.dart" as g;
186 int T5; 162 int T5;
187 var _T6; 163 var _T6;
(...skipping 12 matching lines...) Expand all
200 void b() { }} 176 void b() { }}
201 class Z { }'''); 177 class Z { }''');
202 await computeSuggestions(); 178 await computeSuggestions();
203 expect(replacementOffset, completionOffset); 179 expect(replacementOffset, completionOffset);
204 expect(replacementLength, 0); 180 expect(replacementLength, 0);
205 assertSuggestLibraryPrefixes(['g']); 181 assertSuggestLibraryPrefixes(['g']);
206 } 182 }
207 183
208 test_ClassDeclaration_body() async { 184 test_ClassDeclaration_body() async {
209 // ClassDeclaration CompilationUnit 185 // ClassDeclaration CompilationUnit
210 addSource( 186 addSource('/testB.dart', '''
211 '/testB.dart',
212 '''
213 class B { }'''); 187 class B { }''');
214 addTestSource(''' 188 addTestSource('''
215 import "testB.dart" as x; 189 import "testB.dart" as x;
216 @deprecated class A {^} 190 @deprecated class A {^}
217 class _B {} 191 class _B {}
218 A T;'''); 192 A T;''');
219 await computeSuggestions(); 193 await computeSuggestions();
220 expect(replacementOffset, completionOffset); 194 expect(replacementOffset, completionOffset);
221 expect(replacementLength, 0); 195 expect(replacementLength, 0);
222 assertSuggestLibraryPrefixes(['x']); 196 assertSuggestLibraryPrefixes(['x']);
223 } 197 }
224 198
225 test_ClassDeclaration_body_final() async { 199 test_ClassDeclaration_body_final() async {
226 // ClassDeclaration CompilationUnit 200 // ClassDeclaration CompilationUnit
227 addSource( 201 addSource('/testB.dart', '''
228 '/testB.dart',
229 '''
230 class B { }'''); 202 class B { }''');
231 addTestSource(''' 203 addTestSource('''
232 import "testB.dart" as x; 204 import "testB.dart" as x;
233 class A {final ^} 205 class A {final ^}
234 class _B {} 206 class _B {}
235 A T;'''); 207 A T;''');
236 await computeSuggestions(); 208 await computeSuggestions();
237 expect(replacementOffset, completionOffset); 209 expect(replacementOffset, completionOffset);
238 expect(replacementLength, 0); 210 expect(replacementLength, 0);
239 assertSuggestLibraryPrefixes(['x']); 211 assertSuggestLibraryPrefixes(['x']);
240 } 212 }
241 213
242 test_ClassDeclaration_body_final_field() async { 214 test_ClassDeclaration_body_final_field() async {
243 // ClassDeclaration CompilationUnit 215 // ClassDeclaration CompilationUnit
244 addSource( 216 addSource('/testB.dart', '''
245 '/testB.dart',
246 '''
247 class B { }'''); 217 class B { }''');
248 addTestSource(''' 218 addTestSource('''
249 import "testB.dart" as x; 219 import "testB.dart" as x;
250 class A {final ^ A(){}} 220 class A {final ^ A(){}}
251 class _B {} 221 class _B {}
252 A T;'''); 222 A T;''');
253 await computeSuggestions(); 223 await computeSuggestions();
254 expect(replacementOffset, completionOffset); 224 expect(replacementOffset, completionOffset);
255 expect(replacementLength, 0); 225 expect(replacementLength, 0);
256 assertSuggestLibraryPrefixes(['x']); 226 assertSuggestLibraryPrefixes(['x']);
257 } 227 }
258 228
259 test_ClassDeclaration_body_final_field2() async { 229 test_ClassDeclaration_body_final_field2() async {
260 // ClassDeclaration CompilationUnit 230 // ClassDeclaration CompilationUnit
261 addSource( 231 addSource('/testB.dart', '''
262 '/testB.dart',
263 '''
264 class B { }'''); 232 class B { }''');
265 addTestSource(''' 233 addTestSource('''
266 import "testB.dart" as Soo; 234 import "testB.dart" as Soo;
267 class A {final S^ A();} 235 class A {final S^ A();}
268 class _B {} 236 class _B {}
269 A Sew;'''); 237 A Sew;''');
270 await computeSuggestions(); 238 await computeSuggestions();
271 expect(replacementOffset, completionOffset - 1); 239 expect(replacementOffset, completionOffset - 1);
272 expect(replacementLength, 1); 240 expect(replacementLength, 1);
273 assertSuggestLibraryPrefixes(['Soo']); 241 assertSuggestLibraryPrefixes(['Soo']);
274 } 242 }
275 243
276 test_ClassDeclaration_body_final_final() async { 244 test_ClassDeclaration_body_final_final() async {
277 // ClassDeclaration CompilationUnit 245 // ClassDeclaration CompilationUnit
278 addSource( 246 addSource('/testB.dart', '''
279 '/testB.dart',
280 '''
281 class B { }'''); 247 class B { }''');
282 addTestSource(''' 248 addTestSource('''
283 import "testB.dart" as x; 249 import "testB.dart" as x;
284 class A {final ^ final foo;} 250 class A {final ^ final foo;}
285 class _B {} 251 class _B {}
286 A T;'''); 252 A T;''');
287 await computeSuggestions(); 253 await computeSuggestions();
288 expect(replacementOffset, completionOffset); 254 expect(replacementOffset, completionOffset);
289 expect(replacementLength, 0); 255 expect(replacementLength, 0);
290 assertSuggestLibraryPrefixes(['x']); 256 assertSuggestLibraryPrefixes(['x']);
291 } 257 }
292 258
293 test_ClassDeclaration_body_final_var() async { 259 test_ClassDeclaration_body_final_var() async {
294 // ClassDeclaration CompilationUnit 260 // ClassDeclaration CompilationUnit
295 addSource( 261 addSource('/testB.dart', '''
296 '/testB.dart',
297 '''
298 class B { }'''); 262 class B { }''');
299 addTestSource(''' 263 addTestSource('''
300 import "testB.dart" as x; 264 import "testB.dart" as x;
301 class A {final ^ var foo;} 265 class A {final ^ var foo;}
302 class _B {} 266 class _B {}
303 A T;'''); 267 A T;''');
304 await computeSuggestions(); 268 await computeSuggestions();
305 expect(replacementOffset, completionOffset); 269 expect(replacementOffset, completionOffset);
306 expect(replacementLength, 0); 270 expect(replacementLength, 0);
307 assertSuggestLibraryPrefixes(['x']); 271 assertSuggestLibraryPrefixes(['x']);
308 } 272 }
309 273
310 test_InstanceCreationExpression() async { 274 test_InstanceCreationExpression() async {
311 addSource( 275 addSource('/testA.dart', '''
312 '/testA.dart',
313 '''
314 class A {foo(){var f; {var x;}}} 276 class A {foo(){var f; {var x;}}}
315 class B {B(this.x, [String boo]) { } int x;} 277 class B {B(this.x, [String boo]) { } int x;}
316 class C {C.bar({boo: 'hoo', int z: 0}) { } }'''); 278 class C {C.bar({boo: 'hoo', int z: 0}) { } }''');
317 addTestSource(''' 279 addTestSource('''
318 import "/testA.dart" as t; 280 import "/testA.dart" as t;
319 import "dart:math" as math; 281 import "dart:math" as math;
320 main() {new ^ String x = "hello";}'''); 282 main() {new ^ String x = "hello";}''');
321 await computeSuggestions(); 283 await computeSuggestions();
322 assertSuggestLibraryPrefixes(['math', 't']); 284 assertSuggestLibraryPrefixes(['math', 't']);
323 } 285 }
324 286
325 test_InstanceCreationExpression2() async { 287 test_InstanceCreationExpression2() async {
326 addTestSource('import "dart:convert" as json;f() {var x=new js^}'); 288 addTestSource('import "dart:convert" as json;f() {var x=new js^}');
327 await computeSuggestions(); 289 await computeSuggestions();
328 assertSuggestLibraryPrefixes(['json']); 290 assertSuggestLibraryPrefixes(['json']);
329 } 291 }
330 292
331 test_InstanceCreationExpression_inPart() async { 293 test_InstanceCreationExpression_inPart() async {
332 addSource( 294 addSource('/testA.dart', '''
333 '/testA.dart',
334 '''
335 class A {foo(){var f; {var x;}}} 295 class A {foo(){var f; {var x;}}}
336 class B {B(this.x, [String boo]) { } int x;} 296 class B {B(this.x, [String boo]) { } int x;}
337 class C {C.bar({boo: 'hoo', int z: 0}) { } }'''); 297 class C {C.bar({boo: 'hoo', int z: 0}) { } }''');
338 addSource( 298 addSource('/testB.dart', '''
339 '/testB.dart',
340 '''
341 library testB; 299 library testB;
342 import "/testA.dart" as t; 300 import "/testA.dart" as t;
343 import "dart:math" as math; 301 import "dart:math" as math;
344 part "$testFile" 302 part "$testFile"
345 main() {new ^ String x = "hello";}'''); 303 main() {new ^ String x = "hello";}''');
346 addTestSource(''' 304 addTestSource('''
347 part of testB; 305 part of testB;
348 main() {new ^ String x = "hello";}'''); 306 main() {new ^ String x = "hello";}''');
349 await computeLibrariesContaining(); 307 await computeLibrariesContaining();
350 await computeSuggestions(); 308 await computeSuggestions();
351 assertSuggestLibraryPrefixes(['math', 't']); 309 assertSuggestLibraryPrefixes(['math', 't']);
352 } 310 }
353 311
354 test_InstanceCreationExpression_inPart_detached() async { 312 test_InstanceCreationExpression_inPart_detached() async {
355 addSource( 313 addSource('/testA.dart', '''
356 '/testA.dart',
357 '''
358 class A {foo(){var f; {var x;}}} 314 class A {foo(){var f; {var x;}}}
359 class B {B(this.x, [String boo]) { } int x;} 315 class B {B(this.x, [String boo]) { } int x;}
360 class C {C.bar({boo: 'hoo', int z: 0}) { } }'''); 316 class C {C.bar({boo: 'hoo', int z: 0}) { } }''');
361 addSource( 317 addSource('/testB.dart', '''
362 '/testB.dart',
363 '''
364 library testB; 318 library testB;
365 import "/testA.dart" as t; 319 import "/testA.dart" as t;
366 import "dart:math" as math; 320 import "dart:math" as math;
367 //part "$testFile" 321 //part "$testFile"
368 main() {new ^ String x = "hello";}'''); 322 main() {new ^ String x = "hello";}''');
369 addTestSource(''' 323 addTestSource('''
370 //part of testB; 324 //part of testB;
371 main() {new ^ String x = "hello";}'''); 325 main() {new ^ String x = "hello";}''');
372 await computeSuggestions(); 326 await computeSuggestions();
373 assertNoSuggestions(); 327 assertNoSuggestions();
374 } 328 }
375 } 329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698