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

Unified Diff: pkg/analysis_server/test/services/index2/index2_test.dart

Issue 1771903002: Implement search for names defined in index. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/services/index2/index2.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « pkg/analysis_server/lib/src/services/index2/index2.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698