| 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.services.completion.util; | 5 library test.services.completion.util; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol | 9 import 'package:analysis_server/src/protocol.dart' as protocol |
| 10 show Element, ElementKind; | 10 show Element, ElementKind; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 expect(element.kind, equals(protocol.ElementKind.FIELD)); | 227 expect(element.kind, equals(protocol.ElementKind.FIELD)); |
| 228 expect(element.name, equals(name)); | 228 expect(element.name, equals(name)); |
| 229 expect(element.parameters, isNull); | 229 expect(element.parameters, isNull); |
| 230 // The returnType represents the type of a field | 230 // The returnType represents the type of a field |
| 231 expect(element.returnType, type != null ? type : 'dynamic'); | 231 expect(element.returnType, type != null ? type : 'dynamic'); |
| 232 assertHasNoParameterInfo(cs); | 232 assertHasNoParameterInfo(cs); |
| 233 return cs; | 233 return cs; |
| 234 } | 234 } |
| 235 | 235 |
| 236 CompletionSuggestion assertSuggestFunction(String name, String returnType, | 236 CompletionSuggestion assertSuggestFunction(String name, String returnType, |
| 237 [bool isDeprecated = false, int relevance = DART_RELEVANCE_DEFAULT, | 237 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 238 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 238 bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) { |
| 239 CompletionSuggestion cs = assertSuggest(name, | 239 CompletionSuggestion cs = assertSuggest(name, |
| 240 csKind: kind, relevance: relevance, isDeprecated: isDeprecated); | 240 csKind: kind, relevance: relevance, isDeprecated: deprecated); |
| 241 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 241 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 242 protocol.Element element = cs.element; | 242 protocol.Element element = cs.element; |
| 243 expect(element, isNotNull); | 243 expect(element, isNotNull); |
| 244 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); | 244 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); |
| 245 expect(element.name, equals(name)); | 245 expect(element.name, equals(name)); |
| 246 expect(element.isDeprecated, equals(isDeprecated)); | 246 expect(element.isDeprecated, equals(deprecated)); |
| 247 String param = element.parameters; | 247 String param = element.parameters; |
| 248 expect(param, isNotNull); | 248 expect(param, isNotNull); |
| 249 expect(param[0], equals('(')); | 249 expect(param[0], equals('(')); |
| 250 expect(param[param.length - 1], equals(')')); | 250 expect(param[param.length - 1], equals(')')); |
| 251 expect(element.returnType, | 251 expect(element.returnType, |
| 252 equals(returnType != null ? returnType : 'dynamic')); | 252 equals(returnType != null ? returnType : 'dynamic')); |
| 253 assertHasParameterInfo(cs); | 253 assertHasParameterInfo(cs); |
| 254 return cs; | 254 return cs; |
| 255 } | 255 } |
| 256 | 256 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 var result = _completionManager.computeFast(request); | 426 var result = _completionManager.computeFast(request); |
| 427 expect(request.replacementOffset, isNotNull); | 427 expect(request.replacementOffset, isNotNull); |
| 428 expect(request.replacementLength, isNotNull); | 428 expect(request.replacementLength, isNotNull); |
| 429 return result.isEmpty; | 429 return result.isEmpty; |
| 430 } | 430 } |
| 431 | 431 |
| 432 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { | 432 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { |
| 433 if (!_computeFastCalled) { | 433 if (!_computeFastCalled) { |
| 434 expect(computeFast(), isFalse); | 434 expect(computeFast(), isFalse); |
| 435 } | 435 } |
| 436 | 436 resolve(fullAnalysis); |
| 437 // Index SDK | |
| 438 for (Source librarySource in context.librarySources) { | |
| 439 CompilationUnit unit = | |
| 440 context.getResolvedCompilationUnit2(librarySource, librarySource); | |
| 441 if (unit != null) { | |
| 442 index.indexUnit(context, unit); | |
| 443 } | |
| 444 } | |
| 445 | |
| 446 var result = context.performAnalysisTask(); | |
| 447 bool resolved = false; | |
| 448 while (result.hasMoreWork) { | |
| 449 | |
| 450 // Update the index | |
| 451 result.changeNotices.forEach((ChangeNotice notice) { | |
| 452 CompilationUnit unit = notice.resolvedDartUnit; | |
| 453 if (unit != null) { | |
| 454 index.indexUnit(context, unit); | |
| 455 } | |
| 456 }); | |
| 457 | |
| 458 // If the unit has been resolved, then finish the completion | |
| 459 List<Source> libSourceList = context.getLibrariesContaining(testSource); | |
| 460 if (libSourceList.length > 0) { | |
| 461 LibraryElement library = context.getLibraryElement(libSourceList[0]); | |
| 462 if (library != null) { | |
| 463 CompilationUnit unit = | |
| 464 context.getResolvedCompilationUnit(testSource, library); | |
| 465 if (unit != null) { | |
| 466 request.unit = unit; | |
| 467 request.node = | |
| 468 new NodeLocator.con1(completionOffset).searchWithin(unit); | |
| 469 resolved = true; | |
| 470 if (!fullAnalysis) { | |
| 471 break; | |
| 472 } | |
| 473 } | |
| 474 } | |
| 475 } | |
| 476 | |
| 477 result = context.performAnalysisTask(); | |
| 478 } | |
| 479 if (!resolved) { | |
| 480 fail('expected unit to be resolved'); | |
| 481 } | |
| 482 return computer.computeFull(request).then(assertFunction); | 437 return computer.computeFull(request).then(assertFunction); |
| 483 } | 438 } |
| 484 | 439 |
| 485 void failedCompletion(String message, | 440 void failedCompletion(String message, |
| 486 [Iterable<CompletionSuggestion> completions]) { | 441 [Iterable<CompletionSuggestion> completions]) { |
| 487 StringBuffer sb = new StringBuffer(message); | 442 StringBuffer sb = new StringBuffer(message); |
| 488 if (completions != null) { | 443 if (completions != null) { |
| 489 sb.write('\n found'); | 444 sb.write('\n found'); |
| 490 completions.toList() | 445 completions.toList() |
| 491 ..sort(suggestionComparator) | 446 ..sort(suggestionComparator) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 if (cs == null) { | 479 if (cs == null) { |
| 525 cs = s; | 480 cs = s; |
| 526 } else { | 481 } else { |
| 527 failedCompletion('expected exactly one $cs', | 482 failedCompletion('expected exactly one $cs', |
| 528 request.suggestions.where((s) => s.completion == completion)); | 483 request.suggestions.where((s) => s.completion == completion)); |
| 529 } | 484 } |
| 530 }); | 485 }); |
| 531 return cs; | 486 return cs; |
| 532 } | 487 } |
| 533 | 488 |
| 489 void resolve(bool fullAnalysis) { |
| 490 |
| 491 // Index SDK |
| 492 for (Source librarySource in context.librarySources) { |
| 493 CompilationUnit unit = |
| 494 context.getResolvedCompilationUnit2(librarySource, librarySource); |
| 495 if (unit != null) { |
| 496 index.indexUnit(context, unit); |
| 497 } |
| 498 } |
| 499 |
| 500 var result = context.performAnalysisTask(); |
| 501 bool resolved = false; |
| 502 while (result.hasMoreWork) { |
| 503 |
| 504 // Update the index |
| 505 result.changeNotices.forEach((ChangeNotice notice) { |
| 506 CompilationUnit unit = notice.resolvedDartUnit; |
| 507 if (unit != null) { |
| 508 index.indexUnit(context, unit); |
| 509 } |
| 510 }); |
| 511 |
| 512 // If the unit has been resolved, then finish the completion |
| 513 List<Source> libSourceList = context.getLibrariesContaining(testSource); |
| 514 if (libSourceList.length > 0) { |
| 515 LibraryElement library = context.getLibraryElement(libSourceList[0]); |
| 516 if (library != null) { |
| 517 CompilationUnit unit = |
| 518 context.getResolvedCompilationUnit(testSource, library); |
| 519 if (unit != null) { |
| 520 request.unit = unit; |
| 521 request.node = |
| 522 new NodeLocator.con1(completionOffset).searchWithin(unit); |
| 523 resolved = true; |
| 524 if (!fullAnalysis) { |
| 525 break; |
| 526 } |
| 527 } |
| 528 } |
| 529 } |
| 530 |
| 531 result = context.performAnalysisTask(); |
| 532 } |
| 533 if (!resolved) { |
| 534 fail('expected unit to be resolved'); |
| 535 } |
| 536 } |
| 537 |
| 534 @override | 538 @override |
| 535 void setUp() { | 539 void setUp() { |
| 536 super.setUp(); | 540 super.setUp(); |
| 537 index = createLocalMemoryIndex(); | 541 index = createLocalMemoryIndex(); |
| 538 searchEngine = new SearchEngineImpl(index); | 542 searchEngine = new SearchEngineImpl(index); |
| 539 setUpComputer(); | 543 setUpComputer(); |
| 540 } | 544 } |
| 541 | 545 |
| 542 void setUpComputer(); | 546 void setUpComputer(); |
| 543 } | 547 } |
| 544 | 548 |
| 545 /** | 549 /** |
| 546 * Common tests for `ImportedTypeComputerTest`, `InvocationComputerTest`, | 550 * Common tests for `ImportedTypeComputerTest`, `InvocationComputerTest`, |
| 547 * and `LocalComputerTest`. | 551 * and `LocalComputerTest`. |
| 548 */ | 552 */ |
| 549 abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest { | 553 abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest { |
| 550 | 554 |
| 551 /** | 555 /** |
| 552 * Assert that the ImportedComputer uses cached results to produce identical | 556 * Assert that the ImportedComputer uses cached results to produce identical |
| 553 * suggestions to the original set of suggestions. | 557 * suggestions to the original set of suggestions. |
| 554 */ | 558 */ |
| 555 void assertCachedCompute(_) { | 559 void assertCachedCompute(_) { |
| 556 // Subclasses override | 560 // Subclasses override |
| 557 } | 561 } |
| 558 | 562 |
| 559 CompletionSuggestion assertSuggestImportedClass(String name, | 563 CompletionSuggestion assertSuggestImportedClass(String name, |
| 560 [int relevance = DART_RELEVANCE_DEFAULT, | 564 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 561 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 565 int relevance: DART_RELEVANCE_DEFAULT}) { |
| 562 if (computer is ImportedComputer) { | 566 if (computer is ImportedComputer) { |
| 563 return assertSuggestClass(name, relevance: relevance, kind: kind); | 567 return assertSuggestClass(name, relevance: relevance, kind: kind); |
| 564 } else { | 568 } else { |
| 565 return assertNotSuggested(name); | 569 return assertNotSuggested(name); |
| 566 } | 570 } |
| 567 } | 571 } |
| 568 | 572 |
| 569 CompletionSuggestion assertSuggestImportedConstructor(String name) { | 573 CompletionSuggestion assertSuggestImportedConstructor(String name) { |
| 570 return assertNotSuggested(name); | 574 return assertNotSuggested(name); |
| 571 } | 575 } |
| 572 | 576 |
| 573 CompletionSuggestion assertSuggestImportedField(String name, String type, | 577 CompletionSuggestion assertSuggestImportedField(String name, String type, |
| 574 {int relevance: DART_RELEVANCE_INHERITED_FIELD}) { | 578 {int relevance: DART_RELEVANCE_INHERITED_FIELD}) { |
| 575 return assertNotSuggested(name); | 579 return assertNotSuggested(name); |
| 576 } | 580 } |
| 577 | 581 |
| 578 CompletionSuggestion assertSuggestImportedFunction( | 582 CompletionSuggestion assertSuggestImportedFunction( |
| 579 String name, String returnType, [bool isDeprecated = false, | 583 String name, String returnType, |
| 580 int relevance = DART_RELEVANCE_DEFAULT, | 584 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 581 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 585 bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) { |
| 582 if (computer is ImportedComputer) { | 586 return assertNotSuggested(name); |
| 583 return assertSuggestFunction( | |
| 584 name, returnType, isDeprecated, relevance, kind); | |
| 585 } else { | |
| 586 return assertNotSuggested(name); | |
| 587 } | |
| 588 } | 587 } |
| 589 | 588 |
| 590 CompletionSuggestion assertSuggestImportedFunctionTypeAlias( | 589 CompletionSuggestion assertSuggestImportedFunctionTypeAlias( |
| 591 String name, String returnType, [bool isDeprecated = false, | 590 String name, String returnType, [bool isDeprecated = false, |
| 592 int relevance = DART_RELEVANCE_DEFAULT, | 591 int relevance = DART_RELEVANCE_DEFAULT, |
| 593 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 592 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
| 594 if (computer is ImportedComputer) { | 593 if (computer is ImportedComputer) { |
| 595 return assertSuggestFunctionTypeAlias( | 594 return assertSuggestFunctionTypeAlias( |
| 596 name, returnType, isDeprecated, relevance, kind); | 595 name, returnType, isDeprecated, relevance, kind); |
| 597 } else { | 596 } else { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 String name, String returnType, | 674 String name, String returnType, |
| 676 [int relevance = DART_RELEVANCE_DEFAULT]) { | 675 [int relevance = DART_RELEVANCE_DEFAULT]) { |
| 677 if (computer is InvocationComputer) { | 676 if (computer is InvocationComputer) { |
| 678 return assertSuggestTopLevelVar(name, returnType, relevance); | 677 return assertSuggestTopLevelVar(name, returnType, relevance); |
| 679 } else { | 678 } else { |
| 680 return assertNotSuggested(name); | 679 return assertNotSuggested(name); |
| 681 } | 680 } |
| 682 } | 681 } |
| 683 | 682 |
| 684 CompletionSuggestion assertSuggestLocalClass(String name, | 683 CompletionSuggestion assertSuggestLocalClass(String name, |
| 685 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { | 684 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 685 int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { |
| 686 return assertNotSuggested(name); | 686 return assertNotSuggested(name); |
| 687 } | 687 } |
| 688 | 688 |
| 689 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, | 689 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, |
| 690 {int relevance: DART_RELEVANCE_DEFAULT}) { | 690 {int relevance: DART_RELEVANCE_DEFAULT}) { |
| 691 return assertNotSuggested(name); | 691 return assertNotSuggested(name); |
| 692 } | 692 } |
| 693 | 693 |
| 694 CompletionSuggestion assertSuggestLocalConstructor(String name) { | 694 CompletionSuggestion assertSuggestLocalConstructor(String name) { |
| 695 return assertNotSuggested(name); | 695 return assertNotSuggested(name); |
| 696 } | 696 } |
| 697 | 697 |
| 698 CompletionSuggestion assertSuggestLocalField(String name, String type, | 698 CompletionSuggestion assertSuggestLocalField(String name, String type, |
| 699 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { | 699 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { |
| 700 return assertNotSuggested(name); | 700 return assertNotSuggested(name); |
| 701 } | 701 } |
| 702 | 702 |
| 703 CompletionSuggestion assertSuggestLocalFunction( | 703 CompletionSuggestion assertSuggestLocalFunction( |
| 704 String name, String returnType, | 704 String name, String returnType, {bool deprecated: false, |
| 705 {bool deprecated: false, int relevance: DART_RELEVANCE_LOCAL_FUNCTION}) { | 705 int relevance: DART_RELEVANCE_LOCAL_FUNCTION, |
| 706 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) { |
| 706 return assertNotSuggested(name); | 707 return assertNotSuggested(name); |
| 707 } | 708 } |
| 708 | 709 |
| 709 CompletionSuggestion assertSuggestLocalFunctionTypeAlias( | 710 CompletionSuggestion assertSuggestLocalFunctionTypeAlias( |
| 710 String name, String returnType, | 711 String name, String returnType, |
| 711 {bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) { | 712 {bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) { |
| 712 return assertNotSuggested(name); | 713 return assertNotSuggested(name); |
| 713 } | 714 } |
| 714 | 715 |
| 715 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType, | 716 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 736 | 737 |
| 737 CompletionSuggestion assertSuggestLocalVariable( | 738 CompletionSuggestion assertSuggestLocalVariable( |
| 738 String name, String returnType, | 739 String name, String returnType, |
| 739 {int relevance: DART_RELEVANCE_LOCAL_VARIABLE}) { | 740 {int relevance: DART_RELEVANCE_LOCAL_VARIABLE}) { |
| 740 return assertNotSuggested(name); | 741 return assertNotSuggested(name); |
| 741 } | 742 } |
| 742 | 743 |
| 743 CompletionSuggestion assertSuggestNonLocalClass(String name, | 744 CompletionSuggestion assertSuggestNonLocalClass(String name, |
| 744 [int relevance = DART_RELEVANCE_DEFAULT, | 745 [int relevance = DART_RELEVANCE_DEFAULT, |
| 745 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 746 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
| 746 return assertSuggestImportedClass(name, relevance, kind); | 747 return assertSuggestImportedClass(name, relevance: relevance, kind: kind); |
| 747 } | 748 } |
| 748 | 749 |
| 749 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { | 750 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { |
| 750 return super | 751 return super |
| 751 .computeFull(assertFunction, fullAnalysis: fullAnalysis) | 752 .computeFull(assertFunction, fullAnalysis: fullAnalysis) |
| 752 .then(assertCachedCompute); | 753 .then(assertCachedCompute); |
| 753 } | 754 } |
| 754 | 755 |
| 755 test_ArgumentList() { | 756 test_ArgumentList() { |
| 756 // ArgumentList MethodInvocation ExpressionStatement Block | 757 // ArgumentList MethodInvocation ExpressionStatement Block |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 assertSuggestImportedFunction('hasLength', 'bool'); | 801 assertSuggestImportedFunction('hasLength', 'bool'); |
| 801 assertSuggestImportedFunction('identical', 'bool'); | 802 assertSuggestImportedFunction('identical', 'bool'); |
| 802 assertSuggestLocalClass('B'); | 803 assertSuggestLocalClass('B'); |
| 803 assertSuggestImportedClass('Object'); | 804 assertSuggestImportedClass('Object'); |
| 804 assertNotSuggested('main'); | 805 assertNotSuggested('main'); |
| 805 assertNotSuggested('baz'); | 806 assertNotSuggested('baz'); |
| 806 assertNotSuggested('print'); | 807 assertNotSuggested('print'); |
| 807 }); | 808 }); |
| 808 } | 809 } |
| 809 | 810 |
| 811 test_ArgumentList_InstanceCreationExpression_functionalArg() { |
| 812 // ArgumentList InstanceCreationExpression ExpressionStatement Block |
| 813 addSource('/libA.dart', ''' |
| 814 library A; |
| 815 class A { A(f()) { } } |
| 816 bool hasLength(int expected) { } |
| 817 void baz() { }'''); |
| 818 addTestSource(''' |
| 819 import 'dart:async'; |
| 820 import '/libA.dart'; |
| 821 class B { } |
| 822 String bar() => true; |
| 823 void main() {new A(^)}'''); |
| 824 computeFast(); |
| 825 return computeFull((bool result) { |
| 826 expect(request.replacementOffset, completionOffset); |
| 827 expect(request.replacementLength, 0); |
| 828 assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST); |
| 829 assertSuggestLocalFunction( |
| 830 'bar', 'String', kind: CompletionSuggestionKind.IDENTIFIER); |
| 831 assertSuggestImportedFunction('hasLength', 'bool', |
| 832 kind: CompletionSuggestionKind.IDENTIFIER); |
| 833 assertSuggestImportedFunction('identical', 'bool', |
| 834 kind: CompletionSuggestionKind.IDENTIFIER); |
| 835 assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER); |
| 836 assertSuggestImportedClass('A', |
| 837 kind: CompletionSuggestionKind.IDENTIFIER); |
| 838 assertSuggestImportedClass('Object', |
| 839 kind: CompletionSuggestionKind.IDENTIFIER); |
| 840 assertNotSuggested('main'); |
| 841 assertNotSuggested('baz'); |
| 842 assertNotSuggested('print'); |
| 843 }); |
| 844 } |
| 845 |
| 846 test_ArgumentList_InstanceCreationExpression_typedefArg() { |
| 847 // ArgumentList InstanceCreationExpression ExpressionStatement Block |
| 848 addSource('/libA.dart', ''' |
| 849 library A; |
| 850 typedef Funct(); |
| 851 class A { A(Funct f) { } } |
| 852 bool hasLength(int expected) { } |
| 853 void baz() { }'''); |
| 854 addTestSource(''' |
| 855 import 'dart:async'; |
| 856 import '/libA.dart'; |
| 857 class B { } |
| 858 String bar() => true; |
| 859 void main() {new A(^)}'''); |
| 860 computeFast(); |
| 861 return computeFull((bool result) { |
| 862 expect(request.replacementOffset, completionOffset); |
| 863 expect(request.replacementLength, 0); |
| 864 assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST); |
| 865 assertSuggestLocalFunction( |
| 866 'bar', 'String', kind: CompletionSuggestionKind.IDENTIFIER); |
| 867 assertSuggestImportedFunction('hasLength', 'bool', |
| 868 kind: CompletionSuggestionKind.IDENTIFIER); |
| 869 assertSuggestImportedFunction('identical', 'bool', |
| 870 kind: CompletionSuggestionKind.IDENTIFIER); |
| 871 assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER); |
| 872 assertSuggestImportedClass('A', |
| 873 kind: CompletionSuggestionKind.IDENTIFIER); |
| 874 assertSuggestImportedClass('Object', |
| 875 kind: CompletionSuggestionKind.IDENTIFIER); |
| 876 assertNotSuggested('main'); |
| 877 assertNotSuggested('baz'); |
| 878 assertNotSuggested('print'); |
| 879 }); |
| 880 } |
| 881 |
| 810 test_ArgumentList_local_function() { | 882 test_ArgumentList_local_function() { |
| 811 // ArgumentList MethodInvocation ExpressionStatement Block | 883 // ArgumentList MethodInvocation ExpressionStatement Block |
| 812 addSource('/libA.dart', ''' | 884 addSource('/libA.dart', ''' |
| 813 library A; | 885 library A; |
| 814 bool hasLength(int expected) { } | 886 bool hasLength(int expected) { } |
| 815 void baz() { }'''); | 887 void baz() { }'''); |
| 816 addTestSource(''' | 888 addTestSource(''' |
| 817 import '/libA.dart' | 889 import '/libA.dart' |
| 818 expect(arg) { } | 890 expect(arg) { } |
| 819 class B { } | 891 class B { } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 assertSuggestImportedFunction('hasLength', 'bool'); | 928 assertSuggestImportedFunction('hasLength', 'bool'); |
| 857 assertSuggestImportedFunction('identical', 'bool'); | 929 assertSuggestImportedFunction('identical', 'bool'); |
| 858 assertSuggestLocalClass('B'); | 930 assertSuggestLocalClass('B'); |
| 859 assertSuggestImportedClass('Object'); | 931 assertSuggestImportedClass('Object'); |
| 860 assertNotSuggested('main'); | 932 assertNotSuggested('main'); |
| 861 assertNotSuggested('baz'); | 933 assertNotSuggested('baz'); |
| 862 assertNotSuggested('print'); | 934 assertNotSuggested('print'); |
| 863 }); | 935 }); |
| 864 } | 936 } |
| 865 | 937 |
| 938 test_ArgumentList_MethodInvocation_functionalArg() { |
| 939 // ArgumentList MethodInvocation ExpressionStatement Block |
| 940 addSource('/libA.dart', ''' |
| 941 library A; |
| 942 class A { A(f()) { } } |
| 943 bool hasLength(int expected) { } |
| 944 void baz() { }'''); |
| 945 addTestSource(''' |
| 946 import 'dart:async'; |
| 947 import '/libA.dart'; |
| 948 class B { } |
| 949 String bar(f()) => true; |
| 950 void main() {bar(^);}'''); |
| 951 computeFast(); |
| 952 return computeFull((bool result) { |
| 953 expect(request.replacementOffset, completionOffset); |
| 954 expect(request.replacementLength, 0); |
| 955 assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST); |
| 956 assertSuggestLocalFunction( |
| 957 'bar', 'String', kind: CompletionSuggestionKind.IDENTIFIER); |
| 958 assertSuggestImportedFunction('hasLength', 'bool', |
| 959 kind: CompletionSuggestionKind.IDENTIFIER); |
| 960 assertSuggestImportedFunction('identical', 'bool', |
| 961 kind: CompletionSuggestionKind.IDENTIFIER); |
| 962 assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER); |
| 963 assertSuggestImportedClass('A', |
| 964 kind: CompletionSuggestionKind.IDENTIFIER); |
| 965 assertSuggestImportedClass('Object', |
| 966 kind: CompletionSuggestionKind.IDENTIFIER); |
| 967 assertNotSuggested('main'); |
| 968 assertNotSuggested('baz'); |
| 969 assertNotSuggested('print'); |
| 970 }); |
| 971 } |
| 972 |
| 973 test_ArgumentList_MethodInvocation_methodArg() { |
| 974 // ArgumentList MethodInvocation ExpressionStatement Block |
| 975 addSource('/libA.dart', ''' |
| 976 library A; |
| 977 class A { A(f()) { } } |
| 978 bool hasLength(int expected) { } |
| 979 void baz() { }'''); |
| 980 addTestSource(''' |
| 981 import 'dart:async'; |
| 982 import '/libA.dart'; |
| 983 class B { String bar(f()) => true; } |
| 984 void main() {new B().bar(^);}'''); |
| 985 computeFast(); |
| 986 return computeFull((bool result) { |
| 987 expect(request.replacementOffset, completionOffset); |
| 988 expect(request.replacementLength, 0); |
| 989 assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST); |
| 990 assertSuggestImportedFunction( |
| 991 'hasLength', 'bool', kind: CompletionSuggestionKind.IDENTIFIER); |
| 992 assertSuggestImportedFunction('identical', 'bool', |
| 993 kind: CompletionSuggestionKind.IDENTIFIER); |
| 994 assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER); |
| 995 assertSuggestImportedClass('A', |
| 996 kind: CompletionSuggestionKind.IDENTIFIER); |
| 997 assertSuggestImportedClass('Object', |
| 998 kind: CompletionSuggestionKind.IDENTIFIER); |
| 999 assertNotSuggested('main'); |
| 1000 assertNotSuggested('baz'); |
| 1001 assertNotSuggested('print'); |
| 1002 }); |
| 1003 } |
| 1004 |
| 866 test_ArgumentList_namedParam() { | 1005 test_ArgumentList_namedParam() { |
| 867 // SimpleIdentifier NamedExpression ArgumentList MethodInvocation | 1006 // SimpleIdentifier NamedExpression ArgumentList MethodInvocation |
| 868 // ExpressionStatement | 1007 // ExpressionStatement |
| 869 addSource('/libA.dart', ''' | 1008 addSource('/libA.dart', ''' |
| 870 library A; | 1009 library A; |
| 871 bool hasLength(int expected) { }'''); | 1010 bool hasLength(int expected) { }'''); |
| 872 addTestSource(''' | 1011 addTestSource(''' |
| 873 import '/libA.dart' | 1012 import '/libA.dart' |
| 874 String bar() => true; | 1013 String bar() => true; |
| 875 void main() {expect(foo: ^)}'''); | 1014 void main() {expect(foo: ^)}'''); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 //assertSuggestImportedFunction( | 1267 //assertSuggestImportedFunction( |
| 1129 // 'D1', null, true, COMPLETION_RELEVANCE_LOW); | 1268 // 'D1', null, true, COMPLETION_RELEVANCE_LOW); |
| 1130 assertSuggestLocalFunction('D2', 'Z'); | 1269 assertSuggestLocalFunction('D2', 'Z'); |
| 1131 assertSuggestImportedClass('EE'); | 1270 assertSuggestImportedClass('EE'); |
| 1132 // hidden element suggested as low relevance | 1271 // hidden element suggested as low relevance |
| 1133 //assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW); | 1272 //assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW); |
| 1134 assertSuggestLibraryPrefix('g'); | 1273 assertSuggestLibraryPrefix('g'); |
| 1135 assertNotSuggested('G'); | 1274 assertNotSuggested('G'); |
| 1136 //assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW); | 1275 //assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW); |
| 1137 assertSuggestImportedClass('Object'); | 1276 assertSuggestImportedClass('Object'); |
| 1138 assertSuggestImportedFunction('min', 'num', false); | 1277 assertSuggestImportedFunction('min', 'num'); |
| 1139 //assertSuggestImportedFunction( | 1278 //assertSuggestImportedFunction( |
| 1140 // 'max', | 1279 // 'max', |
| 1141 // 'num', | 1280 // 'num', |
| 1142 // false, | 1281 // false, |
| 1143 // COMPLETION_RELEVANCE_LOW); | 1282 // COMPLETION_RELEVANCE_LOW); |
| 1144 assertSuggestTopLevelVarGetterSetter('T1', 'String'); | 1283 assertSuggestTopLevelVarGetterSetter('T1', 'String'); |
| 1145 assertNotSuggested('_T2'); | 1284 assertNotSuggested('_T2'); |
| 1146 //assertSuggestImportedTopLevelVar('T3', 'int', COMPLETION_RELEVANCE_LOW); | 1285 //assertSuggestImportedTopLevelVar('T3', 'int', COMPLETION_RELEVANCE_LOW); |
| 1147 assertNotSuggested('_T4'); | 1286 assertNotSuggested('_T4'); |
| 1148 assertSuggestLocalTopLevelVar('T5', 'int'); | 1287 assertSuggestLocalTopLevelVar('T5', 'int'); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 assertSuggestLocalVariable('f', null); | 1337 assertSuggestLocalVariable('f', null); |
| 1199 // Don't suggest locals out of scope | 1338 // Don't suggest locals out of scope |
| 1200 assertNotSuggested('r'); | 1339 assertNotSuggested('r'); |
| 1201 assertNotSuggested('x'); | 1340 assertNotSuggested('x'); |
| 1202 | 1341 |
| 1203 // imported elements are portially filtered | 1342 // imported elements are portially filtered |
| 1204 //assertSuggestImportedClass('A'); | 1343 //assertSuggestImportedClass('A'); |
| 1205 assertNotSuggested('_B'); | 1344 assertNotSuggested('_B'); |
| 1206 //assertSuggestImportedClass('C'); | 1345 //assertSuggestImportedClass('C'); |
| 1207 // hidden element suggested as low relevance | 1346 // hidden element suggested as low relevance |
| 1208 assertSuggestImportedClass('D', DART_RELEVANCE_LOW); | 1347 assertSuggestImportedClass('D', relevance: DART_RELEVANCE_LOW); |
| 1209 assertSuggestImportedFunction('D1', null, true, DART_RELEVANCE_LOW); | 1348 assertSuggestImportedFunction( |
| 1349 'D1', null, deprecated: true, relevance: DART_RELEVANCE_LOW); |
| 1210 assertSuggestLocalFunction('D2', 'Z'); | 1350 assertSuggestLocalFunction('D2', 'Z'); |
| 1211 //assertSuggestImportedClass('EE'); | 1351 //assertSuggestImportedClass('EE'); |
| 1212 // hidden element suggested as low relevance | 1352 // hidden element suggested as low relevance |
| 1213 //assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW); | 1353 //assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW); |
| 1214 //assertSuggestLibraryPrefix('g'); | 1354 //assertSuggestLibraryPrefix('g'); |
| 1215 assertNotSuggested('G'); | 1355 assertNotSuggested('G'); |
| 1216 //assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW); | 1356 //assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW); |
| 1217 //assertSuggestImportedClass('Object'); | 1357 //assertSuggestImportedClass('Object'); |
| 1218 //assertSuggestImportedFunction('min', 'num', false); | 1358 //assertSuggestImportedFunction('min', 'num', false); |
| 1219 //assertSuggestImportedFunction( | 1359 //assertSuggestImportedFunction( |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1755 addTestSource(''' | 1895 addTestSource(''' |
| 1756 import "/testA.dart"; | 1896 import "/testA.dart"; |
| 1757 typedef int F2(int blat); | 1897 typedef int F2(int blat); |
| 1758 class Clz = Object with Object; | 1898 class Clz = Object with Object; |
| 1759 class C {foo(){^} void bar() {}}'''); | 1899 class C {foo(){^} void bar() {}}'''); |
| 1760 computeFast(); | 1900 computeFast(); |
| 1761 return computeFull((bool result) { | 1901 return computeFull((bool result) { |
| 1762 expect(request.replacementOffset, completionOffset); | 1902 expect(request.replacementOffset, completionOffset); |
| 1763 expect(request.replacementLength, 0); | 1903 expect(request.replacementLength, 0); |
| 1764 assertSuggestImportedClass('A'); | 1904 assertSuggestImportedClass('A'); |
| 1765 assertSuggestImportedFunction('F1', '_B', false); | 1905 assertSuggestImportedFunction('F1', '_B'); |
| 1766 assertSuggestLocalClass('C'); | 1906 assertSuggestLocalClass('C'); |
| 1767 assertSuggestLocalMethod('foo', 'C', null); | 1907 assertSuggestLocalMethod('foo', 'C', null); |
| 1768 assertSuggestLocalMethod('bar', 'C', 'void'); | 1908 assertSuggestLocalMethod('bar', 'C', 'void'); |
| 1769 assertSuggestLocalFunctionTypeAlias('F2', 'int'); | 1909 assertSuggestLocalFunctionTypeAlias('F2', 'int'); |
| 1770 assertSuggestLocalClassTypeAlias('Clz'); | 1910 assertSuggestLocalClassTypeAlias('Clz'); |
| 1771 assertSuggestLocalClass('C'); | 1911 assertSuggestLocalClass('C'); |
| 1772 assertNotSuggested('x'); | 1912 assertNotSuggested('x'); |
| 1773 assertNotSuggested('_B'); | 1913 assertNotSuggested('_B'); |
| 1774 }); | 1914 }); |
| 1775 } | 1915 } |
| (...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3056 assertNotSuggested('bar2'); | 3196 assertNotSuggested('bar2'); |
| 3057 assertNotSuggested('_B'); | 3197 assertNotSuggested('_B'); |
| 3058 assertSuggestLocalClass('Y'); | 3198 assertSuggestLocalClass('Y'); |
| 3059 assertSuggestLocalClass('C'); | 3199 assertSuggestLocalClass('C'); |
| 3060 assertSuggestLocalVariable('f', null); | 3200 assertSuggestLocalVariable('f', null); |
| 3061 assertNotSuggested('x'); | 3201 assertNotSuggested('x'); |
| 3062 assertNotSuggested('e'); | 3202 assertNotSuggested('e'); |
| 3063 }); | 3203 }); |
| 3064 } | 3204 } |
| 3065 } | 3205 } |
| OLD | NEW |