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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:analysis_server/protocol/protocol.dart'; | 7 import 'package:analysis_server/protocol/protocol.dart'; |
8 import 'package:analysis_server/protocol/protocol_generated.dart'; | 8 import 'package:analysis_server/protocol/protocol_generated.dart'; |
9 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 9 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
11 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
12 | 12 |
13 import 'abstract_search_domain.dart'; | 13 import 'abstract_search_domain.dart'; |
14 | 14 |
15 main() { | 15 main() { |
16 defineReflectiveSuite(() { | 16 defineReflectiveSuite(() { |
17 defineReflectiveTests(ElementReferencesTest); | 17 defineReflectiveTests(ElementReferencesTest); |
18 }); | 18 }); |
19 } | 19 } |
20 | 20 |
21 @reflectiveTest | 21 @reflectiveTest |
22 class ElementReferencesTest extends AbstractSearchDomainTest { | 22 class ElementReferencesTest extends AbstractSearchDomainTest { |
23 Element searchElement; | 23 Element searchElement; |
24 | 24 |
25 @override | |
26 bool get enableNewAnalysisDriver => false; | |
27 | |
28 void assertHasRef(SearchResultKind kind, String search, bool isPotential) { | 25 void assertHasRef(SearchResultKind kind, String search, bool isPotential) { |
29 assertHasResult(kind, search); | 26 assertHasResult(kind, search); |
30 expect(result.isPotential, isPotential); | 27 expect(result.isPotential, isPotential); |
31 } | 28 } |
32 | 29 |
33 Future<Null> findElementReferences( | 30 Future<Null> findElementReferences( |
34 String search, bool includePotential) async { | 31 String search, bool includePotential) async { |
35 int offset = findOffset(search); | 32 int offset = findOffset(search); |
36 await waitForTasksFinished(); | 33 await waitForTasksFinished(); |
37 Request request = new SearchFindElementReferencesParams( | 34 Request request = new SearchFindElementReferencesParams( |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 396 |
400 test_oneUnit_zeroLibraries() async { | 397 test_oneUnit_zeroLibraries() async { |
401 addTestFile(''' | 398 addTestFile(''' |
402 part of lib; | 399 part of lib; |
403 fff(p) {} | 400 fff(p) {} |
404 main() { | 401 main() { |
405 fff(10); | 402 fff(10); |
406 } | 403 } |
407 '''); | 404 '''); |
408 await findElementReferences('fff(p) {}', false); | 405 await findElementReferences('fff(p) {}', false); |
409 expect(results, isEmpty); | 406 expect(results, hasLength(1)); |
| 407 assertHasResult(SearchResultKind.INVOCATION, 'fff(10);'); |
410 } | 408 } |
411 | 409 |
412 test_parameter() async { | 410 test_parameter() async { |
413 addTestFile(''' | 411 addTestFile(''' |
414 main(ppp) { | 412 main(ppp) { |
415 print(ppp); | 413 print(ppp); |
416 ppp += 3; | 414 ppp += 3; |
417 ppp = 2; | 415 ppp = 2; |
418 ppp(); | 416 ppp(); |
419 } | 417 } |
420 '''); | 418 '''); |
421 await findElementReferences('ppp) {', false); | 419 await findElementReferences('ppp) {', false); |
422 expect(searchElement.kind, ElementKind.PARAMETER); | 420 expect(searchElement.kind, ElementKind.PARAMETER); |
423 expect(results, hasLength(4)); | 421 expect(results, hasLength(4)); |
424 assertHasResult(SearchResultKind.READ, 'ppp);'); | 422 assertHasResult(SearchResultKind.READ, 'ppp);'); |
425 assertHasResult(SearchResultKind.READ_WRITE, 'ppp += 3'); | 423 assertHasResult(SearchResultKind.READ_WRITE, 'ppp += 3'); |
426 assertHasResult(SearchResultKind.WRITE, 'ppp = 2'); | 424 assertHasResult(SearchResultKind.WRITE, 'ppp = 2'); |
427 assertHasResult(SearchResultKind.INVOCATION, 'ppp();'); | 425 assertHasResult(SearchResultKind.INVOCATION, 'ppp();'); |
428 } | 426 } |
429 | 427 |
| 428 @failingTest |
430 test_path_inConstructor_named() async { | 429 test_path_inConstructor_named() async { |
| 430 // The path does not contain the first expected element. |
431 addTestFile(''' | 431 addTestFile(''' |
432 library my_lib; | 432 library my_lib; |
433 class A {} | 433 class A {} |
434 class B { | 434 class B { |
435 B.named() { | 435 B.named() { |
436 A a = null; | 436 A a = null; |
437 } | 437 } |
438 } | 438 } |
439 '''); | 439 '''); |
440 await findElementReferences('A {}', false); | 440 await findElementReferences('A {}', false); |
441 assertHasResult(SearchResultKind.REFERENCE, 'A a = null;'); | 441 assertHasResult(SearchResultKind.REFERENCE, 'A a = null;'); |
442 expect( | 442 expect( |
443 getPathString(result.path), | 443 getPathString(result.path), |
444 ''' | 444 ''' |
445 LOCAL_VARIABLE a | 445 LOCAL_VARIABLE a |
446 CONSTRUCTOR named | 446 CONSTRUCTOR named |
447 CLASS B | 447 CLASS B |
448 COMPILATION_UNIT test.dart | 448 COMPILATION_UNIT test.dart |
449 LIBRARY my_lib'''); | 449 LIBRARY my_lib'''); |
450 } | 450 } |
451 | 451 |
| 452 @failingTest |
452 test_path_inConstructor_unnamed() async { | 453 test_path_inConstructor_unnamed() async { |
| 454 // The path does not contain the first expected element. |
453 addTestFile(''' | 455 addTestFile(''' |
454 library my_lib; | 456 library my_lib; |
455 class A {} | 457 class A {} |
456 class B { | 458 class B { |
457 B() { | 459 B() { |
458 A a = null; | 460 A a = null; |
459 } | 461 } |
460 } | 462 } |
461 '''); | 463 '''); |
462 await findElementReferences('A {}', false); | 464 await findElementReferences('A {}', false); |
463 assertHasResult(SearchResultKind.REFERENCE, 'A a = null;'); | 465 assertHasResult(SearchResultKind.REFERENCE, 'A a = null;'); |
464 expect( | 466 expect( |
465 getPathString(result.path), | 467 getPathString(result.path), |
466 ''' | 468 ''' |
467 LOCAL_VARIABLE a | 469 LOCAL_VARIABLE a |
468 CONSTRUCTOR | 470 CONSTRUCTOR |
469 CLASS B | 471 CLASS B |
470 COMPILATION_UNIT test.dart | 472 COMPILATION_UNIT test.dart |
471 LIBRARY my_lib'''); | 473 LIBRARY my_lib'''); |
472 } | 474 } |
473 | 475 |
| 476 @failingTest |
474 test_path_inFunction() async { | 477 test_path_inFunction() async { |
| 478 // The path does not contain the first expected element. |
475 addTestFile(''' | 479 addTestFile(''' |
476 library my_lib; | 480 library my_lib; |
477 class A {} | 481 class A {} |
478 main() { | 482 main() { |
479 A a = null; | 483 A a = null; |
480 } | 484 } |
481 '''); | 485 '''); |
482 await findElementReferences('A {}', false); | 486 await findElementReferences('A {}', false); |
483 assertHasResult(SearchResultKind.REFERENCE, 'A a = null;'); | 487 assertHasResult(SearchResultKind.REFERENCE, 'A a = null;'); |
484 expect( | 488 expect( |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 T m() => null; | 671 T m() => null; |
668 } | 672 } |
669 '''); | 673 '''); |
670 await findElementReferences('T> {', false); | 674 await findElementReferences('T> {', false); |
671 expect(searchElement.kind, ElementKind.TYPE_PARAMETER); | 675 expect(searchElement.kind, ElementKind.TYPE_PARAMETER); |
672 expect(results, hasLength(2)); | 676 expect(results, hasLength(2)); |
673 assertHasResult(SearchResultKind.REFERENCE, 'T f;'); | 677 assertHasResult(SearchResultKind.REFERENCE, 'T f;'); |
674 assertHasResult(SearchResultKind.REFERENCE, 'T m()'); | 678 assertHasResult(SearchResultKind.REFERENCE, 'T m()'); |
675 } | 679 } |
676 } | 680 } |
OLD | NEW |