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

Unified Diff: pkg/analysis_server/test/analysis_notification_navigation_test.dart

Issue 342983007: Update navigation computer to include Element instead of id. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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/analysis_server/lib/src/constants.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/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 77d0df4c485a821a6f460fd3ec38daa971705ff8..f66e65715d81922e037655922a47b09643f28155 100644
--- a/pkg/analysis_server/test/analysis_notification_navigation_test.dart
+++ b/pkg/analysis_server/test/analysis_notification_navigation_test.dart
@@ -7,6 +7,7 @@ library test.domain.analysis.notification.navigation;
import 'dart:async';
import 'package:analysis_server/src/analysis_server.dart';
+import 'package:analysis_server/src/computer/element.dart';
import 'package:analysis_server/src/constants.dart';
import 'package:analysis_server/src/protocol.dart';
import 'package:unittest/unittest.dart';
@@ -27,70 +28,29 @@ class _AnalysisNotificationNavigationTest extends AbstractAnalysisTest {
List<_NavigationRegion> regions;
_NavigationRegion testRegion;
List<_NavigationTarget> testTargets;
-
- @override
- void setUp() {
- super.setUp();
- createProject();
- }
-
- void processNotification(Notification notification) {
- if (notification.event == ANALYSIS_NAVIGATION) {
- String file = notification.getParameter(FILE);
- if (file == testFile) {
- regions = [];
- List<Map<String, Object>> regionsJson = notification.getParameter(REGIONS);
- for (Map<String, Object> regionJson in regionsJson) {
- var regionOffset = regionJson['offset'];
- var regionLength = regionJson['length'];
- List<_NavigationTarget> targets = [];
- for (Map<String, Object> targetJson in regionJson['targets']) {
- var targetFile = targetJson['file'];
- var targetOffset = targetJson['offset'];
- var targetLength = targetJson['length'];
- targets.add(new _NavigationTarget(targetFile, targetOffset, targetLength));
- }
- var region = new _NavigationRegion(regionOffset, regionLength, targets);
- regions.add(region);
- }
- }
- }
- }
-
- Future prepareNavigation(then()) {
- addAnalysisSubscription(AnalysisService.NAVIGATION, testFile);
- return waitForTasksFinished().then((_) {
- then();
- });
- }
+ _NavigationTarget testTarget;
/**
- * 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.
+ * Validates that there is a target in [testTargets] with [file], at [offset]
+ * and with the given [length].
*/
- 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;
- testTargets = region.targets;
+ void assertHasFileTarget(String file, int offset, int length) {
+ for (_NavigationTarget target in testTargets) {
+ if (target.file == file && target.offset == offset && target.length ==
+ length) {
+ testTarget = target;
return;
}
}
- if (exists == true) {
- fail('Expected to find (offset=$offset; length=$length) in\n'
- '${regions.join('\n')}');
- }
+ fail(
+ 'Expected to find target (file=$file; offset=$offset; length=$length) in\n'
+ '${testRegion} in\n' '${regions.join('\n')}');
+ }
+
+ void assertHasOperatorRegion(String regionSearch, int regionLength,
+ String targetSearch, int targetLength) {
+ assertHasRegion(regionSearch, regionLength);
+ assertHasTarget(targetSearch, targetLength);
}
/**
@@ -117,6 +77,15 @@ class _AnalysisNotificationNavigationTest extends AbstractAnalysisTest {
}
/**
+ * 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].
@@ -130,38 +99,6 @@ class _AnalysisNotificationNavigationTest extends AbstractAnalysisTest {
}
/**
- * Validates that there is a target in [testTargets] with [file], at [offset]
- * and with the given [length].
- */
- void assertHasFileTarget(String file, int offset, int length) {
- for (_NavigationTarget target in testTargets) {
- if (target.file == file &&
- target.offset == offset &&
- target.length == length) {
- return;
- }
- }
- fail('Expected to find target (file=$file; offset=$offset; length=$length) in\n'
- '${testRegion} in\n'
- '${regions.join('\n')}');
- }
-
- /**
- * Validates that there is an identifier region at [regionSearch] with target
- * at [targetSearch].
- */
- void assertHasRegionTarget(String regionSearch, String targetSearch) {
- assertHasRegion(regionSearch);
- assertHasTarget(targetSearch);
- }
-
- void assertHasOperatorRegion(String regionSearch, int regionLength,
- String targetSearch, int targetLength) {
- assertHasRegion(regionSearch, regionLength);
- assertHasTarget(targetSearch, targetLength);
- }
-
- /**
* Validates that there is no a region at [search] and with the given
* [length].
*/
@@ -187,6 +124,87 @@ class _AnalysisNotificationNavigationTest extends AbstractAnalysisTest {
findRegion(offset, length, false);
}
+ /**
+ * 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;
+ testTargets = region.targets;
+ return;
+ }
+ }
+ if (exists == true) {
+ fail('Expected to find (offset=$offset; length=$length) in\n'
+ '${regions.join('\n')}');
+ }
+ }
+
+ Future prepareNavigation(then()) {
+ addAnalysisSubscription(AnalysisService.NAVIGATION, testFile);
+ return waitForTasksFinished().then((_) {
+ then();
+ });
+ }
+
+ void processNotification(Notification notification) {
+ if (notification.event == ANALYSIS_NAVIGATION) {
+ String file = notification.getParameter(FILE);
+ if (file == testFile) {
+ regions = [];
+ List<Map<String, Object>> regionsJson = notification.getParameter(
+ REGIONS);
+ for (Map<String, Object> regionJson in regionsJson) {
+ var regionOffset = regionJson[OFFSET];
+ var regionLength = regionJson[LENGTH];
+ List<_NavigationTarget> targets = [];
+ for (Map<String, Object> targetJson in regionJson[TARGETS]) {
+ var targetFile = targetJson[FILE];
+ var targetOffset = targetJson[OFFSET];
+ var targetLength = targetJson[LENGTH];
+ var elementJson = targetJson[ELEMENT];
+ targets.add(new _NavigationTarget(targetFile, targetOffset,
+ targetLength, new Element.fromJson(elementJson)));
+ }
+ var region = new _NavigationRegion(regionOffset, regionLength,
+ targets);
+ regions.add(region);
+ }
+ }
+ }
+ }
+
+ @override
+ void setUp() {
+ super.setUp();
+ createProject();
+ }
+
+ test_afterAnalysis() {
+ addTestFile('''
+class AAA {}
+AAA aaa;
+''');
+ return waitForTasksFinished().then((_) {
+ return prepareNavigation(() {
+ assertHasRegionTarget('AAA aaa;', 'AAA {}');
+ });
+ });
+ }
+
test_constructor_named() {
addTestFile('''
class A {
@@ -234,18 +252,6 @@ class AAA {
});
}
- test_afterAnalysis() {
- addTestFile('''
-class AAA {}
-AAA aaa;
-''');
- return waitForTasksFinished().then((_) {
- return prepareNavigation(() {
- assertHasRegionTarget('AAA aaa;', 'AAA {}');
- });
- });
- }
-
test_identifier_resolved() {
addTestFile('''
class AAA {}
@@ -454,6 +460,24 @@ part "test_unit.dart";
// assertNoRegionString('part "test_unit.dart"');
// });
}
+
+ test_targetElement() {
+ addTestFile('''
+class AAA {}
+main() {
+ AAA aaa = null;
+}
+''');
+ return prepareNavigation(() {
+ assertHasRegionTarget('AAA aaa', 'AAA {}');
+ Element element = testTarget.element;
+ expect(element.kind, ElementKind.CLASS);
+ expect(element.name, 'AAA');
+ expect(element.isAbstract, false);
+ expect(element.parameters, isNull);
+ expect(element.returnType, isNull);
+ });
+ }
}
@@ -470,6 +494,7 @@ class _NavigationTarget {
final String file;
final int offset;
final int length;
+ final Element element;
- _NavigationTarget(this.file, this.offset, this.length);
+ _NavigationTarget(this.file, this.offset, this.length, this.element);
}
« no previous file with comments | « pkg/analysis_server/lib/src/constants.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698