| OLD | NEW |
| 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 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 import "/testCD.dart" hide D; | 43 import "/testCD.dart" hide D; |
| 44 import "/testEEF.dart" show EE; | 44 import "/testEEF.dart" show EE; |
| 45 import "/testG.dart" as g; | 45 import "/testG.dart" as g; |
| 46 class X {foo(){^}}'''); | 46 class X {foo(){^}}'''); |
| 47 // pass true for full analysis to pick up unimported source | 47 // pass true for full analysis to pick up unimported source |
| 48 return computeFull(true).then((_) { | 48 return computeFull(true).then((_) { |
| 49 assertSuggestClass('A'); | 49 assertSuggestClass('A'); |
| 50 assertNotSuggested('x'); | 50 assertNotSuggested('x'); |
| 51 assertNotSuggested('_B'); | 51 assertNotSuggested('_B'); |
| 52 assertSuggestClass('C'); | 52 assertSuggestClass('C'); |
| 53 assertNotSuggested('D'); | 53 // hidden element suggested as low relevance |
| 54 assertSuggestClass('D', CompletionRelevance.LOW); |
| 54 assertSuggestClass('EE'); | 55 assertSuggestClass('EE'); |
| 55 assertNotSuggested('F'); | 56 // hidden element suggested as low relevance |
| 57 assertSuggestClass('F', CompletionRelevance.LOW); |
| 56 assertSuggestLibraryPrefix('g'); | 58 assertSuggestLibraryPrefix('g'); |
| 57 assertNotSuggested('G'); | 59 assertNotSuggested('G'); |
| 58 assertSuggestClass('H', CompletionRelevance.LOW); | 60 assertSuggestClass('H', CompletionRelevance.LOW); |
| 59 // Should not suggest compilation unit elements | 61 // Should not suggest compilation unit elements |
| 60 // which are returned by the LocalComputer | 62 // which are returned by the LocalComputer |
| 61 assertNotSuggested('X'); | 63 assertNotSuggested('X'); |
| 62 assertSuggestClass('Object'); | 64 assertSuggestClass('Object'); |
| 63 // TODO (danrubel) suggest HtmlElement as low relevance | 65 // TODO (danrubel) suggest HtmlElement as low relevance |
| 64 assertNotSuggested('HtmlElement'); | 66 assertNotSuggested('HtmlElement'); |
| 65 }); | 67 }); |
| 66 } | 68 } |
| 67 | 69 |
| 70 test_PrefixedIdentifier() { |
| 71 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
| 72 addTestSource(''' |
| 73 class A {var b; X _c;} |
| 74 class X{} |
| 75 main() {A a; a.^}'''); |
| 76 return computeFull(true).then((_) { |
| 77 // PrefixedIdentifier is handled by InvocationComputer |
| 78 assertNotSuggested('b'); |
| 79 assertNotSuggested('_c'); |
| 80 assertNotSuggested('Object'); |
| 81 }); |
| 82 } |
| 83 |
| 68 test_Block_function() { | 84 test_Block_function() { |
| 69 addSource('/testA.dart', ''' | 85 addSource('/testA.dart', ''' |
| 70 export "dart:math" hide sin; | 86 export "dart:math" hide max; |
| 71 @deprecated A() {int x;} | 87 @deprecated A() {int x;} |
| 72 _B() {}'''); | 88 _B() {}'''); |
| 73 addTestSource(''' | 89 addTestSource(''' |
| 74 import "/testA.dart"; | 90 import "/testA.dart"; |
| 75 class X {foo(){^}}'''); | 91 class X {foo(){^}}'''); |
| 76 return computeFull().then((_) { | 92 return computeFull().then((_) { |
| 77 assertSuggestFunction('A', null, true); | 93 assertSuggestFunction('A', null, true); |
| 78 assertNotSuggested('x'); | 94 assertNotSuggested('x'); |
| 79 assertNotSuggested('_B'); | 95 assertNotSuggested('_B'); |
| 80 // TODO (danrubel) should suggest exported elements from imported lib | 96 assertSuggestFunction('min', 'num', false); |
| 81 //assertSuggestFunction('cos', 'num', false); | 97 assertSuggestFunction('max', 'num', false, CompletionRelevance.LOW); |
| 82 assertNotSuggested('cos'); | |
| 83 assertNotSuggested('sin'); | |
| 84 // Should not suggest compilation unit elements | 98 // Should not suggest compilation unit elements |
| 85 // which are returned by the LocalComputer | 99 // which are returned by the LocalComputer |
| 86 assertNotSuggested('X'); | 100 assertNotSuggested('X'); |
| 87 }); | 101 }); |
| 88 } | 102 } |
| 89 | 103 |
| 90 test_Block_topLevelVar() { | 104 test_Block_topLevelVar() { |
| 91 // Block BlockFunctionBody MethodDeclaration | 105 // Block BlockFunctionBody MethodDeclaration |
| 92 addSource('/testA.dart', ''' | 106 addSource('/testA.dart', ''' |
| 93 String T1; | 107 String T1; |
| 94 var _T2;'''); | 108 var _T2;'''); |
| 95 addSource('/testB.dart', /* not imported */ ''' | 109 addSource('/testB.dart', /* not imported */ ''' |
| 96 int T3; | 110 int T3; |
| 97 var _T4;'''); | 111 var _T4;'''); |
| 98 addTestSource(''' | 112 addTestSource(''' |
| 99 import "/testA.dart"; | 113 import "/testA.dart"; |
| 100 class C {foo(){^}}'''); | 114 class C {foo(){^}}'''); |
| 101 // pass true for full analysis to pick up unimported source | 115 // pass true for full analysis to pick up unimported source |
| 102 return computeFull(true).then((_) { | 116 return computeFull(true).then((_) { |
| 103 assertSuggestTopLevelVar('T1', 'String'); | 117 assertSuggestTopLevelVarGetterSetter('T1', 'String'); |
| 104 assertNotSuggested('_T2'); | 118 assertNotSuggested('_T2'); |
| 105 assertSuggestTopLevelVar('T3', 'int', CompletionRelevance.LOW); | 119 assertSuggestTopLevelVar('T3', 'int', CompletionRelevance.LOW); |
| 106 assertNotSuggested('_T4'); | 120 assertNotSuggested('_T4'); |
| 107 }); | 121 }); |
| 108 } | 122 } |
| 109 | 123 |
| 110 test_ExpressionStatement_class() { | 124 test_ExpressionStatement_class() { |
| 111 // SimpleIdentifier ExpressionStatement Block | 125 // SimpleIdentifier ExpressionStatement Block |
| 112 addSource('/testA.dart', ''' | 126 addSource('/testA.dart', ''' |
| 113 class A {int x;} | 127 class A {int x;} |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 return computeFull().then((_) { | 300 return computeFull().then((_) { |
| 287 assertSuggestClass('A'); | 301 assertSuggestClass('A'); |
| 288 assertNotSuggested('x'); | 302 assertNotSuggested('x'); |
| 289 assertNotSuggested('_B'); | 303 assertNotSuggested('_B'); |
| 290 // Should not suggest compilation unit elements | 304 // Should not suggest compilation unit elements |
| 291 // which are returned by the LocalComputer | 305 // which are returned by the LocalComputer |
| 292 assertNotSuggested('C'); | 306 assertNotSuggested('C'); |
| 293 }); | 307 }); |
| 294 } | 308 } |
| 295 } | 309 } |
| OLD | NEW |