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

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

Issue 632323002: local cascade suggestion fix and move towards common tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 2 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.services.completion.toplevel; 5 library test.services.completion.toplevel;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/completion/imported_computer.dart'; 8 import 'package:analysis_server/src/services/completion/imported_computer.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
11 import '../../reflective_tests.dart'; 11 import '../../reflective_tests.dart';
12 import 'completion_test_util.dart'; 12 import 'completion_test_util.dart';
13 13
14 main() { 14 main() {
15 groupSep = ' | '; 15 groupSep = ' | ';
16 runReflectiveTests(ImportedTypeComputerTest); 16 runReflectiveTests(ImportedTypeComputerTest);
17 } 17 }
18 18
19 @ReflectiveTestCase() 19 @ReflectiveTestCase()
20 class ImportedTypeComputerTest extends AbstractCompletionTest { 20 class ImportedTypeComputerTest extends AbstractSelectorSuggestionTest {
21 21
22 @override 22 @override
23 void setUp() { 23 void setUp() {
24 super.setUp(); 24 super.setUp();
25 computer = new ImportedComputer(); 25 computer = new ImportedComputer();
26 } 26 }
27 27
28 test_Block_class() {
29 // Block BlockFunctionBody MethodDeclaration ClassDeclaration
30 addSource('/testAB.dart', '''
31 class A {int x;}
32 class _B { }''');
33 addSource('/testCD.dart', '''
34 class C { }
35 class D { }''');
36 addSource('/testEEF.dart', '''
37 class EE { }
38 class F { }''');
39 addSource('/testG.dart', 'class G { }');
40 addSource('/testH.dart', 'class H { }'); // not imported
41 addTestSource('''
42 import "/testAB.dart";
43 import "/testCD.dart" hide D;
44 import "/testEEF.dart" show EE;
45 import "/testG.dart" as g;
46 class X {foo(){^}}''');
47 // pass true for full analysis to pick up unimported source
48 return computeFull(true).then((_) {
49 assertSuggestClass('A');
50 assertNotSuggested('x');
51 assertNotSuggested('_B');
52 assertSuggestClass('C');
53 // hidden element suggested as low relevance
54 assertSuggestClass('D', CompletionRelevance.LOW);
55 assertSuggestClass('EE');
56 // hidden element suggested as low relevance
57 assertSuggestClass('F', CompletionRelevance.LOW);
58 assertSuggestLibraryPrefix('g');
59 assertNotSuggested('G');
60 assertSuggestClass('H', CompletionRelevance.LOW);
61 // Should not suggest compilation unit elements
62 // which are returned by the LocalComputer
63 assertNotSuggested('X');
64 assertSuggestClass('Object');
65 // TODO (danrubel) suggest HtmlElement as low relevance
66 assertNotSuggested('HtmlElement');
67 });
68 }
69
70 test_Block_function() { 28 test_Block_function() {
71 // Block BlockFunctionBody MethodDeclaration ClassDeclaration 29 // Block BlockFunctionBody MethodDeclaration ClassDeclaration
72 addSource('/testA.dart', ''' 30 addSource('/testA.dart', '''
73 export "dart:math" hide max; 31 export "dart:math" hide max;
74 @deprecated A() {int x;} 32 @deprecated A() {int x;}
75 _B() {}'''); 33 _B() {}''');
76 addTestSource(''' 34 addTestSource('''
77 import "/testA.dart"; 35 import "/testA.dart";
78 class X {foo(){^}}'''); 36 class X {foo(){^}}''');
79 return computeFull().then((_) { 37 return computeFull().then((_) {
(...skipping 25 matching lines...) Expand all
105 assertSuggestTopLevelVarGetterSetter('T1', 'String'); 63 assertSuggestTopLevelVarGetterSetter('T1', 'String');
106 assertNotSuggested('_T2'); 64 assertNotSuggested('_T2');
107 assertSuggestTopLevelVar('T3', 'int', CompletionRelevance.LOW); 65 assertSuggestTopLevelVar('T3', 'int', CompletionRelevance.LOW);
108 assertNotSuggested('_T4'); 66 assertNotSuggested('_T4');
109 // LocalComputer provides local suggestions 67 // LocalComputer provides local suggestions
110 assertNotSuggested('C'); 68 assertNotSuggested('C');
111 assertNotSuggested('foo'); 69 assertNotSuggested('foo');
112 }); 70 });
113 } 71 }
114 72
73 test_ConstructorName_importedClass() {
74 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
75 // InstanceCreationExpression
76 addSource('/testB.dart', '''
77 lib B;
78 class X {X.c(); X._d(); z() {}}''');
79 addTestSource('''
80 import "/testB.dart";
81 var m;
82 main() {new X.^}''');
83 return computeFull().then((_) {
84 assertNoSuggestions();
85 });
86 }
87
88 test_ConstructorName_localClass() {
89 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
90 // InstanceCreationExpression
91 addTestSource('''
92 var m;
93 class X {X.c(); X._d(); z() {}}
94 main() {new X.^}''');
95 return computeFull().then((_) {
96 assertNoSuggestions();
97 });
98 }
99
115 test_ExpressionStatement_class() { 100 test_ExpressionStatement_class() {
116 // SimpleIdentifier ExpressionStatement Block 101 // SimpleIdentifier ExpressionStatement Block
117 addSource('/testA.dart', ''' 102 addSource('/testA.dart', '''
118 class A {int x;} 103 class A {int x;}
119 class _B { }'''); 104 class _B { }''');
120 addTestSource(''' 105 addTestSource('''
121 import "/testA.dart"; 106 import "/testA.dart";
122 class C {foo(){O^}}'''); 107 class C {foo(){O^}}''');
123 return computeFull().then((_) { 108 return computeFull().then((_) {
124 assertSuggestClass('A'); 109 assertSuggestClass('A');
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 test_ImportDirective_dart() { 182 test_ImportDirective_dart() {
198 // SimpleStringLiteral ImportDirective 183 // SimpleStringLiteral ImportDirective
199 addTestSource(''' 184 addTestSource('''
200 import "dart^"; 185 import "dart^";
201 main() {}'''); 186 main() {}''');
202 return computeFull().then((_) { 187 return computeFull().then((_) {
203 assertNotSuggested('Object'); 188 assertNotSuggested('Object');
204 }); 189 });
205 } 190 }
206 191
192 test_IsExpression_local() {
193 // SimpleIdentifier TypeName IsExpression IfStatement
194 addTestSource('''
195 class X {X.c(); X._d(); z() {}}
196 main() {var x; if (x is ^) { }}''');
197 return computeFull().then((_) {
198 assertNoSuggestions();
199 });
200 }
201
207 test_PrefixedIdentifier() { 202 test_PrefixedIdentifier() {
208 // SimpleIdentifier PrefixedIdentifier ExpressionStatement 203 // SimpleIdentifier PrefixedIdentifier ExpressionStatement
209 addSource('/testA.dart', ''' 204 addSource('/testA.dart', '''
210 class A() {int x;} 205 class A() {int x;}
211 _B() {}'''); 206 _B() {}''');
212 addTestSource(''' 207 addTestSource('''
213 import "/testA.dart"; 208 import "/testA.dart";
214 class X {foo(){A a; a.^}}'''); 209 class X {foo(){A a; a.^}}''');
215 return computeFull().then((_) { 210 return computeFull().then((_) {
216 // InvocationComputer provides suggestions for prefixed expressions 211 // InvocationComputer provides suggestions for prefixed expressions
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // VariableDeclarationStatement Block 284 // VariableDeclarationStatement Block
290 addSource('/testA.dart', 'var T1;'); 285 addSource('/testA.dart', 'var T1;');
291 addTestSource(''' 286 addTestSource('''
292 import "/testA.dart"; 287 import "/testA.dart";
293 class C {a() {var ^}}'''); 288 class C {a() {var ^}}''');
294 return computeFull().then((_) { 289 return computeFull().then((_) {
295 assertNotSuggested('T1'); 290 assertNotSuggested('T1');
296 }); 291 });
297 } 292 }
298 293
299 xtest_ConstructorName_importedClass() {
300 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
301 // InstanceCreationExpression
302 addSource('/testB.dart', '''
303 lib B;
304 class X {X.c(); X._d(); z() {}}''');
305 addTestSource('''
306 import "/testB.dart";
307 var m;
308 main() {new X.^}''');
309 return computeFull().then((_) {
310 assertNoSuggestions();
311 });
312 }
313
314 xtest_ConstructorName_localClass() {
315 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
316 // InstanceCreationExpression
317 addTestSource('''
318 var m;
319 class X {X.c(); X._d(); z() {}}
320 main() {new X.^}''');
321 return computeFull().then((_) {
322 assertNoSuggestions();
323 });
324 }
325
326 // TODO (danrubel) implement
327 xtest_InstanceCreationExpression() { 294 xtest_InstanceCreationExpression() {
328 // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression 295 // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression
329 addSource('/testA.dart', ''' 296 addSource('/testA.dart', '''
330 class A {int x;} 297 class A {int x;}
331 B() { }'''); 298 B() { }''');
332 addTestSource(''' 299 addTestSource('''
333 import "/testA.dart"; 300 import "/testA.dart";
334 class C {foo(){new ^}}'''); 301 class C {foo(){new ^}}''');
335 return computeFull().then((_) { 302 return computeFull().then((_) {
336 assertSuggestClass('A'); 303 assertSuggestClass('A');
337 assertNotSuggested('x'); 304 assertNotSuggested('x');
338 assertNotSuggested('B'); 305 assertNotSuggested('B');
339 // Should not suggest compilation unit elements 306 // Should not suggest compilation unit elements
340 // which are returned by the LocalComputer 307 // which are returned by the LocalComputer
341 assertNotSuggested('C'); 308 assertNotSuggested('C');
342 }); 309 });
343 } 310 }
344 311
345 // TODO (danrubel) implement
346 xtest_IsExpression_imported() { 312 xtest_IsExpression_imported() {
347 // SimpleIdentifier TypeName IsExpression IfStatement 313 // SimpleIdentifier TypeName IsExpression IfStatement
348 addSource('/testB.dart', ''' 314 addSource('/testB.dart', '''
349 lib B; 315 lib B;
350 class X {X.c(); X._d(); z() {}}'''); 316 class X {X.c(); X._d(); z() {}}''');
351 addTestSource(''' 317 addTestSource('''
352 import "/testB.dart"; 318 import "/testB.dart";
353 main() {var x; if (x is ^) { }}'''); 319 main() {var x; if (x is ^) { }}''');
354 return computeFull().then((_) { 320 return computeFull().then((_) {
355 assertSuggestConstructor('c'); 321 assertSuggestConstructor('c');
356 assertNotSuggested('main'); 322 assertNotSuggested('main');
357 assertNotSuggested('X'); 323 assertNotSuggested('X');
358 assertNotSuggested('B'); 324 assertNotSuggested('B');
359 assertNotSuggested('x'); 325 assertNotSuggested('x');
360 }); 326 });
361 } 327 }
362 328
363 // TODO (danrubel) implement
364 xtest_IsExpression_local() {
365 // SimpleIdentifier TypeName IsExpression IfStatement
366 addTestSource('''
367 class X {X.c(); X._d(); z() {}}
368 main() {var x; if (x is ^) { }}''');
369 return computeFull().then((_) {
370 assertNoSuggestions();
371 });
372 }
373
374 // TODO (danrubel) implement
375 xtest_VariableDeclarationStatement_RHS() { 329 xtest_VariableDeclarationStatement_RHS() {
376 // SimpleIdentifier VariableDeclaration VariableDeclarationList 330 // SimpleIdentifier VariableDeclaration VariableDeclarationList
377 // VariableDeclarationStatement 331 // VariableDeclarationStatement
378 addSource('/testA.dart', 'class A {int x;} class _B { }'); 332 addSource('/testA.dart', 'class A {int x;} class _B { }');
379 addTestSource(''' 333 addTestSource('''
380 import "/testA.dart"; 334 import "/testA.dart";
381 class C {foo(){var e = ^}}'''); 335 class C {foo(){var e = ^}}''');
382 return computeFull().then((_) { 336 return computeFull().then((_) {
383 assertSuggestClass('A'); 337 assertSuggestClass('A');
384 assertNotSuggested('x'); 338 assertNotSuggested('x');
385 assertNotSuggested('_B'); 339 assertNotSuggested('_B');
386 // Should not suggest compilation unit elements 340 // Should not suggest compilation unit elements
387 // which are returned by the LocalComputer 341 // which are returned by the LocalComputer
388 assertNotSuggested('C'); 342 assertNotSuggested('C');
389 }); 343 });
390 } 344 }
391 } 345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698