OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/services/index2/index2.dart'; | 5 import 'package:analysis_server/src/services/index2/index2.dart'; |
6 import 'package:analyzer/dart/ast/ast.dart'; | 6 import 'package:analyzer/dart/ast/ast.dart'; |
7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
8 import 'package:analyzer/src/generated/source.dart'; | 8 import 'package:analyzer/src/generated/source.dart'; |
9 import 'package:analyzer/src/summary/idl.dart'; | 9 import 'package:analyzer/src/summary/idl.dart'; |
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 '''); | 173 '''); |
174 List<Location> locations = | 174 List<Location> locations = |
175 await index.getUnresolvedMemberReferences('test'); | 175 await index.getUnresolvedMemberReferences('test'); |
176 expect(locations, hasLength(4)); | 176 expect(locations, hasLength(4)); |
177 findLocationTest(locations, 'test(); // p-inv-ur-q'); | 177 findLocationTest(locations, 'test(); // p-inv-ur-q'); |
178 findLocationTest(locations, 'test = 1; // p-ref-ur-q'); | 178 findLocationTest(locations, 'test = 1; // p-ref-ur-q'); |
179 findLocationTest(locations, 'test += 2; // p-ref-ur-q'); | 179 findLocationTest(locations, 'test += 2; // p-ref-ur-q'); |
180 findLocationTest(locations, 'test); // p-ref-ur-q'); | 180 findLocationTest(locations, 'test); // p-ref-ur-q'); |
181 } | 181 } |
182 | 182 |
| 183 test_indexUnit_nullUnit() async { |
| 184 index.indexUnit(null); |
| 185 } |
| 186 |
| 187 test_indexUnit_nullUnitElement() async { |
| 188 resolveTestUnit(''); |
| 189 testUnit.element = null; |
| 190 index.indexUnit(testUnit); |
| 191 } |
| 192 |
| 193 test_removeContext() async { |
| 194 _indexTestUnit(''' |
| 195 class A {} |
| 196 '''); |
| 197 RegExp regExp = new RegExp(r'^A$'); |
| 198 expect(await index.getDefinedNames(regExp, IndexNameKind.topLevel), |
| 199 hasLength(1)); |
| 200 // remove the context - no |
| 201 index.removeContext(context); |
| 202 expect( |
| 203 await index.getDefinedNames(regExp, IndexNameKind.topLevel), isEmpty); |
| 204 } |
| 205 |
183 /** | 206 /** |
184 * Assert that the given list of [locations] has a [Location] corresponding | 207 * Assert that the given list of [locations] has a [Location] corresponding |
185 * to the [element]. | 208 * to the [element]. |
186 */ | 209 */ |
187 void _assertHasDefinedName(List<Location> locations, Element element) { | 210 void _assertHasDefinedName(List<Location> locations, Element element) { |
188 String libraryUri = element.library.source.uri.toString(); | 211 String libraryUri = element.library.source.uri.toString(); |
189 String unitUri = element.source.uri.toString(); | 212 String unitUri = element.source.uri.toString(); |
190 for (Location location in locations) { | 213 for (Location location in locations) { |
191 if (location.libraryUri == libraryUri && | 214 if (location.libraryUri == libraryUri && |
192 location.unitUri == unitUri && | 215 location.unitUri == unitUri && |
(...skipping 11 matching lines...) Expand all Loading... |
204 index.indexUnit(testUnit); | 227 index.indexUnit(testUnit); |
205 } | 228 } |
206 | 229 |
207 Source _indexUnit(String path, String code) { | 230 Source _indexUnit(String path, String code) { |
208 Source source = addSource(path, code); | 231 Source source = addSource(path, code); |
209 CompilationUnit unit = resolveLibraryUnit(source); | 232 CompilationUnit unit = resolveLibraryUnit(source); |
210 index.indexUnit(unit); | 233 index.indexUnit(unit); |
211 return source; | 234 return source; |
212 } | 235 } |
213 } | 236 } |
OLD | NEW |