| Index: pkg/analysis_server/test/services/index2/index2_test.dart
|
| diff --git a/pkg/analysis_server/test/services/index2/index2_test.dart b/pkg/analysis_server/test/services/index2/index2_test.dart
|
| index 4143e82319d257f12e8724e069158d68c392ee2a..d82bdb3257229e6c3f126ff34e061066bd64f626 100644
|
| --- a/pkg/analysis_server/test/services/index2/index2_test.dart
|
| +++ b/pkg/analysis_server/test/services/index2/index2_test.dart
|
| @@ -73,6 +73,51 @@ class Index2Test extends AbstractSingleUnitTest {
|
| index = null;
|
| }
|
|
|
| + test_getDefinedNames_classMember() async {
|
| + _indexTestUnit('''
|
| +class A {
|
| + test() {}
|
| +}
|
| +class B {
|
| + int test = 1;
|
| + main() {
|
| + int test = 2;
|
| + }
|
| +}
|
| +''');
|
| + ClassElement classA = findElement('A');
|
| + ClassElement classB = findElement('B');
|
| + List<Location> locations = await index.getDefinedNames(
|
| + new RegExp(r'^test$'), IndexNameKind.classMember);
|
| + expect(locations, hasLength(2));
|
| + _assertHasDefinedName(locations, classA.methods[0]);
|
| + _assertHasDefinedName(locations, classB.fields[0]);
|
| + }
|
| +
|
| + test_getDefinedNames_topLevel() async {
|
| + _indexTestUnit('''
|
| +class A {} // A
|
| +class B = Object with A;
|
| +typedef C();
|
| +D() {}
|
| +var E = null;
|
| +class NoMatchABCDE {}
|
| +''');
|
| + Element topA = findElement('A');
|
| + Element topB = findElement('B');
|
| + Element topC = findElement('C');
|
| + Element topD = findElement('D');
|
| + Element topE = findElement('E');
|
| + List<Location> locations = await index.getDefinedNames(
|
| + new RegExp(r'^[A-E]$'), IndexNameKind.topLevel);
|
| + expect(locations, hasLength(5));
|
| + _assertHasDefinedName(locations, topA);
|
| + _assertHasDefinedName(locations, topB);
|
| + _assertHasDefinedName(locations, topC);
|
| + _assertHasDefinedName(locations, topD);
|
| + _assertHasDefinedName(locations, topE);
|
| + }
|
| +
|
| test_getRelations_isExtendedBy() async {
|
| _indexTestUnit(r'''
|
| class A {}
|
| @@ -103,6 +148,25 @@ main(int a, int b) {
|
| findLocationTest(locations, 'int b');
|
| }
|
|
|
| + /**
|
| + * Assert that the given list of [locations] has a [Location] corresponding
|
| + * to the [element].
|
| + */
|
| + void _assertHasDefinedName(List<Location> locations, Element element) {
|
| + String libraryUri = element.library.source.uri.toString();
|
| + String unitUri = element.source.uri.toString();
|
| + for (Location location in locations) {
|
| + if (location.libraryUri == libraryUri &&
|
| + location.unitUri == unitUri &&
|
| + location.offset == element.nameOffset &&
|
| + location.length == 0) {
|
| + return;
|
| + }
|
| + }
|
| + fail('No declaration of $element at ${element.nameOffset} in\n'
|
| + '${locations.join('\n')}');
|
| + }
|
| +
|
| void _indexTestUnit(String code) {
|
| resolveTestUnit(code);
|
| index.indexUnit(testUnit);
|
|
|