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

Unified Diff: pkg/analyzer/test/src/dart/analysis/search_test.dart

Issue 2956193003: Implement search for direct subtypes in a single AnalysisDriver. (Closed)
Patch Set: Created 3 years, 6 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/analyzer/lib/src/dart/analysis/search.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/dart/analysis/search_test.dart
diff --git a/pkg/analyzer/test/src/dart/analysis/search_test.dart b/pkg/analyzer/test/src/dart/analysis/search_test.dart
index a732388a5b7a801ae08b2722e4534c1ec8725014..29f5a18a601d3f6c8204209a3101af911d52587d 100644
--- a/pkg/analyzer/test/src/dart/analysis/search_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/search_test.dart
@@ -1082,6 +1082,87 @@ class C implements T {} // C
await _verifyReferences(element, expected);
}
+ test_subtypes() async {
+ await _resolveTestUnit('''
+class A {}
+
+class B extends A {
+ void methodB() {}
+}
+
+class C extends Object with A {
+ void methodC() {}
+}
+
+class D implements A {
+ void methodD() {}
+}
+
+class E extends B {
+ void methodE() {}
+}
+
+class F {}
+''');
+ ClassElement a = _findElement('A');
+
+ // Search by 'type'.
+ List<SubtypeResult> subtypes = await driver.search.subtypes(type: a);
+ expect(subtypes, hasLength(3));
+
+ SubtypeResult b = subtypes.singleWhere((r) => r.name == 'B');
+ SubtypeResult c = subtypes.singleWhere((r) => r.name == 'C');
+ SubtypeResult d = subtypes.singleWhere((r) => r.name == 'D');
+
+ expect(b.members, ['methodB']);
+ expect(c.members, ['methodC']);
+ expect(d.members, ['methodD']);
+
+ // Search by 'id'.
+ {
+ List<SubtypeResult> subtypes = await driver.search.subtypes(subtype: b);
+ expect(subtypes, hasLength(1));
+ SubtypeResult e = subtypes.singleWhere((r) => r.name == 'E');
+ expect(e.members, ['methodE']);
+ }
+ }
+
+ test_subtypes_files() async {
+ String pathB = _p('$testProject/b.dart');
+ String pathC = _p('$testProject/c.dart');
+ provider.newFile(
+ pathB,
+ r'''
+import 'test.dart';
+class B extends A {}
+''');
+ provider.newFile(
+ pathC,
+ r'''
+import 'test.dart';
+class C extends A {}
+class D {}
+''');
+
+ await _resolveTestUnit('''
+class A {}
+''');
+ ClassElement a = _findElement('A');
+
+ driver.addFile(pathB);
+ driver.addFile(pathC);
+ await scheduler.waitForIdle();
+
+ List<SubtypeResult> subtypes = await driver.search.subtypes(type: a);
+ expect(subtypes, hasLength(2));
+
+ SubtypeResult b = subtypes.singleWhere((r) => r.name == 'B');
+ SubtypeResult c = subtypes.singleWhere((r) => r.name == 'C');
+
+ expect(b.id, endsWith('b.dart;B'));
+ expect(c.id, endsWith('c.dart;C'));
+ }
+
test_topLevelElements() async {
await _resolveTestUnit('''
class A {} // A
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/search.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698