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

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

Issue 649853004: Issue 21377. Specify that navigation regions are sorted and implement it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 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';
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 /** 117 /**
118 * Validates that there is no a region for [search] string. 118 * Validates that there is no a region for [search] string.
119 */ 119 */
120 void assertNoRegionString(String search) { 120 void assertNoRegionString(String search) {
121 int offset = findOffset(search); 121 int offset = findOffset(search);
122 int length = search.length; 122 int length = search.length;
123 findRegion(offset, length, false); 123 findRegion(offset, length, false);
124 } 124 }
125 125
126 void assertRegionsSorted() {
127 int lastEnd = -1;
128 for (NavigationRegion region in regions) {
129 int offset = region.offset;
130 if (offset < lastEnd) {
131 fail('$lastEnd was expected to be > $offset in\n' + regions.join('\n'));
132 }
133 lastEnd = offset + region.length;
134 }
135 }
136
126 /** 137 /**
127 * Finds the navigation region with the given [offset] and [length]. 138 * Finds the navigation region with the given [offset] and [length].
128 * If [length] is `-1`, then it is ignored. 139 * If [length] is `-1`, then it is ignored.
129 * 140 *
130 * If [exists] is `true`, then fails if such region does not exist. 141 * If [exists] is `true`, then fails if such region does not exist.
131 * Otherwise remembers this it into [testRegion]. 142 * Otherwise remembers this it into [testRegion].
132 * Also fills [testTargets] with its targets. 143 * Also fills [testTargets] with its targets.
133 * 144 *
134 * If [exists] is `false`, then fails if such region exists. 145 * If [exists] is `false`, then fails if such region exists.
135 */ 146 */
(...skipping 13 matching lines...) Expand all
149 } 160 }
150 if (exists == true) { 161 if (exists == true) {
151 fail( 162 fail(
152 'Expected to find (offset=$offset; length=$length) in\n' 163 'Expected to find (offset=$offset; length=$length) in\n'
153 '${regions.join('\n')}'); 164 '${regions.join('\n')}');
154 } 165 }
155 } 166 }
156 167
157 Future prepareNavigation() { 168 Future prepareNavigation() {
158 addAnalysisSubscription(AnalysisService.NAVIGATION, testFile); 169 addAnalysisSubscription(AnalysisService.NAVIGATION, testFile);
159 return waitForTasksFinished(); 170 return waitForTasksFinished().then((_) {
171 assertRegionsSorted();
172 });
160 } 173 }
161 174
162 void processNotification(Notification notification) { 175 void processNotification(Notification notification) {
163 if (notification.event == ANALYSIS_NAVIGATION) { 176 if (notification.event == ANALYSIS_NAVIGATION) {
164 var params = new AnalysisNavigationParams.fromNotification(notification); 177 var params = new AnalysisNavigationParams.fromNotification(notification);
165 if (params.file == testFile) { 178 if (params.file == testFile) {
166 regions = params.regions; 179 regions = params.regions;
167 } 180 }
168 } 181 }
169 } 182 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 addTestFile(''' 289 addTestFile('''
277 main() { 290 main() {
278 print(vvv); 291 print(vvv);
279 } 292 }
280 '''); 293 ''');
281 return prepareNavigation().then((_) { 294 return prepareNavigation().then((_) {
282 assertNoRegionString('vvv'); 295 assertNoRegionString('vvv');
283 }); 296 });
284 } 297 }
285 298
299 test_identifier_whenStrayImportDirective() {
300 addTestFile('''
301 main() {
302 int aaa = 42;
303 print(aaa);
304 }
305 import 'dart:math';
306 ''');
307 return prepareNavigation().then((_) {
308 assertHasRegionTarget('aaa);', 'aaa = 42');
309 });
310 }
311
286 test_instanceCreation_implicit() { 312 test_instanceCreation_implicit() {
287 addTestFile(''' 313 addTestFile('''
288 class A { 314 class A {
289 } 315 }
290 main() { 316 main() {
291 new A(); 317 new A();
292 } 318 }
293 '''); 319 ''');
294 return prepareNavigation().then((_) { 320 return prepareNavigation().then((_) {
295 findRegion(findOffset('new A'), 'new A'.length, true); 321 findRegion(findOffset('new A'), 'new A'.length, true);
296 assertHasTarget('A {'); 322 assertHasTarget('A {');
297 }); 323 });
298 } 324 }
299 325
300 test_instanceCreation_named() { 326 test_instanceCreation_named() {
301 addTestFile(''' 327 addTestFile('''
302 class A { 328 class A {
303 A.named() {} 329 A.named() {}
304 } 330 }
305 main() { 331 main() {
306 new A.named(); 332 new A.named();
307 } 333 }
308 '''); 334 ''');
309 return prepareNavigation().then((_) { 335 return prepareNavigation().then((_) {
310 { 336 {
311 findRegion(findOffset('new '), 'new '.length, true); 337 findRegion(findOffset('new '), 'new'.length, true);
312 assertHasTarget('named() {}'); 338 assertHasTarget('named() {}');
313 } 339 }
314 { 340 {
315 findRegion(findOffset('A.named();'), 'A'.length, true); 341 findRegion(findOffset('A.named();'), 'A'.length, true);
316 assertHasTarget('A {'); 342 assertHasTarget('A {');
317 } 343 }
318 { 344 {
319 findRegion(findOffset('.named();'), '.named'.length, true); 345 findRegion(findOffset('.named();'), '.named'.length, true);
320 assertHasTarget('named() {}'); 346 assertHasTarget('named() {}');
321 } 347 }
322 }); 348 });
323 } 349 }
324 350
325 test_instanceCreation_unnamed() { 351 test_instanceCreation_unnamed() {
326 addTestFile(''' 352 addTestFile('''
327 class A { 353 class A {
328 A() {} 354 A() {}
329 } 355 }
330 main() { 356 main() {
331 new A(); 357 new A();
332 } 358 }
333 '''); 359 ''');
334 return prepareNavigation().then((_) { 360 return prepareNavigation().then((_) {
335 { 361 {
336 findRegion(findOffset('new '), 'new '.length, true); 362 findRegion(findOffset('new '), 'new'.length, true);
337 assertHasTarget('A() {}', 0); 363 assertHasTarget('A() {}', 0);
338 } 364 }
339 { 365 {
340 findRegion(findOffset('A();'), 'A'.length, true); 366 findRegion(findOffset('A();'), 'A'.length, true);
341 assertHasTarget('A {'); 367 assertHasTarget('A {');
342 } 368 }
343 }); 369 });
344 } 370 }
345 371
346 test_operator_arithmetic() { 372 test_operator_arithmetic() {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 test_type_void() { 537 test_type_void() {
512 addTestFile(''' 538 addTestFile('''
513 void main() { 539 void main() {
514 } 540 }
515 '''); 541 ''');
516 return prepareNavigation().then((_) { 542 return prepareNavigation().then((_) {
517 assertNoRegionAt('void'); 543 assertNoRegionAt('void');
518 }); 544 });
519 } 545 }
520 } 546 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698