| 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.domain.completion; | 5 library test.domain.completion; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/completion/completion_core.dart' | 9 import 'package:analysis_server/completion/completion_core.dart' |
| 10 show CompletionRequest, CompletionResult; | 10 show CompletionRequest, CompletionResult; |
| 11 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 12 import 'package:analysis_server/src/channel/channel.dart'; | 12 import 'package:analysis_server/src/channel/channel.dart'; |
| 13 import 'package:analysis_server/src/constants.dart'; | 13 import 'package:analysis_server/src/constants.dart'; |
| 14 import 'package:analysis_server/src/context_manager.dart'; | 14 import 'package:analysis_server/src/context_manager.dart'; |
| 15 import 'package:analysis_server/src/domain_analysis.dart'; | 15 import 'package:analysis_server/src/domain_analysis.dart'; |
| 16 import 'package:analysis_server/src/domain_completion.dart'; | 16 import 'package:analysis_server/src/domain_completion.dart'; |
| 17 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 17 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 18 import 'package:analysis_server/src/protocol.dart'; | 18 import 'package:analysis_server/src/protocol.dart'; |
| 19 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; | 19 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; |
| 20 import 'package:analysis_server/src/services/completion/contribution_sorter.dart
'; |
| 20 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 21 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 21 import 'package:analysis_server/src/services/index/index.dart' show Index; | 22 import 'package:analysis_server/src/services/index/index.dart' show Index; |
| 22 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 23 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
| 23 import 'package:analysis_server/src/services/search/search_engine.dart'; | 24 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 24 import 'package:analyzer/file_system/file_system.dart'; | 25 import 'package:analyzer/file_system/file_system.dart'; |
| 25 import 'package:analyzer/instrumentation/instrumentation.dart'; | 26 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 26 import 'package:analyzer/source/pub_package_map_provider.dart'; | 27 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 27 import 'package:analyzer/src/generated/engine.dart'; | 28 import 'package:analyzer/src/generated/engine.dart'; |
| 28 import 'package:analyzer/src/generated/sdk.dart'; | 29 import 'package:analyzer/src/generated/sdk.dart'; |
| 29 import 'package:analyzer/src/generated/source.dart'; | 30 import 'package:analyzer/src/generated/source.dart'; |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 | 464 |
| 464 test_invocation() { | 465 test_invocation() { |
| 465 addTestFile('class A {b() {}} main() {A a; a.^}'); | 466 addTestFile('class A {b() {}} main() {A a; a.^}'); |
| 466 return getSuggestions().then((_) { | 467 return getSuggestions().then((_) { |
| 467 expect(replacementOffset, equals(completionOffset)); | 468 expect(replacementOffset, equals(completionOffset)); |
| 468 expect(replacementLength, equals(0)); | 469 expect(replacementLength, equals(0)); |
| 469 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); | 470 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); |
| 470 }); | 471 }); |
| 471 } | 472 } |
| 472 | 473 |
| 474 test_invocation_sdk_relevancy_off() { |
| 475 var originalSorter = DartCompletionManager.defaultContributionSorter; |
| 476 var mockSorter = new MockRelevancySorter(); |
| 477 DartCompletionManager.defaultContributionSorter = mockSorter; |
| 478 addTestFile('main() {Map m; m.^}'); |
| 479 return getSuggestions().then((_) { |
| 480 // Assert that the CommonUsageComputer has been replaced |
| 481 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE), |
| 482 isFalse); |
| 483 DartCompletionManager.defaultContributionSorter = originalSorter; |
| 484 expect(mockSorter.count, 2); |
| 485 }); |
| 486 } |
| 487 |
| 488 test_invocation_sdk_relevancy_on() { |
| 489 addTestFile('main() {Map m; m.^}'); |
| 490 return getSuggestions().then((_) { |
| 491 // Assert that the CommonUsageComputer is working |
| 492 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE), |
| 493 isTrue); |
| 494 }); |
| 495 } |
| 496 |
| 473 test_invocation_withTrailingStmt() { | 497 test_invocation_withTrailingStmt() { |
| 474 addTestFile('class A {b() {}} main() {A a; a.^ int x = 7;}'); | 498 addTestFile('class A {b() {}} main() {A a; a.^ int x = 7;}'); |
| 475 return getSuggestions().then((_) { | 499 return getSuggestions().then((_) { |
| 476 expect(replacementOffset, equals(completionOffset)); | 500 expect(replacementOffset, equals(completionOffset)); |
| 477 expect(replacementLength, equals(0)); | 501 expect(replacementLength, equals(0)); |
| 478 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); | 502 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); |
| 479 }); | 503 }); |
| 480 } | 504 } |
| 481 | 505 |
| 482 test_keyword() { | 506 test_keyword() { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 } | 707 } |
| 684 | 708 |
| 685 @override | 709 @override |
| 686 TimestampedData<String> getContents(Source source) { | 710 TimestampedData<String> getContents(Source source) { |
| 687 return source.contents; | 711 return source.contents; |
| 688 } | 712 } |
| 689 | 713 |
| 690 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 714 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 691 } | 715 } |
| 692 | 716 |
| 717 class MockRelevancySorter implements ContributionSorter { |
| 718 int count = 0; |
| 719 |
| 720 @override |
| 721 void sort(DartCompletionRequest request) { |
| 722 if (++count > 2) { |
| 723 throw 'unexpected sort'; |
| 724 } |
| 725 } |
| 726 } |
| 727 |
| 693 /** | 728 /** |
| 694 * Mock stream for tracking calls to listen and subscription.cancel. | 729 * Mock stream for tracking calls to listen and subscription.cancel. |
| 695 */ | 730 */ |
| 696 class MockStream<E> implements Stream<E> { | 731 class MockStream<E> implements Stream<E> { |
| 697 MockSubscription<E> mockSubscription = new MockSubscription<E>(); | 732 MockSubscription<E> mockSubscription = new MockSubscription<E>(); |
| 698 int listenCount = 0; | 733 int listenCount = 0; |
| 699 | 734 |
| 700 int get cancelCount => mockSubscription.cancelCount; | 735 int get cancelCount => mockSubscription.cancelCount; |
| 701 | 736 |
| 702 @override | 737 @override |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 } | 836 } |
| 802 '''); | 837 '''); |
| 803 await waitForTasksFinished(); | 838 await waitForTasksFinished(); |
| 804 Request request = | 839 Request request = |
| 805 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); | 840 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); |
| 806 Response response = handler.handleRequest(request); | 841 Response response = handler.handleRequest(request); |
| 807 expect(response.error, isNotNull); | 842 expect(response.error, isNotNull); |
| 808 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); | 843 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); |
| 809 } | 844 } |
| 810 } | 845 } |
| OLD | NEW |