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

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

Issue 628473002: cleanup/organize/improve completion 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 '../../reflective_tests.dart';
10 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
11 10
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 AbstractCompletionTest {
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_class() { 28 test_Block_class() {
29 addSource('/testA.dart', 'class A {int x;} class _B { }'); 29 // Block BlockFunctionBody MethodDeclaration ClassDeclaration
30 addTestSource('import "/testA.dart"; class C {foo(){^}}'); 30 addSource('/testAB.dart', '''
31 return computeFull().then((_) { 31 class A {int x;}
32 assertSuggestClass('A'); 32 class _B { }''');
33 assertNotSuggested('x'); 33 addSource('/testCD.dart', '''
34 assertNotSuggested('_B'); 34 class C { }
35 // Should not suggest compilation unit elements 35 class D { }''');
36 // which are returned by the LocalComputer 36 addSource('/testEEF.dart', '''
37 assertNotSuggested('C'); 37 class EE { }
38 }); 38 class F { }''');
39 } 39 addSource('/testG.dart', 'class G { }');
40 40 addSource('/testH.dart', 'class H { }'); // not imported
41 test_function() { 41 addTestSource('''
42 addSource('/testA.dart', '@deprecated A() {int x;} _B() {}'); 42 import "/testAB.dart";
43 addTestSource('import "/testA.dart"; class C {foo(){^}}'); 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 assertNotSuggested('D');
54 assertSuggestClass('EE');
55 assertNotSuggested('F');
56 // Don't suggest library prefix as it is suggested by local computer
57 // TODO (danrubel) modify so that imported_computer handles
58 // all aspects of import statement
59 assertNotSuggested('g');
60 assertNotSuggested('G');
61 assertSuggestClass('H', CompletionRelevance.LOW);
62 // Should not suggest compilation unit elements
63 // which are returned by the LocalComputer
64 assertNotSuggested('X');
65 assertSuggestClass('Object');
66 // TODO (danrubel) suggest HtmlElement as low relevance
67 assertNotSuggested('HtmlElement');
68 });
69 }
70
71 test_Block_function() {
72 addSource('/testA.dart', '''
73 export "dart:math" hide sin;
74 @deprecated A() {int x;}
75 _B() {}''');
76 addTestSource('''
77 import "/testA.dart";
78 class X {foo(){^}}''');
44 return computeFull().then((_) { 79 return computeFull().then((_) {
45 assertSuggestFunction('A', null, true); 80 assertSuggestFunction('A', null, true);
46 assertNotSuggested('x'); 81 assertNotSuggested('x');
47 assertNotSuggested('_B'); 82 assertNotSuggested('_B');
48 // Should not suggest compilation unit elements 83 // TODO (danrubel) should suggest exported elements from imported lib
49 // which are returned by the LocalComputer 84 //assertSuggestFunction('cos', 'num', false);
50 assertNotSuggested('C'); 85 assertNotSuggested('cos');
51 }); 86 assertNotSuggested('sin');
52 } 87 // Should not suggest compilation unit elements
53 88 // which are returned by the LocalComputer
54 test_class_importHide() { 89 assertNotSuggested('X');
55 addSource('/testA.dart', 'class A { } class B { }'); 90 });
56 addTestSource('import "/testA.dart" hide ^; class C {}'); 91 }
57 return computeFull().then((_) { 92
58 assertSuggestClass('A'); 93 test_Block_topLevelVar() {
59 assertSuggestClass('B'); 94 // Block BlockFunctionBody MethodDeclaration
60 assertNotSuggested('Object'); 95 addSource('/testA.dart', '''
61 }); 96 String T1;
62 } 97 var _T2;''');
63 98 addSource('/testB.dart', /* not imported */ '''
64 test_class_importShow() { 99 int T3;
65 addSource('/testA.dart', 'class A { } class B { }'); 100 var _T4;''');
66 addTestSource('import "/testA.dart" show ^; class C {}'); 101 addTestSource('''
67 return computeFull().then((_) { 102 import "/testA.dart";
68 // only suggest elements listed in show combinator 103 class C {foo(){^}}''');
69 assertSuggestClass('A'); 104 // pass true for full analysis to pick up unimported source
70 assertSuggestClass('B');
71 assertNotSuggested('Object');
72 });
73 }
74
75 test_class_importShowWithPart() {
76 addSource('/testB.dart', 'part of libA; class B { }');
77 addSource('/testA.dart', 'part "/testB.dart"; class A { }');
78 addTestSource('import "/testA.dart" show ^; class C {}');
79 return computeFull().then((_) {
80 // only suggest elements listed in show combinator
81 assertSuggestClass('A');
82 assertSuggestClass('B');
83 assertNotSuggested('Object');
84 });
85 }
86
87 test_class_importedWithHide() {
88 addSource('/testA.dart', 'class A { } class B { }');
89 addTestSource('import "/testA.dart" hide B; class C {foo(){^}}');
90 return computeFull().then((_) {
91 // exclude elements listed in hide combinator
92 assertSuggestClass('A');
93 assertNotSuggested('B');
94 assertSuggestClass('Object');
95 });
96 }
97
98 test_class_importedWithPrefix() {
99 addSource('/testA.dart', 'class A { }');
100 addTestSource('import "/testA.dart" as foo; class C {foo(){^}}');
101 return computeFull().then((_) {
102 // do not suggest types imported with prefix
103 assertNotSuggested('A');
104 // do not suggest prefix as it is suggested by LocalComputer
105 assertNotSuggested('foo');
106 });
107 }
108
109 test_class_importedWithShow() {
110 addSource('/testA.dart', 'class A { } class B { }');
111 addTestSource('import "/testA.dart" show A; class C {foo(){^}}');
112 return computeFull().then((_) {
113 // only suggest elements listed in show combinator
114 assertSuggestClass('A');
115 assertNotSuggested('B');
116 assertSuggestClass('Object');
117 });
118 }
119
120 test_class_notImported() {
121 addSource('/testA.dart', 'class A {int x;} class _B { }');
122 addTestSource('class C {foo(){^}}');
123 return computeFull(true).then((_) { 105 return computeFull(true).then((_) {
124 assertSuggestClass('A', CompletionRelevance.LOW);
125 assertNotSuggested('x');
126 assertNotSuggested('_B');
127 });
128 }
129
130 test_dartCore() {
131 addTestSource('class C {foo(){^}}');
132 return computeFull().then((_) {
133 assertSuggestClass('Object');
134 assertNotSuggested('HtmlElement');
135 });
136 }
137
138 test_dartHtml() {
139 addTestSource('import "dart:html"; class C {foo(){^}}');
140 return computeFull().then((_) {
141 assertSuggestClass('Object');
142 assertSuggestClass('HtmlElement');
143 });
144 }
145
146 test_field_name() {
147 addSource('/testA.dart', 'class A { }');
148 addTestSource('import "/testA.dart"; class C {A ^}');
149 return computeFull().then((_) {
150 assertNotSuggested('A');
151 });
152 }
153
154 test_field_name2() {
155 addSource('/testA.dart', 'class A { }');
156 addTestSource('import "/testA.dart"; class C {var ^}');
157 return computeFull().then((_) {
158 assertNotSuggested('A');
159 });
160 }
161
162 test_local_name() {
163 addSource('/testA.dart', 'B T1; class B{}');
164 addTestSource('import "/testA.dart"; class C {a() {C ^}}');
165 return computeFull().then((_) {
166 assertNotSuggested('T1');
167 });
168 }
169
170 test_local_name2() {
171 addSource('/testA.dart', 'var T1;');
172 addTestSource('import "/testA.dart"; class C {a() {var ^}}');
173 return computeFull().then((_) {
174 assertNotSuggested('T1');
175 });
176 }
177
178 test_import_dart() {
179 addTestSource('import "dart^"; main() {}');
180 return computeFull().then((_) {
181 assertNotSuggested('T1');
182 });
183 }
184
185 test_topLevelVar() {
186 addSource('/testA.dart', 'String T1; var _T2;');
187 addTestSource('import "/testA.dart"; class C {foo(){^}}');
188 return computeFull().then((_) {
189 assertSuggestTopLevelVar('T1', 'String'); 106 assertSuggestTopLevelVar('T1', 'String');
190 assertNotSuggested('_T2'); 107 assertNotSuggested('_T2');
191 }); 108 assertSuggestTopLevelVar('T3', 'int', CompletionRelevance.LOW);
192 } 109 assertNotSuggested('_T4');
193 110 });
194 test_topLevelVar_name() { 111 }
112
113 test_ExpressionStatement_class() {
114 // SimpleIdentifier ExpressionStatement Block
115 addSource('/testA.dart', '''
116 class A {int x;}
117 class _B { }''');
118 addTestSource('''
119 import "/testA.dart";
120 class C {foo(){O^}}''');
121 return computeFull().then((_) {
122 assertSuggestClass('A');
123 assertNotSuggested('x');
124 assertNotSuggested('_B');
125 // Should not suggest compilation unit elements
126 // which are returned by the LocalComputer
127 assertNotSuggested('C');
128 });
129 }
130
131 test_ExpressionStatement_name() {
132 // ExpressionStatement Block BlockFunctionBody MethodDeclaration
133 addSource('/testA.dart', '''
134 B T1;
135 class B{}''');
136 addTestSource('''
137 import "/testA.dart";
138 class C {a() {C ^}}''');
139 return computeFull().then((_) {
140 assertNotSuggested('T1');
141 });
142 }
143
144 test_FieldDeclaration_name() {
145 // SimpleIdentifier VariableDeclaration VariableDeclarationList
146 // FieldDeclaration
147 addSource('/testA.dart', 'class A { }');
148 addTestSource('''
149 import "/testA.dart";
150 class C {A ^}''');
151 return computeFull().then((_) {
152 assertNotSuggested('A');
153 });
154 }
155
156 test_FieldDeclaration_name_varType() {
157 // SimpleIdentifier VariableDeclaration VariableDeclarationList
158 // FieldDeclaration
159 addSource('/testA.dart', 'class A { }');
160 addTestSource('''
161 import "/testA.dart";
162 class C {var ^}''');
163 return computeFull().then((_) {
164 assertNotSuggested('A');
165 });
166 }
167
168 test_HideCombinator_class() {
169 // SimpleIdentifier HideCombinator ImportDirective
170 addSource('/testAB.dart', '''
171 library libAB;
172 part '/partAB.dart';
173 class A { }
174 class B { }''');
175 addSource('/partAB.dart', '''
176 part of libAB;
177 class PB { }''');
178 addSource('/testCD.dart', '''
179 class C { }
180 class D { }''');
181 addTestSource('''
182 import "/testAB.dart" hide ^;
183 import "/testCD.dart";
184 class X {}''');
185 return computeFull().then((_) {
186 assertSuggestClass('A');
187 assertSuggestClass('B');
188 assertSuggestClass('PB');
189 assertNotSuggested('C');
190 assertNotSuggested('D');
191 assertNotSuggested('Object');
192 });
193 }
194
195 test_ImportDirective_dart() {
196 // SimpleStringLiteral ImportDirective
197 addTestSource('''
198 import "dart^";
199 main() {}''');
200 return computeFull().then((_) {
201 assertNotSuggested('Object');
202 });
203 }
204
205 test_ShowCombinator_class() {
206 // SimpleIdentifier ShowCombinator ImportDirective
207 addSource('/testAB.dart', '''
208 class A { }
209 class B { }''');
210 addSource('/testCD.dart', '''
211 class C { }
212 class D { }''');
213 addTestSource('''
214 import "/testAB.dart" show ^;
215 import "/testCD.dart";
216 class X {}''');
217 return computeFull().then((_) {
218 assertSuggestClass('A');
219 assertSuggestClass('B');
220 assertNotSuggested('C');
221 assertNotSuggested('D');
222 assertNotSuggested('Object');
223 });
224 }
225
226 test_TopLevelVariableDeclaration_name() {
227 // SimpleIdentifier VariableDeclaration VariableDeclarationList
228 // TopLevelVariableDeclaration
195 addSource('/testA.dart', 'class B { };'); 229 addSource('/testA.dart', 'class B { };');
196 addTestSource('import "/testA.dart"; class C {} B ^'); 230 addTestSource('''
231 import "/testA.dart";
232 class C {} B ^''');
197 return computeFull().then((_) { 233 return computeFull().then((_) {
198 assertNotSuggested('B'); 234 assertNotSuggested('B');
199 }); 235 });
200 } 236 }
201 237
202 test_topLevelVar_name2() { 238 test_TopLevelVariableDeclaration_name_untyped() {
239 // SimpleIdentifier VariableDeclaration VariableDeclarationList
240 // TopLevelVariableDeclaration
203 addSource('/testA.dart', 'class B { };'); 241 addSource('/testA.dart', 'class B { };');
204 addTestSource('import "/testA.dart"; class C {} var ^'); 242 addTestSource('''
243 import "/testA.dart";
244 class C {} var ^''');
205 return computeFull().then((_) { 245 return computeFull().then((_) {
206 assertNotSuggested('B'); 246 assertNotSuggested('B');
207 }); 247 });
208 } 248 }
209 249
210 test_topLevelVar_notImported() { 250 test_VariableDeclaration_name() {
211 addSource('/testA.dart', 'var T1; var _T2;'); 251 // SimpleIdentifier VariableDeclaration VariableDeclarationList
212 addTestSource('class C {foo(){^}}'); 252 // VariableDeclarationStatement Block
213 return computeFull(true).then((_) { 253 addSource('/testA.dart', 'var T1;');
214 assertSuggestTopLevelVar('T1', null, CompletionRelevance.LOW); 254 addTestSource('''
215 assertNotSuggested('_T2'); 255 import "/testA.dart";
256 class C {a() {var ^}}''');
257 return computeFull().then((_) {
258 assertNotSuggested('T1');
259 });
260 }
261
262 // TODO (danrubel) implement
263 xtest_InstanceCreationExpression() {
264 // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression
265 addSource('/testA.dart', '''
266 class A {int x;}
267 B() { }''');
268 addTestSource('''
269 import "/testA.dart";
270 class C {foo(){new ^}}''');
271 return computeFull().then((_) {
272 assertSuggestClass('A');
273 assertNotSuggested('x');
274 assertNotSuggested('B');
275 // Should not suggest compilation unit elements
276 // which are returned by the LocalComputer
277 assertNotSuggested('C');
278 });
279 }
280
281 // TODO (danrubel) implement
282 xtest_VariableDeclarationStatement_RHS() {
283 // SimpleIdentifier VariableDeclaration VariableDeclarationList
284 // VariableDeclarationStatement
285 addSource('/testA.dart', 'class A {int x;} class _B { }');
286 addTestSource('''
287 import "/testA.dart";
288 class C {foo(){var e = ^}}''');
289 return computeFull().then((_) {
290 assertSuggestClass('A');
291 assertNotSuggested('x');
292 assertNotSuggested('_B');
293 // Should not suggest compilation unit elements
294 // which are returned by the LocalComputer
295 assertNotSuggested('C');
216 }); 296 });
217 } 297 }
218 } 298 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698