| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 abstract class AbstractCompletionTest extends AbstractContextTest { | 36 abstract class AbstractCompletionTest extends AbstractContextTest { |
| 37 Index index; | 37 Index index; |
| 38 SearchEngineImpl searchEngine; | 38 SearchEngineImpl searchEngine; |
| 39 DartCompletionContributor contributor; | 39 DartCompletionContributor contributor; |
| 40 String testFile = '/completionTest.dart'; | 40 String testFile = '/completionTest.dart'; |
| 41 Source testSource; | 41 Source testSource; |
| 42 CompilationUnit testUnit; | 42 CompilationUnit testUnit; |
| 43 int completionOffset; | 43 int completionOffset; |
| 44 AstNode completionNode; | 44 AstNode completionNode; |
| 45 bool _computeFastCalled = false; | 45 bool computeFastResult; |
| 46 DartCompletionRequest request; | 46 DartCompletionRequest request; |
| 47 DartCompletionCache cache; | 47 DartCompletionCache cache; |
| 48 DartCompletionManager _completionManager; | 48 DartCompletionManager _completionManager; |
| 49 | 49 |
| 50 void addResolvedUnit(String file, String code) { | 50 void addResolvedUnit(String file, String code) { |
| 51 Source source = addSource(file, code); | 51 Source source = addSource(file, code); |
| 52 CompilationUnit unit = resolveLibraryUnit(source); | 52 CompilationUnit unit = resolveLibraryUnit(source); |
| 53 index.indexUnit(context, unit); | 53 index.indexUnit(context, unit); |
| 54 } | 54 } |
| 55 | 55 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 [int relevance = DART_RELEVANCE_DEFAULT]) { | 375 [int relevance = DART_RELEVANCE_DEFAULT]) { |
| 376 if (contributor is ImportedReferenceContributor) { | 376 if (contributor is ImportedReferenceContributor) { |
| 377 assertSuggestGetter(name, returnType); | 377 assertSuggestGetter(name, returnType); |
| 378 assertSuggestSetter(name); | 378 assertSuggestSetter(name); |
| 379 } else { | 379 } else { |
| 380 assertNotSuggested(name); | 380 assertNotSuggested(name); |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 | 383 |
| 384 bool computeFast() { | 384 bool computeFast() { |
| 385 _computeFastCalled = true; | 385 expect(computeFastResult, isNull); |
| 386 _completionManager = new DartCompletionManager(context, searchEngine, | 386 _completionManager = new DartCompletionManager(context, searchEngine, |
| 387 testSource, cache, [contributor], new CommonUsageComputer({})); | 387 testSource, cache, [contributor], new CommonUsageComputer({})); |
| 388 var result = _completionManager.computeFast(request); | 388 var result = _completionManager.computeFast(request); |
| 389 expect(request.replacementOffset, isNotNull); | 389 expect(request.replacementOffset, isNotNull); |
| 390 expect(request.replacementLength, isNotNull); | 390 expect(request.replacementLength, isNotNull); |
| 391 return result.isEmpty; | 391 computeFastResult = result.isEmpty; |
| 392 return computeFastResult; |
| 392 } | 393 } |
| 393 | 394 |
| 394 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { | 395 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { |
| 395 if (!_computeFastCalled) { | 396 if (computeFastResult == null) { |
| 396 expect(computeFast(), isFalse); | 397 computeFast(); |
| 397 } | 398 } |
| 398 resolve(fullAnalysis); | 399 if (computeFastResult) { |
| 399 return contributor.computeFull(request).then(assertFunction); | 400 assertFunction(true); |
| 401 return new Future.value(true); |
| 402 } else { |
| 403 resolve(fullAnalysis); |
| 404 return contributor.computeFull(request).then(assertFunction); |
| 405 } |
| 400 } | 406 } |
| 401 | 407 |
| 402 void failedCompletion(String message, | 408 void failedCompletion(String message, |
| 403 [Iterable<CompletionSuggestion> completions]) { | 409 [Iterable<CompletionSuggestion> completions]) { |
| 404 StringBuffer sb = new StringBuffer(message); | 410 StringBuffer sb = new StringBuffer(message); |
| 405 if (completions != null) { | 411 if (completions != null) { |
| 406 sb.write('\n found'); | 412 sb.write('\n found'); |
| 407 completions.toList() | 413 completions.toList() |
| 408 ..sort(suggestionComparator) | 414 ..sort(suggestionComparator) |
| 409 ..forEach((CompletionSuggestion suggestion) { | 415 ..forEach((CompletionSuggestion suggestion) { |
| (...skipping 3207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3617 assertSuggestInvocationSetter('_s2'); | 3623 assertSuggestInvocationSetter('_s2'); |
| 3618 assertNotSuggested('z'); | 3624 assertNotSuggested('z'); |
| 3619 assertNotSuggested('I'); | 3625 assertNotSuggested('I'); |
| 3620 assertNotSuggested('A'); | 3626 assertNotSuggested('A'); |
| 3621 assertNotSuggested('X'); | 3627 assertNotSuggested('X'); |
| 3622 assertNotSuggested('Object'); | 3628 assertNotSuggested('Object'); |
| 3623 assertNotSuggested('=='); | 3629 assertNotSuggested('=='); |
| 3624 }); | 3630 }); |
| 3625 } | 3631 } |
| 3626 | 3632 |
| 3633 test_ThisExpression_constructor_param() { |
| 3634 // SimpleIdentifier FieldFormalParameter FormalParameterList |
| 3635 addTestSource(''' |
| 3636 main() { } |
| 3637 class I {X get f => new A();get _g => new A();} |
| 3638 class A implements I { |
| 3639 A(this.^) {} |
| 3640 A.z() {} |
| 3641 var b; X _c; |
| 3642 X get d => new A();get _e => new A(); |
| 3643 // no semicolon between completion point and next statement |
| 3644 set s1(I x) {} set _s2(I x) {m(null);} |
| 3645 m(X x) {} I _n(X x) {}} |
| 3646 class X{}'''); |
| 3647 computeFast(); |
| 3648 return computeFull((bool result) { |
| 3649 expect(request.replacementOffset, completionOffset); |
| 3650 expect(request.replacementLength, 0); |
| 3651 assertSuggestInvocationField('b', null, |
| 3652 relevance: DART_RELEVANCE_LOCAL_FIELD); |
| 3653 assertSuggestInvocationField('_c', 'X', |
| 3654 relevance: DART_RELEVANCE_LOCAL_FIELD); |
| 3655 assertNotSuggested('d'); |
| 3656 assertNotSuggested('_e'); |
| 3657 assertNotSuggested('f'); |
| 3658 assertNotSuggested('_g'); |
| 3659 assertNotSuggested('m'); |
| 3660 assertNotSuggested('_n'); |
| 3661 assertNotSuggested('s1'); |
| 3662 assertNotSuggested('_s2'); |
| 3663 assertNotSuggested('z'); |
| 3664 assertNotSuggested('I'); |
| 3665 assertNotSuggested('A'); |
| 3666 assertNotSuggested('X'); |
| 3667 assertNotSuggested('Object'); |
| 3668 assertNotSuggested('=='); |
| 3669 }); |
| 3670 } |
| 3671 |
| 3672 test_ThisExpression_constructor_param2() { |
| 3673 // SimpleIdentifier FieldFormalParameter FormalParameterList |
| 3674 addTestSource(''' |
| 3675 main() { } |
| 3676 class I {X get f => new A();get _g => new A();} |
| 3677 class A implements I { |
| 3678 A(this.b^) {} |
| 3679 A.z() {} |
| 3680 var b; X _c; |
| 3681 X get d => new A();get _e => new A(); |
| 3682 // no semicolon between completion point and next statement |
| 3683 set s1(I x) {} set _s2(I x) {m(null);} |
| 3684 m(X x) {} I _n(X x) {}} |
| 3685 class X{}'''); |
| 3686 computeFast(); |
| 3687 return computeFull((bool result) { |
| 3688 expect(request.replacementOffset, completionOffset - 1); |
| 3689 expect(request.replacementLength, 1); |
| 3690 assertSuggestInvocationField('b', null, |
| 3691 relevance: DART_RELEVANCE_LOCAL_FIELD); |
| 3692 assertSuggestInvocationField('_c', 'X', |
| 3693 relevance: DART_RELEVANCE_LOCAL_FIELD); |
| 3694 assertNotSuggested('d'); |
| 3695 assertNotSuggested('_e'); |
| 3696 assertNotSuggested('f'); |
| 3697 assertNotSuggested('_g'); |
| 3698 assertNotSuggested('m'); |
| 3699 assertNotSuggested('_n'); |
| 3700 assertNotSuggested('s1'); |
| 3701 assertNotSuggested('_s2'); |
| 3702 assertNotSuggested('z'); |
| 3703 assertNotSuggested('I'); |
| 3704 assertNotSuggested('A'); |
| 3705 assertNotSuggested('X'); |
| 3706 assertNotSuggested('Object'); |
| 3707 assertNotSuggested('=='); |
| 3708 }); |
| 3709 } |
| 3710 |
| 3711 test_ThisExpression_constructor_param3() { |
| 3712 // SimpleIdentifier FieldFormalParameter FormalParameterList |
| 3713 addTestSource(''' |
| 3714 main() { } |
| 3715 class I {X get f => new A();get _g => new A();} |
| 3716 class A implements I { |
| 3717 A(this.^b) {} |
| 3718 A.z() {} |
| 3719 var b; X _c; |
| 3720 X get d => new A();get _e => new A(); |
| 3721 // no semicolon between completion point and next statement |
| 3722 set s1(I x) {} set _s2(I x) {m(null);} |
| 3723 m(X x) {} I _n(X x) {}} |
| 3724 class X{}'''); |
| 3725 computeFast(); |
| 3726 return computeFull((bool result) { |
| 3727 expect(request.replacementOffset, completionOffset); |
| 3728 expect(request.replacementLength, 1); |
| 3729 assertSuggestInvocationField('b', null, |
| 3730 relevance: DART_RELEVANCE_LOCAL_FIELD); |
| 3731 assertSuggestInvocationField('_c', 'X', |
| 3732 relevance: DART_RELEVANCE_LOCAL_FIELD); |
| 3733 assertNotSuggested('d'); |
| 3734 assertNotSuggested('_e'); |
| 3735 assertNotSuggested('f'); |
| 3736 assertNotSuggested('_g'); |
| 3737 assertNotSuggested('m'); |
| 3738 assertNotSuggested('_n'); |
| 3739 assertNotSuggested('s1'); |
| 3740 assertNotSuggested('_s2'); |
| 3741 assertNotSuggested('z'); |
| 3742 assertNotSuggested('I'); |
| 3743 assertNotSuggested('A'); |
| 3744 assertNotSuggested('X'); |
| 3745 assertNotSuggested('Object'); |
| 3746 assertNotSuggested('=='); |
| 3747 }); |
| 3748 } |
| 3749 |
| 3750 test_ThisExpression_constructor_param4() { |
| 3751 // SimpleIdentifier FieldFormalParameter FormalParameterList |
| 3752 addTestSource(''' |
| 3753 main() { } |
| 3754 class I {X get f => new A();get _g => new A();} |
| 3755 class A implements I { |
| 3756 A(this.b, this.^) {} |
| 3757 A.z() {} |
| 3758 var b; X _c; |
| 3759 X get d => new A();get _e => new A(); |
| 3760 // no semicolon between completion point and next statement |
| 3761 set s1(I x) {} set _s2(I x) {m(null);} |
| 3762 m(X x) {} I _n(X x) {}} |
| 3763 class X{}'''); |
| 3764 computeFast(); |
| 3765 return computeFull((bool result) { |
| 3766 expect(request.replacementOffset, completionOffset); |
| 3767 expect(request.replacementLength, 0); |
| 3768 assertNotSuggested('b'); |
| 3769 assertSuggestInvocationField('_c', 'X', |
| 3770 relevance: DART_RELEVANCE_LOCAL_FIELD); |
| 3771 assertNotSuggested('d'); |
| 3772 assertNotSuggested('_e'); |
| 3773 assertNotSuggested('f'); |
| 3774 assertNotSuggested('_g'); |
| 3775 assertNotSuggested('m'); |
| 3776 assertNotSuggested('_n'); |
| 3777 assertNotSuggested('s1'); |
| 3778 assertNotSuggested('_s2'); |
| 3779 assertNotSuggested('z'); |
| 3780 assertNotSuggested('I'); |
| 3781 assertNotSuggested('A'); |
| 3782 assertNotSuggested('X'); |
| 3783 assertNotSuggested('Object'); |
| 3784 assertNotSuggested('=='); |
| 3785 }); |
| 3786 } |
| 3787 |
| 3627 test_TopLevelVariableDeclaration_typed_name() { | 3788 test_TopLevelVariableDeclaration_typed_name() { |
| 3628 // SimpleIdentifier VariableDeclaration VariableDeclarationList | 3789 // SimpleIdentifier VariableDeclaration VariableDeclarationList |
| 3629 // TopLevelVariableDeclaration | 3790 // TopLevelVariableDeclaration |
| 3630 addTestSource('class A {} B ^'); | 3791 addTestSource('class A {} B ^'); |
| 3631 computeFast(); | 3792 computeFast(); |
| 3632 return computeFull((bool result) { | 3793 return computeFull((bool result) { |
| 3633 assertNoSuggestions(); | 3794 assertNoSuggestions(); |
| 3634 }); | 3795 }); |
| 3635 } | 3796 } |
| 3636 | 3797 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3774 assertNotSuggested('bar2'); | 3935 assertNotSuggested('bar2'); |
| 3775 assertNotSuggested('_B'); | 3936 assertNotSuggested('_B'); |
| 3776 assertSuggestLocalClass('Y'); | 3937 assertSuggestLocalClass('Y'); |
| 3777 assertSuggestLocalClass('C'); | 3938 assertSuggestLocalClass('C'); |
| 3778 assertSuggestLocalVariable('f', null); | 3939 assertSuggestLocalVariable('f', null); |
| 3779 assertNotSuggested('x'); | 3940 assertNotSuggested('x'); |
| 3780 assertNotSuggested('e'); | 3941 assertNotSuggested('e'); |
| 3781 }); | 3942 }); |
| 3782 } | 3943 } |
| 3783 } | 3944 } |
| OLD | NEW |