OLD | NEW |
---|---|
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 void assertHasRegion(String search, [int length = -1]) { | 60 void assertHasRegion(String search, [int length = -1]) { |
61 int offset = findOffset(search); | 61 int offset = findOffset(search); |
62 if (length == -1) { | 62 if (length == -1) { |
63 length = findIdentifierLength(search); | 63 length = findIdentifierLength(search); |
64 } | 64 } |
65 findRegion(offset, length, true); | 65 findRegion(offset, length, true); |
66 } | 66 } |
67 | 67 |
68 /** | 68 /** |
69 * Validates that there is a region at the offset of [search] in [testFile] | 69 * Validates that there is a region at the offset of [search] in [testFile] |
70 * with the length of [search]. | 70 * with the length of [search]. |
Brian Wilkerson
2014/11/10 21:04:23
The comment needs to be updated.
scheglov
2014/11/11 03:01:06
Done.
| |
71 */ | 71 */ |
72 void assertHasRegionString(String search) { | 72 void assertHasRegionString(String search, [int length = -1]) { |
73 int offset = findOffset(search); | 73 int offset = findOffset(search); |
74 int length = search.length; | 74 if (length == -1) { |
75 length = search.length; | |
76 } | |
75 findRegion(offset, length, true); | 77 findRegion(offset, length, true); |
76 } | 78 } |
77 | 79 |
78 /** | 80 /** |
79 * Validates that there is an identifier region at [regionSearch] with target | 81 * Validates that there is an identifier region at [regionSearch] with target |
80 * at [targetSearch]. | 82 * at [targetSearch]. |
81 */ | 83 */ |
82 void assertHasRegionTarget(String regionSearch, String targetSearch) { | 84 void assertHasRegionTarget(String regionSearch, String targetSearch) { |
83 assertHasRegion(regionSearch); | 85 assertHasRegion(regionSearch); |
84 assertHasTarget(targetSearch); | 86 assertHasTarget(targetSearch); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 /** | 139 /** |
138 * Finds the navigation region with the given [offset] and [length]. | 140 * Finds the navigation region with the given [offset] and [length]. |
139 * If [length] is `-1`, then it is ignored. | 141 * If [length] is `-1`, then it is ignored. |
140 * | 142 * |
141 * If [exists] is `true`, then fails if such region does not exist. | 143 * If [exists] is `true`, then fails if such region does not exist. |
142 * Otherwise remembers this it into [testRegion]. | 144 * Otherwise remembers this it into [testRegion]. |
143 * Also fills [testTargets] with its targets. | 145 * Also fills [testTargets] with its targets. |
144 * | 146 * |
145 * If [exists] is `false`, then fails if such region exists. | 147 * If [exists] is `false`, then fails if such region exists. |
146 */ | 148 */ |
147 void findRegion(int offset, int length, [bool exists]) { | 149 void findRegion(int offset, int length, bool exists) { |
148 for (NavigationRegion region in regions) { | 150 for (NavigationRegion region in regions) { |
149 if (region.offset == offset && | 151 if (region.offset == offset && |
150 (length == -1 || region.length == length)) { | 152 (length == -1 || region.length == length)) { |
151 if (exists == false) { | 153 if (exists == false) { |
152 fail( | 154 fail( |
153 'Not expected to find (offset=$offset; length=$length) in\n' | 155 'Not expected to find (offset=$offset; length=$length) in\n' |
154 '${regions.join('\n')}'); | 156 '${regions.join('\n')}'); |
155 } | 157 } |
156 testRegion = region; | 158 testRegion = region; |
157 testTargets = region.targets; | 159 testTargets = region.targets; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 | 313 |
312 test_instanceCreation_implicit() { | 314 test_instanceCreation_implicit() { |
313 addTestFile(''' | 315 addTestFile(''' |
314 class A { | 316 class A { |
315 } | 317 } |
316 main() { | 318 main() { |
317 new A(); | 319 new A(); |
318 } | 320 } |
319 '''); | 321 '''); |
320 return prepareNavigation().then((_) { | 322 return prepareNavigation().then((_) { |
321 { | 323 assertHasRegionString('new A'); |
322 findRegion(findOffset('new A'), 'new'.length, true); | 324 assertHasTarget('A {'); |
323 assertHasTarget('A {'); | |
324 } | |
325 { | |
326 findRegion(findOffset('A()'), 'A'.length, true); | |
327 assertHasTarget('A {'); | |
328 } | |
329 }); | 325 }); |
330 } | 326 } |
331 | 327 |
332 test_instanceCreation_implicit_withTypeArgument() { | 328 test_instanceCreation_implicit_withTypeArgument() { |
333 addTestFile(''' | 329 addTestFile(''' |
334 class A {} | 330 class A {} |
335 class B<T> { | 331 class B<T> {} |
336 } | |
337 main() { | 332 main() { |
338 new B<A>(); | 333 new B<A>(); |
339 } | 334 } |
340 '''); | 335 '''); |
341 return prepareNavigation().then((_) { | 336 return prepareNavigation().then((_) { |
342 { | 337 { |
343 findRegion(findOffset('new B'), 'new'.length, true); | 338 assertHasRegion('new B<A>', 'new B'.length); |
344 assertHasTarget('B<T> {'); | 339 assertHasTarget('B<T> {'); |
345 } | 340 } |
346 { | 341 { |
347 findRegion(findOffset('A>();'), 'A'.length, true); | 342 assertHasRegion('A>();', 'A'.length); |
348 assertHasTarget('A {'); | 343 assertHasTarget('A {'); |
349 } | 344 } |
350 }); | 345 }); |
351 } | 346 } |
352 | 347 |
353 test_instanceCreation_named() { | 348 test_instanceCreation_named() { |
354 addTestFile(''' | 349 addTestFile(''' |
355 class A { | 350 class A { |
356 A.named() {} | 351 A.named() {} |
357 } | 352 } |
358 main() { | 353 main() { |
359 new A.named(); | 354 new A.named(); |
360 } | 355 } |
361 '''); | 356 '''); |
362 return prepareNavigation().then((_) { | 357 return prepareNavigation().then((_) { |
363 { | 358 assertHasRegionString('new A.named'); |
364 findRegion(findOffset('new '), 'new'.length, true); | 359 assertHasTarget('named() {}'); |
365 assertHasTarget('named() {}'); | |
366 } | |
367 { | |
368 findRegion(findOffset('A.named();'), 'A'.length, true); | |
369 assertHasTarget('A {'); | |
370 } | |
371 { | |
372 findRegion(findOffset('.named();'), '.named'.length, true); | |
373 assertHasTarget('named() {}'); | |
374 } | |
375 }); | 360 }); |
376 } | 361 } |
377 | 362 |
378 test_instanceCreation_named_withTypeArgument() { | 363 test_instanceCreation_named_withTypeArgument() { |
379 addTestFile(''' | 364 addTestFile(''' |
380 class A {} | 365 class A {} |
381 class B<T> { | 366 class B<T> { |
382 A.named() {} | 367 A.named() {} |
383 } | 368 } |
384 main() { | 369 main() { |
385 new B<A>.named(); | 370 new B<A>.named(); |
386 } | 371 } |
387 '''); | 372 '''); |
388 return prepareNavigation().then((_) { | 373 return prepareNavigation().then((_) { |
389 { | 374 { |
390 findRegion(findOffset('new '), 'new'.length, true); | 375 assertHasRegionString('new B'); |
391 assertHasTarget('named() {}'); | 376 assertHasTarget('named() {}'); |
392 } | 377 } |
393 { | 378 { |
394 findRegion(findOffset('B<A>.named();'), 'B'.length, true); | 379 assertHasRegion('A>.named'); |
395 assertHasTarget('B<T> {'); | 380 assertHasTarget('A {'); |
396 } | 381 } |
397 { | 382 { |
398 findRegion(findOffset('.named();'), '.named'.length, true); | 383 assertHasRegion('.named();', '.named'.length); |
399 assertHasTarget('named() {}'); | 384 assertHasTarget('named() {}'); |
400 } | 385 } |
401 { | |
402 findRegion(findOffset('A>.named();'), 'A'.length, true); | |
403 assertHasTarget('A {'); | |
404 } | |
405 }); | 386 }); |
406 } | 387 } |
407 | 388 |
408 test_instanceCreation_unnamed() { | 389 test_instanceCreation_unnamed() { |
409 addTestFile(''' | 390 addTestFile(''' |
410 class A { | 391 class A { |
411 A() {} | 392 A() {} |
412 } | 393 } |
413 main() { | 394 main() { |
414 new A(); | 395 new A(); |
415 } | 396 } |
416 '''); | 397 '''); |
417 return prepareNavigation().then((_) { | 398 return prepareNavigation().then((_) { |
418 { | 399 assertHasRegionString('new A'); |
419 findRegion(findOffset('new '), 'new'.length, true); | 400 assertHasTarget('A() {}', 0); |
420 assertHasTarget('A() {}', 0); | |
421 } | |
422 { | |
423 findRegion(findOffset('A();'), 'A'.length, true); | |
424 assertHasTarget('A {'); | |
425 } | |
426 }); | 401 }); |
427 } | 402 } |
428 | 403 |
429 test_instanceCreation_unnamed_withTypeArgument() { | 404 test_instanceCreation_unnamed_withTypeArgument() { |
430 addTestFile(''' | 405 addTestFile(''' |
431 class A {} | 406 class A {} |
432 class B<T> { | 407 class B<T> { |
433 B() {} | 408 B() {} |
434 } | 409 } |
435 main() { | 410 main() { |
436 new B<A>(); | 411 new B<A>(); |
437 } | 412 } |
438 '''); | 413 '''); |
439 return prepareNavigation().then((_) { | 414 return prepareNavigation().then((_) { |
440 { | 415 { |
441 findRegion(findOffset('new '), 'new'.length, true); | 416 assertHasRegionString('new B'); |
442 assertHasTarget('B() {}', 0); | 417 assertHasTarget('B() {}', 0); |
443 } | 418 } |
444 { | 419 { |
445 findRegion(findOffset('B<A>();'), 'B'.length, true); | 420 assertHasRegion('A>();'); |
446 assertHasTarget('B<T> {'); | |
447 } | |
448 { | |
449 findRegion(findOffset('A>();'), 'A'.length, true); | |
450 assertHasTarget('A {'); | 421 assertHasTarget('A {'); |
451 } | 422 } |
452 }); | 423 }); |
453 } | 424 } |
454 | 425 |
455 test_multiplyDefinedElement() { | 426 test_multiplyDefinedElement() { |
456 addFile('$projectPath/bin/libA.dart', 'library A; int TEST = 1;'); | 427 addFile('$projectPath/bin/libA.dart', 'library A; int TEST = 1;'); |
457 addFile('$projectPath/bin/libB.dart', 'library B; int TEST = 2;'); | 428 addFile('$projectPath/bin/libB.dart', 'library B; int TEST = 2;'); |
458 addTestFile(''' | 429 addTestFile(''' |
459 import 'libA.dart'; | 430 import 'libA.dart'; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 test_type_void() { | 606 test_type_void() { |
636 addTestFile(''' | 607 addTestFile(''' |
637 void main() { | 608 void main() { |
638 } | 609 } |
639 '''); | 610 '''); |
640 return prepareNavigation().then((_) { | 611 return prepareNavigation().then((_) { |
641 assertNoRegionAt('void'); | 612 assertNoRegionAt('void'); |
642 }); | 613 }); |
643 } | 614 } |
644 } | 615 } |
OLD | NEW |