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

Unified Diff: pkg/analysis_server/test/analysis/notification_navigation_test.dart

Issue 1232683003: Issue 23640. Implement 'analysis.getNavigation' request. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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
Index: pkg/analysis_server/test/analysis/notification_navigation_test.dart
diff --git a/pkg/analysis_server/test/analysis/notification_navigation_test.dart b/pkg/analysis_server/test/analysis/notification_navigation_test.dart
index 16d1bcd27c944aa4f78acc11240418169f1dfda4..13d54cd9e540203de8394ae9b72cc0474b5f472f 100644
--- a/pkg/analysis_server/test/analysis/notification_navigation_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_navigation_test.dart
@@ -19,154 +19,7 @@ main() {
}
@reflectiveTest
-class AnalysisNotificationNavigationTest extends AbstractAnalysisTest {
- List<NavigationRegion> regions;
- List<NavigationTarget> targets;
- List<String> targetFiles;
-
- NavigationRegion testRegion;
- List<int> testTargetIndexes;
- NavigationTarget testTarget;
-
- /**
- * Validates that there is a target in [testTargetIndexes] with [file],
- * at [offset] and with the given [length].
- */
- void assertHasFileTarget(String file, int offset, int length) {
- List<NavigationTarget> testTargets =
- testTargetIndexes.map((int index) => targets[index]).toList();
- for (NavigationTarget target in testTargets) {
- if (targetFiles[target.fileIndex] == file &&
- target.offset == offset &&
- target.length == length) {
- testTarget = target;
- return;
- }
- }
- fail(
- 'Expected to find target (file=$file; offset=$offset; length=$length) in\n'
- '${testRegion} in\n' '${testTargets.join('\n')}');
- }
-
- void assertHasOperatorRegion(String regionSearch, int regionLength,
- String targetSearch, int targetLength) {
- assertHasRegion(regionSearch, regionLength);
- assertHasTarget(targetSearch, targetLength);
- }
-
- /**
- * Validates that there is a region at the offset of [search] in [testFile].
- * If [length] is not specified explicitly, then length of an identifier
- * from [search] is used.
- */
- void assertHasRegion(String search, [int length = -1]) {
- int offset = findOffset(search);
- if (length == -1) {
- length = findIdentifierLength(search);
- }
- findRegion(offset, length, true);
- }
-
- /**
- * Validates that there is a region at the offset of [search] in [testFile]
- * with the given [length] or the length of [search].
- */
- void assertHasRegionString(String search, [int length = -1]) {
- int offset = findOffset(search);
- if (length == -1) {
- length = search.length;
- }
- findRegion(offset, length, true);
- }
-
- /**
- * Validates that there is an identifier region at [regionSearch] with target
- * at [targetSearch].
- */
- void assertHasRegionTarget(String regionSearch, String targetSearch) {
- assertHasRegion(regionSearch);
- assertHasTarget(targetSearch);
- }
-
- /**
- * Validates that there is a target in [testTargets] with [testFile], at the
- * offset of [search] in [testFile], and with the given [length] or the length
- * of an leading identifier in [search].
- */
- void assertHasTarget(String search, [int length = -1]) {
- int offset = findOffset(search);
- if (length == -1) {
- length = findIdentifierLength(search);
- }
- assertHasFileTarget(testFile, offset, length);
- }
-
- /**
- * Validates that there is no a region at [search] and with the given
- * [length].
- */
- void assertNoRegion(String search, int length) {
- int offset = findOffset(search);
- findRegion(offset, length, false);
- }
-
- /**
- * Validates that there is no a region at [search] with any length.
- */
- void assertNoRegionAt(String search) {
- int offset = findOffset(search);
- findRegion(offset, -1, false);
- }
-
- /**
- * Validates that there is no a region for [search] string.
- */
- void assertNoRegionString(String search) {
- int offset = findOffset(search);
- int length = search.length;
- findRegion(offset, length, false);
- }
-
- void assertRegionsSorted() {
- int lastEnd = -1;
- for (NavigationRegion region in regions) {
- int offset = region.offset;
- if (offset < lastEnd) {
- fail('$lastEnd was expected to be > $offset in\n' + regions.join('\n'));
- }
- lastEnd = offset + region.length;
- }
- }
-
- /**
- * Finds the navigation region with the given [offset] and [length].
- * If [length] is `-1`, then it is ignored.
- *
- * If [exists] is `true`, then fails if such region does not exist.
- * Otherwise remembers this it into [testRegion].
- * Also fills [testTargets] with its targets.
- *
- * If [exists] is `false`, then fails if such region exists.
- */
- void findRegion(int offset, int length, bool exists) {
- for (NavigationRegion region in regions) {
- if (region.offset == offset &&
- (length == -1 || region.length == length)) {
- if (exists == false) {
- fail('Not expected to find (offset=$offset; length=$length) in\n'
- '${regions.join('\n')}');
- }
- testRegion = region;
- testTargetIndexes = region.targets;
- return;
- }
- }
- if (exists == true) {
- fail('Expected to find (offset=$offset; length=$length) in\n'
- '${regions.join('\n')}');
- }
- }
-
+class AnalysisNotificationNavigationTest extends AbstractNavigationTest {
Future prepareNavigation() {
addAnalysisSubscription(AnalysisService.NAVIGATION, testFile);
return waitForTasksFinished().then((_) {
@@ -785,3 +638,152 @@ void main() {
});
}
}
+
+class AbstractNavigationTest extends AbstractAnalysisTest {
+ List<NavigationRegion> regions;
+ List<NavigationTarget> targets;
+ List<String> targetFiles;
+
+ NavigationRegion testRegion;
+ List<int> testTargetIndexes;
+ NavigationTarget testTarget;
+
+ /**
+ * Validates that there is a target in [testTargetIndexes] with [file],
+ * at [offset] and with the given [length].
+ */
+ void assertHasFileTarget(String file, int offset, int length) {
+ List<NavigationTarget> testTargets =
+ testTargetIndexes.map((int index) => targets[index]).toList();
+ for (NavigationTarget target in testTargets) {
+ if (targetFiles[target.fileIndex] == file &&
+ target.offset == offset &&
+ target.length == length) {
+ testTarget = target;
+ return;
+ }
+ }
+ fail(
+ 'Expected to find target (file=$file; offset=$offset; length=$length) in\n'
+ '${testRegion} in\n' '${testTargets.join('\n')}');
+ }
+
+ void assertHasOperatorRegion(String regionSearch, int regionLength,
+ String targetSearch, int targetLength) {
+ assertHasRegion(regionSearch, regionLength);
+ assertHasTarget(targetSearch, targetLength);
+ }
+
+ /**
+ * Validates that there is a region at the offset of [search] in [testFile].
+ * If [length] is not specified explicitly, then length of an identifier
+ * from [search] is used.
+ */
+ void assertHasRegion(String search, [int length = -1]) {
+ int offset = findOffset(search);
+ if (length == -1) {
+ length = findIdentifierLength(search);
+ }
+ findRegion(offset, length, true);
+ }
+
+ /**
+ * Validates that there is a region at the offset of [search] in [testFile]
+ * with the given [length] or the length of [search].
+ */
+ void assertHasRegionString(String search, [int length = -1]) {
+ int offset = findOffset(search);
+ if (length == -1) {
+ length = search.length;
+ }
+ findRegion(offset, length, true);
+ }
+
+ /**
+ * Validates that there is an identifier region at [regionSearch] with target
+ * at [targetSearch].
+ */
+ void assertHasRegionTarget(String regionSearch, String targetSearch) {
+ assertHasRegion(regionSearch);
+ assertHasTarget(targetSearch);
+ }
+
+ /**
+ * Validates that there is a target in [testTargets] with [testFile], at the
+ * offset of [search] in [testFile], and with the given [length] or the length
+ * of an leading identifier in [search].
+ */
+ void assertHasTarget(String search, [int length = -1]) {
+ int offset = findOffset(search);
+ if (length == -1) {
+ length = findIdentifierLength(search);
+ }
+ assertHasFileTarget(testFile, offset, length);
+ }
+
+ /**
+ * Validates that there is no a region at [search] and with the given
+ * [length].
+ */
+ void assertNoRegion(String search, int length) {
+ int offset = findOffset(search);
+ findRegion(offset, length, false);
+ }
+
+ /**
+ * Validates that there is no a region at [search] with any length.
+ */
+ void assertNoRegionAt(String search) {
+ int offset = findOffset(search);
+ findRegion(offset, -1, false);
+ }
+
+ /**
+ * Validates that there is no a region for [search] string.
+ */
+ void assertNoRegionString(String search) {
+ int offset = findOffset(search);
+ int length = search.length;
+ findRegion(offset, length, false);
+ }
+
+ void assertRegionsSorted() {
+ int lastEnd = -1;
+ for (NavigationRegion region in regions) {
+ int offset = region.offset;
+ if (offset < lastEnd) {
+ fail('$lastEnd was expected to be > $offset in\n' + regions.join('\n'));
+ }
+ lastEnd = offset + region.length;
+ }
+ }
+
+ /**
+ * Finds the navigation region with the given [offset] and [length].
+ * If [length] is `-1`, then it is ignored.
+ *
+ * If [exists] is `true`, then fails if such region does not exist.
+ * Otherwise remembers this it into [testRegion].
+ * Also fills [testTargets] with its targets.
+ *
+ * If [exists] is `false`, then fails if such region exists.
+ */
+ void findRegion(int offset, int length, bool exists) {
+ for (NavigationRegion region in regions) {
+ if (region.offset == offset &&
+ (length == -1 || region.length == length)) {
+ if (exists == false) {
+ fail('Not expected to find (offset=$offset; length=$length) in\n'
+ '${regions.join('\n')}');
+ }
+ testRegion = region;
+ testTargetIndexes = region.targets;
+ return;
+ }
+ }
+ if (exists == true) {
+ fail('Expected to find (offset=$offset; length=$length) in\n'
+ '${regions.join('\n')}');
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698