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

Unified Diff: pkg/analyzer/test/src/summary/index_unit_test.dart

Issue 1753433002: Record names references in index. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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/summary/index_unit.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/summary/index_unit_test.dart
diff --git a/pkg/analyzer/test/src/summary/index_unit_test.dart b/pkg/analyzer/test/src/summary/index_unit_test.dart
index 5ff7d230b5d4d0fa4552bfa7e742a62dd72b784d..afd06d23a9398ccee6bc3a94bdd0a296ecec2200 100644
--- a/pkg/analyzer/test/src/summary/index_unit_test.dart
+++ b/pkg/analyzer/test/src/summary/index_unit_test.dart
@@ -45,6 +45,10 @@ class PackageIndexAssemblerTest extends AbstractSingleUnitTest {
return new _ElementIndexAssert(this, element);
}
+ _NameIndexAssert assertThatName(String name) {
+ return new _NameIndexAssert(this, name);
+ }
+
CompilationUnitElement importedUnit({int index: 0}) {
List<ImportElement> imports = testLibraryElement.imports;
return imports[index].importedLibrary.definingCompilationUnit;
@@ -603,6 +607,50 @@ A myVariable = null;
assertThat(element).isReferencedAt('A myVariable');
}
+ void test_usedName_isInvokedBy() {
+ verifyNoTestUnitErrors = false;
+ _indexTestUnit('''
+class A {
+ Function x;
+
+ m() {
+ x(); // 1
+ this.x(); // 2
+ y(); // 3
+ this.y(); // 4
+ }
+}
+''');
+ assertThatName('x')
+ ..isInvokedAt('x(); // 1', isQualified: false)
+ ..isInvokedAt('x(); // 2');
+ assertThatName('y')
+ ..isInvokedAt('y(); // 3', isQualified: false, isResolved: false)
+ ..isInvokedAt('y(); // 4', isResolved: false);
+ }
+
+ void test_usedName_isReferencedBy() {
+ verifyNoTestUnitErrors = false;
+ _indexTestUnit('''
+class A {
+ int x;
+
+ m() {
+ x; // 1
+ this.x; // 2
+ y; // 3
+ this.y; // 4
+ }
+}
+''');
+ assertThatName('x')
+ ..isReferencedAt('x; // 1', isQualified: false)
+ ..isReferencedAt('x; // 2');
+ assertThatName('y')
+ ..isReferencedAt('y; // 3', isQualified: false, isResolved: false)
+ ..isReferencedAt('y; // 4', isResolved: false);
+ }
+
void _assertDefinedName(String name, IndexNameKind kind, String search) {
int offset = findOffset(search);
int nameId = _getStringId(name);
@@ -639,12 +687,27 @@ A myVariable = null;
}
if (matchIndex != null &&
unitIndex.usedElementKinds[matchIndex] == expectedRelationKind) {
+ // TODO(scheglov) verify 'qualified' and 'resolved'
return;
}
_failWithIndexDump(
'not found\n$element $expectedRelationKind at $expectedLocation');
}
+ void _assertUsedName(
+ String name, IndexRelationKind kind, ExpectedLocation expectedLocation) {
+ int nameId = _getStringId(name);
+ for (int i = 0; i < unitIndex.usedNames.length; i++) {
+ if (unitIndex.usedNames[i] == nameId &&
+ unitIndex.usedNameKinds[i] == kind &&
+ unitIndex.usedNameOffsets[i] == expectedLocation.offset) {
+ // TODO(scheglov) verify 'qualified' and 'resolved'
+ return;
+ }
+ }
+ _failWithIndexDump('Not found $name $kind at $expectedLocation');
+ }
+
ExpectedLocation _expectedLocation(String search,
{int length, bool isQualified: false, bool isResolved: true}) {
int offset = findOffset(search);
@@ -771,3 +834,28 @@ class _ElementIndexAssert {
test._expectedLocation(search, length: length));
}
}
+
+class _NameIndexAssert {
+ final PackageIndexAssemblerTest test;
+ final String name;
+
+ _NameIndexAssert(this.test, this.name);
+
+ void isInvokedAt(String search,
+ {int length, bool isQualified: true, bool isResolved: true}) {
+ test._assertUsedName(
+ name,
+ IndexRelationKind.IS_INVOKED_BY,
+ test._expectedLocation(search,
+ length: length, isQualified: isQualified, isResolved: isResolved));
+ }
+
+ void isReferencedAt(String search,
+ {int length, bool isQualified: true, bool isResolved: true}) {
+ test._assertUsedName(
+ name,
+ IndexRelationKind.IS_REFERENCED_BY,
+ test._expectedLocation(search,
+ length: length, isQualified: isQualified, isResolved: isResolved));
+ }
+}
« no previous file with comments | « pkg/analyzer/lib/src/summary/index_unit.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698