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

Side by Side Diff: pkg/analysis_server/test/analysis/notification_navigation_test.dart

Issue 766323002: Compressed/optimized navigation notification. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updates for review comments. Created 6 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.analysis.notification.navigation; 5 library test.analysis.notification.navigation;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_server/src/protocol.dart'; 10 import 'package:analysis_server/src/protocol.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 12
13 import '../analysis_abstract.dart'; 13 import '../analysis_abstract.dart';
14 import '../reflective_tests.dart'; 14 import '../reflective_tests.dart';
15 15
16 16
17 main() { 17 main() {
18 groupSep = ' | '; 18 groupSep = ' | ';
19 runReflectiveTests(AnalysisNotificationNavigationTest); 19 runReflectiveTests(AnalysisNotificationNavigationTest);
20 } 20 }
21 21
22 22
23 @ReflectiveTestCase() 23 @ReflectiveTestCase()
24 class AnalysisNotificationNavigationTest extends AbstractAnalysisTest { 24 class AnalysisNotificationNavigationTest extends AbstractAnalysisTest {
25 List<NavigationRegion> regions; 25 List<NavigationRegion> regions;
26 List<NavigationTarget> targets;
27 List<String> targetFiles;
28
26 NavigationRegion testRegion; 29 NavigationRegion testRegion;
27 List<Element> testTargets; 30 List<int> testTargetIndexes;
28 Element testTarget; 31 NavigationTarget testTarget;
29 32
30 /** 33 /**
31 * Validates that there is a target in [testTargets] with [file], at [offset] 34 * Validates that there is a target in [testTargetIndexes] with [file],
32 * and with the given [length]. 35 * at [offset] and with the given [length].
33 */ 36 */
34 void assertHasFileTarget(String file, int offset, int length) { 37 void assertHasFileTarget(String file, int offset, int length) {
35 for (Element target in testTargets) { 38 List<NavigationTarget> testTargets =
36 Location location = target.location; 39 testTargetIndexes.map((int index) => targets[index]).toList();
37 if (location.file == file && 40 for (NavigationTarget target in testTargets) {
38 location.offset == offset && 41 if (targetFiles[target.fileIndex] == file &&
39 location.length == length) { 42 target.offset == offset &&
43 target.length == length) {
40 testTarget = target; 44 testTarget = target;
41 return; 45 return;
42 } 46 }
43 } 47 }
44 fail( 48 fail(
45 'Expected to find target (file=$file; offset=$offset; length=$length) in \n' 49 'Expected to find target (file=$file; offset=$offset; length=$length) in \n'
46 '${testRegion} in\n' '${testTargets.join('\n')}'); 50 '${testRegion} in\n' '${testTargets.join('\n')}');
47 } 51 }
48 52
49 void assertHasOperatorRegion(String regionSearch, int regionLength, 53 void assertHasOperatorRegion(String regionSearch, int regionLength,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 void findRegion(int offset, int length, bool exists) { 153 void findRegion(int offset, int length, bool exists) {
150 for (NavigationRegion region in regions) { 154 for (NavigationRegion region in regions) {
151 if (region.offset == offset && 155 if (region.offset == offset &&
152 (length == -1 || region.length == length)) { 156 (length == -1 || region.length == length)) {
153 if (exists == false) { 157 if (exists == false) {
154 fail( 158 fail(
155 'Not expected to find (offset=$offset; length=$length) in\n' 159 'Not expected to find (offset=$offset; length=$length) in\n'
156 '${regions.join('\n')}'); 160 '${regions.join('\n')}');
157 } 161 }
158 testRegion = region; 162 testRegion = region;
159 testTargets = region.targets; 163 testTargetIndexes = region.targets;
160 return; 164 return;
161 } 165 }
162 } 166 }
163 if (exists == true) { 167 if (exists == true) {
164 fail( 168 fail(
165 'Expected to find (offset=$offset; length=$length) in\n' 169 'Expected to find (offset=$offset; length=$length) in\n'
166 '${regions.join('\n')}'); 170 '${regions.join('\n')}');
167 } 171 }
168 } 172 }
169 173
170 Future prepareNavigation() { 174 Future prepareNavigation() {
171 addAnalysisSubscription(AnalysisService.NAVIGATION, testFile); 175 addAnalysisSubscription(AnalysisService.NAVIGATION, testFile);
172 return waitForTasksFinished().then((_) { 176 return waitForTasksFinished().then((_) {
173 assertRegionsSorted(); 177 assertRegionsSorted();
174 }); 178 });
175 } 179 }
176 180
177 void processNotification(Notification notification) { 181 void processNotification(Notification notification) {
178 if (notification.event == ANALYSIS_NAVIGATION) { 182 if (notification.event == ANALYSIS_NAVIGATION) {
179 var params = new AnalysisNavigationParams.fromNotification(notification); 183 var params = new AnalysisNavigationParams.fromNotification(notification);
180 if (params.file == testFile) { 184 if (params.file == testFile) {
181 regions = params.regions; 185 regions = params.regions;
186 targets = params.targets;
187 targetFiles = params.files;
182 } 188 }
183 } 189 }
184 } 190 }
185 191
186 @override 192 @override
187 void setUp() { 193 void setUp() {
188 super.setUp(); 194 super.setUp();
189 createProject(); 195 createProject();
190 } 196 }
191 197
192 test_afterAnalysis() { 198 test_afterAnalysis() {
193 addTestFile(''' 199 addTestFile('''
194 class AAA {} 200 class AAA {}
195 AAA aaa; 201 AAA aaa;
196 '''); 202 ''');
197 return waitForTasksFinished().then((_) { 203 return waitForTasksFinished().then((_) {
198 return prepareNavigation().then((_) { 204 return prepareNavigation().then((_) {
199 assertHasRegionTarget('AAA aaa;', 'AAA {}'); 205 assertHasRegionTarget('AAA aaa;', 'AAA {}');
200 }); 206 });
201 }); 207 });
202 } 208 }
203 209
204 test_class_fromSDK() { 210 test_class_fromSDK() {
205 addTestFile(''' 211 addTestFile('''
206 int V = 42; 212 int V = 42;
207 '''); 213 ''');
208 return prepareNavigation().then((_) { 214 return prepareNavigation().then((_) {
209 assertHasRegion('int V'); 215 assertHasRegion('int V');
210 Element target = testTargets[0]; 216 int targetIndex = testTargetIndexes[0];
211 Location location = target.location; 217 NavigationTarget target = targets[targetIndex];
212 expect(location.startLine, greaterThan(0)); 218 expect(target.startLine, greaterThan(0));
213 expect(location.startColumn, greaterThan(0)); 219 expect(target.startColumn, greaterThan(0));
214 }); 220 });
215 } 221 }
216 222
217 test_constructor_named() { 223 test_constructor_named() {
218 addTestFile(''' 224 addTestFile('''
219 class A { 225 class A {
220 A.named(BBB p) {} 226 A.named(BBB p) {}
221 } 227 }
222 class BBB {} 228 class BBB {}
223 '''); 229 ''');
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 test_targetElement() { 584 test_targetElement() {
579 addTestFile(''' 585 addTestFile('''
580 class AAA {} 586 class AAA {}
581 main() { 587 main() {
582 AAA aaa = null; 588 AAA aaa = null;
583 } 589 }
584 '''); 590 ''');
585 return prepareNavigation().then((_) { 591 return prepareNavigation().then((_) {
586 assertHasRegionTarget('AAA aaa', 'AAA {}'); 592 assertHasRegionTarget('AAA aaa', 'AAA {}');
587 expect(testTarget.kind, ElementKind.CLASS); 593 expect(testTarget.kind, ElementKind.CLASS);
588 expect(testTarget.name, 'AAA');
589 expect(testTarget.isAbstract, false);
590 expect(testTarget.parameters, isNull);
591 expect(testTarget.returnType, isNull);
592 }); 594 });
593 } 595 }
594 596
595 test_type_dynamic() { 597 test_type_dynamic() {
596 addTestFile(''' 598 addTestFile('''
597 main() { 599 main() {
598 dynamic v = null; 600 dynamic v = null;
599 } 601 }
600 '''); 602 ''');
601 return prepareNavigation().then((_) { 603 return prepareNavigation().then((_) {
602 assertNoRegionAt('dynamic'); 604 assertNoRegionAt('dynamic');
603 }); 605 });
604 } 606 }
605 607
606 test_type_void() { 608 test_type_void() {
607 addTestFile(''' 609 addTestFile('''
608 void main() { 610 void main() {
609 } 611 }
610 '''); 612 ''');
611 return prepareNavigation().then((_) { 613 return prepareNavigation().then((_) {
612 assertNoRegionAt('void'); 614 assertNoRegionAt('void');
613 }); 615 });
614 } 616 }
615 } 617 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/protocol_server.dart ('k') | pkg/analysis_server/test/integration/analysis/navigation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698