OLD | NEW |
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/provisional/completion/dart/completion_dart.
dart'; | 5 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; |
6 import 'package:analysis_server/src/services/completion/dart/local_library_contr
ibutor.dart'; | 6 import 'package:analysis_server/src/services/completion/dart/local_library_contr
ibutor.dart'; |
7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
8 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 8 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
9 | 9 |
10 import 'completion_contributor_util.dart'; | 10 import 'completion_contributor_util.dart'; |
11 | 11 |
12 main() { | 12 main() { |
13 defineReflectiveSuite(() { | 13 defineReflectiveSuite(() { |
14 defineReflectiveTests(LocalLibraryContributorTest); | 14 defineReflectiveTests(LocalLibraryContributorTest); |
15 }); | 15 }); |
16 } | 16 } |
17 | 17 |
18 @reflectiveTest | 18 @reflectiveTest |
19 class LocalLibraryContributorTest extends DartCompletionContributorTest { | 19 class LocalLibraryContributorTest extends DartCompletionContributorTest { |
20 @override | 20 @override |
21 DartCompletionContributor createContributor() { | 21 DartCompletionContributor createContributor() { |
22 return new LocalLibraryContributor(); | 22 return new LocalLibraryContributor(); |
23 } | 23 } |
24 | 24 |
25 test_partFile_Constructor() async { | 25 test_partFile_Constructor() async { |
26 // SimpleIdentifier TypeName ConstructorName | 26 // SimpleIdentifier TypeName ConstructorName |
27 addSource( | 27 addSource('/testB.dart', ''' |
28 '/testB.dart', | |
29 ''' | |
30 lib B; | 28 lib B; |
31 int T1; | 29 int T1; |
32 F1() { } | 30 F1() { } |
33 class X {X.c(); X._d(); z() {}}'''); | 31 class X {X.c(); X._d(); z() {}}'''); |
34 addSource( | 32 addSource('/testA.dart', ''' |
35 '/testA.dart', | |
36 ''' | |
37 library libA; | 33 library libA; |
38 import "/testB.dart"; | 34 import "/testB.dart"; |
39 part "$testFile"; | 35 part "$testFile"; |
40 class A { } | 36 class A { } |
41 var m;'''); | 37 var m;'''); |
42 addTestSource(''' | 38 addTestSource(''' |
43 part of libA; | 39 part of libA; |
44 class B { factory B.bar(int x) => null; } | 40 class B { factory B.bar(int x) => null; } |
45 main() {new ^}'''); | 41 main() {new ^}'''); |
46 await computeLibrariesContaining(); | 42 await computeLibrariesContaining(); |
47 await computeSuggestions(); | 43 await computeSuggestions(); |
48 expect(replacementOffset, completionOffset); | 44 expect(replacementOffset, completionOffset); |
49 expect(replacementLength, 0); | 45 expect(replacementLength, 0); |
50 assertSuggestConstructor('A'); | 46 assertSuggestConstructor('A'); |
51 // Suggested by LocalConstructorContributor | 47 // Suggested by LocalConstructorContributor |
52 assertNotSuggested('B.bar'); | 48 assertNotSuggested('B.bar'); |
53 // Suggested by ImportedReferenceContributor | 49 // Suggested by ImportedReferenceContributor |
54 assertNotSuggested('Object'); | 50 assertNotSuggested('Object'); |
55 assertNotSuggested('X.c'); | 51 assertNotSuggested('X.c'); |
56 assertNotSuggested('X._d'); | 52 assertNotSuggested('X._d'); |
57 assertNotSuggested('F1'); | 53 assertNotSuggested('F1'); |
58 assertNotSuggested('T1'); | 54 assertNotSuggested('T1'); |
59 assertNotSuggested('_d'); | 55 assertNotSuggested('_d'); |
60 assertNotSuggested('z'); | 56 assertNotSuggested('z'); |
61 assertNotSuggested('m'); | 57 assertNotSuggested('m'); |
62 } | 58 } |
63 | 59 |
64 test_partFile_Constructor2() async { | 60 test_partFile_Constructor2() async { |
65 // SimpleIdentifier TypeName ConstructorName | 61 // SimpleIdentifier TypeName ConstructorName |
66 addSource( | 62 addSource('/testB.dart', ''' |
67 '/testB.dart', | |
68 ''' | |
69 lib B; | 63 lib B; |
70 int T1; | 64 int T1; |
71 F1() { } | 65 F1() { } |
72 class X {X.c(); X._d(); z() {}}'''); | 66 class X {X.c(); X._d(); z() {}}'''); |
73 addSource( | 67 addSource('/testA.dart', ''' |
74 '/testA.dart', | |
75 ''' | |
76 part of libA; | 68 part of libA; |
77 class B { }'''); | 69 class B { }'''); |
78 addTestSource(''' | 70 addTestSource(''' |
79 library libA; | 71 library libA; |
80 import "/testB.dart"; | 72 import "/testB.dart"; |
81 part "/testA.dart"; | 73 part "/testA.dart"; |
82 class A { A({String boo: 'hoo'}) { } } | 74 class A { A({String boo: 'hoo'}) { } } |
83 main() {new ^} | 75 main() {new ^} |
84 var m;'''); | 76 var m;'''); |
85 await computeLibrariesContaining(); | 77 await computeLibrariesContaining(); |
86 await computeSuggestions(); | 78 await computeSuggestions(); |
87 expect(replacementOffset, completionOffset); | 79 expect(replacementOffset, completionOffset); |
88 expect(replacementLength, 0); | 80 expect(replacementLength, 0); |
89 assertSuggestConstructor('B'); | 81 assertSuggestConstructor('B'); |
90 // Suggested by ConstructorContributor | 82 // Suggested by ConstructorContributor |
91 assertNotSuggested('A'); | 83 assertNotSuggested('A'); |
92 // Suggested by ImportedReferenceContributor | 84 // Suggested by ImportedReferenceContributor |
93 assertNotSuggested('Object'); | 85 assertNotSuggested('Object'); |
94 assertNotSuggested('X.c'); | 86 assertNotSuggested('X.c'); |
95 assertNotSuggested('X._d'); | 87 assertNotSuggested('X._d'); |
96 assertNotSuggested('F1'); | 88 assertNotSuggested('F1'); |
97 assertNotSuggested('T1'); | 89 assertNotSuggested('T1'); |
98 assertNotSuggested('_d'); | 90 assertNotSuggested('_d'); |
99 assertNotSuggested('z'); | 91 assertNotSuggested('z'); |
100 assertNotSuggested('m'); | 92 assertNotSuggested('m'); |
101 } | 93 } |
102 | 94 |
103 test_partFile_InstanceCreationExpression_assignment_filter() async { | 95 test_partFile_InstanceCreationExpression_assignment_filter() async { |
104 // ConstructorName InstanceCreationExpression VariableDeclarationList | 96 // ConstructorName InstanceCreationExpression VariableDeclarationList |
105 addSource( | 97 addSource('/testB.dart', ''' |
106 '/testB.dart', | |
107 ''' | |
108 lib B; | 98 lib B; |
109 int T1; | 99 int T1; |
110 F1() { } | 100 F1() { } |
111 class X {X.c(); X._d(); z() {}}'''); | 101 class X {X.c(); X._d(); z() {}}'''); |
112 addSource( | 102 addSource('/testA.dart', ''' |
113 '/testA.dart', | |
114 ''' | |
115 part of libA; | 103 part of libA; |
116 class A {} class B extends A {} class C implements A {} class D {} | 104 class A {} class B extends A {} class C implements A {} class D {} |
117 '''); | 105 '''); |
118 addTestSource(''' | 106 addTestSource(''' |
119 library libA; | 107 library libA; |
120 import "/testB.dart"; | 108 import "/testB.dart"; |
121 part "/testA.dart"; | 109 part "/testA.dart"; |
122 class Local { } | 110 class Local { } |
123 main() { | 111 main() { |
124 A a; | 112 A a; |
(...skipping 25 matching lines...) Expand all Loading... |
150 assertNotSuggested('X._d'); | 138 assertNotSuggested('X._d'); |
151 assertNotSuggested('F1'); | 139 assertNotSuggested('F1'); |
152 assertNotSuggested('T1'); | 140 assertNotSuggested('T1'); |
153 assertNotSuggested('_d'); | 141 assertNotSuggested('_d'); |
154 assertNotSuggested('z'); | 142 assertNotSuggested('z'); |
155 assertNotSuggested('m'); | 143 assertNotSuggested('m'); |
156 } | 144 } |
157 | 145 |
158 test_partFile_InstanceCreationExpression_variable_declaration_filter() async { | 146 test_partFile_InstanceCreationExpression_variable_declaration_filter() async { |
159 // ConstructorName InstanceCreationExpression VariableDeclarationList | 147 // ConstructorName InstanceCreationExpression VariableDeclarationList |
160 addSource( | 148 addSource('/testB.dart', ''' |
161 '/testB.dart', | |
162 ''' | |
163 lib B; | 149 lib B; |
164 int T1; | 150 int T1; |
165 F1() { } | 151 F1() { } |
166 class X {X.c(); X._d(); z() {}}'''); | 152 class X {X.c(); X._d(); z() {}}'''); |
167 addSource( | 153 addSource('/testA.dart', ''' |
168 '/testA.dart', | |
169 ''' | |
170 part of libA; | 154 part of libA; |
171 class A {} class B extends A {} class C implements A {} class D {} | 155 class A {} class B extends A {} class C implements A {} class D {} |
172 '''); | 156 '''); |
173 addTestSource(''' | 157 addTestSource(''' |
174 library libA; | 158 library libA; |
175 import "/testB.dart"; | 159 import "/testB.dart"; |
176 part "/testA.dart"; | 160 part "/testA.dart"; |
177 class Local { } | 161 class Local { } |
178 main() { | 162 main() { |
179 A a = new ^ | 163 A a = new ^ |
(...skipping 22 matching lines...) Expand all Loading... |
202 assertNotSuggested('X.c'); | 186 assertNotSuggested('X.c'); |
203 assertNotSuggested('X._d'); | 187 assertNotSuggested('X._d'); |
204 assertNotSuggested('F1'); | 188 assertNotSuggested('F1'); |
205 assertNotSuggested('T1'); | 189 assertNotSuggested('T1'); |
206 assertNotSuggested('_d'); | 190 assertNotSuggested('_d'); |
207 assertNotSuggested('z'); | 191 assertNotSuggested('z'); |
208 assertNotSuggested('m'); | 192 assertNotSuggested('m'); |
209 } | 193 } |
210 | 194 |
211 test_partFile_TypeName() async { | 195 test_partFile_TypeName() async { |
212 addSource( | 196 addSource('/testB.dart', ''' |
213 '/testB.dart', | |
214 ''' | |
215 lib B; | 197 lib B; |
216 int T1; | 198 int T1; |
217 F1() { } | 199 F1() { } |
218 class X {X.c(); X._d(); z() {}}'''); | 200 class X {X.c(); X._d(); z() {}}'''); |
219 addSource( | 201 addSource('/testA.dart', ''' |
220 '/testA.dart', | |
221 ''' | |
222 library libA; | 202 library libA; |
223 import "/testB.dart"; | 203 import "/testB.dart"; |
224 part "$testFile"; | 204 part "$testFile"; |
225 class A { var a1; a2(){}} | 205 class A { var a1; a2(){}} |
226 var m; | 206 var m; |
227 typedef t1(int blue); | 207 typedef t1(int blue); |
228 int af() {return 0;}'''); | 208 int af() {return 0;}'''); |
229 addTestSource(''' | 209 addTestSource(''' |
230 part of libA; | 210 part of libA; |
231 class B { factory B.bar(int x) => null; } | 211 class B { factory B.bar(int x) => null; } |
(...skipping 17 matching lines...) Expand all Loading... |
249 assertNotSuggested('Object'); | 229 assertNotSuggested('Object'); |
250 assertNotSuggested('X.c'); | 230 assertNotSuggested('X.c'); |
251 assertNotSuggested('X._d'); | 231 assertNotSuggested('X._d'); |
252 assertNotSuggested('F1'); | 232 assertNotSuggested('F1'); |
253 assertNotSuggested('T1'); | 233 assertNotSuggested('T1'); |
254 assertNotSuggested('_d'); | 234 assertNotSuggested('_d'); |
255 assertNotSuggested('z'); | 235 assertNotSuggested('z'); |
256 } | 236 } |
257 | 237 |
258 test_partFile_TypeName2() async { | 238 test_partFile_TypeName2() async { |
259 addSource( | 239 addSource('/testB.dart', ''' |
260 '/testB.dart', | |
261 ''' | |
262 lib B; | 240 lib B; |
263 int T1; | 241 int T1; |
264 F1() { } | 242 F1() { } |
265 class X {X.c(); X._d(); z() {}}'''); | 243 class X {X.c(); X._d(); z() {}}'''); |
266 addSource( | 244 addSource('/testA.dart', ''' |
267 '/testA.dart', | |
268 ''' | |
269 part of libA; | 245 part of libA; |
270 class B { var b1; b2(){}} | 246 class B { var b1; b2(){}} |
271 int bf() => 0; | 247 int bf() => 0; |
272 typedef t1(int blue); | 248 typedef t1(int blue); |
273 var n;'''); | 249 var n;'''); |
274 addTestSource(''' | 250 addTestSource(''' |
275 library libA; | 251 library libA; |
276 import "/testB.dart"; | 252 import "/testB.dart"; |
277 part "/testA.dart"; | 253 part "/testA.dart"; |
278 class A { A({String boo: 'hoo'}) { } } | 254 class A { A({String boo: 'hoo'}) { } } |
(...skipping 18 matching lines...) Expand all Loading... |
297 assertNotSuggested('Object'); | 273 assertNotSuggested('Object'); |
298 assertNotSuggested('X.c'); | 274 assertNotSuggested('X.c'); |
299 assertNotSuggested('X._d'); | 275 assertNotSuggested('X._d'); |
300 assertNotSuggested('F1'); | 276 assertNotSuggested('F1'); |
301 assertNotSuggested('T1'); | 277 assertNotSuggested('T1'); |
302 assertNotSuggested('_d'); | 278 assertNotSuggested('_d'); |
303 assertNotSuggested('z'); | 279 assertNotSuggested('z'); |
304 assertNotSuggested('m'); | 280 assertNotSuggested('m'); |
305 } | 281 } |
306 } | 282 } |
OLD | NEW |