| 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'; | |
| 8 import 'package:analysis_server/src/services/completion/imported_computer.dart'; | 7 import 'package:analysis_server/src/services/completion/imported_computer.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 10 | 9 |
| 11 import '../../reflective_tests.dart'; | 10 import '../../reflective_tests.dart'; |
| 12 import 'completion_test_util.dart'; | 11 import 'completion_test_util.dart'; |
| 13 | 12 |
| 14 main() { | 13 main() { |
| 15 groupSep = ' | '; | 14 groupSep = ' | '; |
| 16 runReflectiveTests(ImportedTypeComputerTest); | 15 runReflectiveTests(ImportedTypeComputerTest); |
| 17 } | 16 } |
| 18 | 17 |
| 19 @ReflectiveTestCase() | 18 @ReflectiveTestCase() |
| 20 class ImportedTypeComputerTest extends AbstractSelectorSuggestionTest { | 19 class ImportedTypeComputerTest extends AbstractSelectorSuggestionTest { |
| 21 | 20 |
| 22 @override | 21 @override |
| 23 void setUp() { | 22 void setUp() { |
| 24 super.setUp(); | 23 super.setUp(); |
| 25 computer = new ImportedComputer(); | 24 computer = new ImportedComputer(); |
| 26 } | 25 } |
| 27 | |
| 28 test_Block_function() { | |
| 29 // Block BlockFunctionBody MethodDeclaration ClassDeclaration | |
| 30 addSource('/testA.dart', ''' | |
| 31 export "dart:math" hide max; | |
| 32 @deprecated A() {int x;} | |
| 33 _B() {}'''); | |
| 34 addTestSource(''' | |
| 35 import "/testA.dart"; | |
| 36 class X {foo(){^}}'''); | |
| 37 return computeFull().then((_) { | |
| 38 assertSuggestFunction('A', null, true); | |
| 39 assertNotSuggested('x'); | |
| 40 assertNotSuggested('_B'); | |
| 41 assertSuggestFunction('min', 'num', false); | |
| 42 assertSuggestFunction('max', 'num', false, CompletionRelevance.LOW); | |
| 43 // Should not suggest compilation unit elements | |
| 44 // which are returned by the LocalComputer | |
| 45 assertNotSuggested('X'); | |
| 46 assertNotSuggested('foo'); | |
| 47 }); | |
| 48 } | |
| 49 | |
| 50 test_Block_topLevelVar() { | |
| 51 // Block BlockFunctionBody MethodDeclaration | |
| 52 addSource('/testA.dart', ''' | |
| 53 String T1; | |
| 54 var _T2;'''); | |
| 55 addSource('/testB.dart', /* not imported */ ''' | |
| 56 int T3; | |
| 57 var _T4;'''); | |
| 58 addTestSource(''' | |
| 59 import "/testA.dart"; | |
| 60 class C {foo(){^}}'''); | |
| 61 // pass true for full analysis to pick up unimported source | |
| 62 return computeFull(true).then((_) { | |
| 63 assertSuggestTopLevelVarGetterSetter('T1', 'String'); | |
| 64 assertNotSuggested('_T2'); | |
| 65 assertSuggestTopLevelVar('T3', 'int', CompletionRelevance.LOW); | |
| 66 assertNotSuggested('_T4'); | |
| 67 // LocalComputer provides local suggestions | |
| 68 assertNotSuggested('C'); | |
| 69 assertNotSuggested('foo'); | |
| 70 }); | |
| 71 } | |
| 72 | |
| 73 test_ExpressionStatement_class() { | |
| 74 // SimpleIdentifier ExpressionStatement Block | |
| 75 addSource('/testA.dart', ''' | |
| 76 _B F1() { } | |
| 77 class A {int x;} | |
| 78 class _B { }'''); | |
| 79 addTestSource(''' | |
| 80 import "/testA.dart"; | |
| 81 class C {foo(){O^}}'''); | |
| 82 return computeFull().then((_) { | |
| 83 assertSuggestClass('A'); | |
| 84 assertSuggestFunction('F1', '_B', false); | |
| 85 assertNotSuggested('x'); | |
| 86 assertNotSuggested('_B'); | |
| 87 // Should not suggest compilation unit elements | |
| 88 // which are returned by the LocalComputer | |
| 89 assertNotSuggested('C'); | |
| 90 }); | |
| 91 } | |
| 92 | |
| 93 test_ExpressionStatement_name() { | |
| 94 // ExpressionStatement Block BlockFunctionBody MethodDeclaration | |
| 95 addSource('/testA.dart', ''' | |
| 96 B T1; | |
| 97 class B{}'''); | |
| 98 addTestSource(''' | |
| 99 import "/testA.dart"; | |
| 100 class C {a() {C ^}}'''); | |
| 101 return computeFull().then((_) { | |
| 102 assertNotSuggested('T1'); | |
| 103 }); | |
| 104 } | |
| 105 | |
| 106 test_FieldDeclaration_name() { | |
| 107 // SimpleIdentifier VariableDeclaration VariableDeclarationList | |
| 108 // FieldDeclaration | |
| 109 addSource('/testA.dart', 'class A { }'); | |
| 110 addTestSource(''' | |
| 111 import "/testA.dart"; | |
| 112 class C {A ^}'''); | |
| 113 return computeFull().then((_) { | |
| 114 assertNotSuggested('A'); | |
| 115 }); | |
| 116 } | |
| 117 | |
| 118 test_FieldDeclaration_name_varType() { | |
| 119 // SimpleIdentifier VariableDeclaration VariableDeclarationList | |
| 120 // FieldDeclaration | |
| 121 addSource('/testA.dart', 'class A { }'); | |
| 122 addTestSource(''' | |
| 123 import "/testA.dart"; | |
| 124 class C {var ^}'''); | |
| 125 return computeFull().then((_) { | |
| 126 assertNotSuggested('A'); | |
| 127 }); | |
| 128 } | |
| 129 } | 26 } |
| OLD | NEW |