Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: pkg/analysis_server/test/domain_completion_test.dart

Issue 1347283005: refactor ContributionSorter to use new API (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/completion/completion_dart.dart' as newApi;
11 import 'package:analysis_server/src/analysis_server.dart'; 12 import 'package:analysis_server/src/analysis_server.dart';
12 import 'package:analysis_server/src/channel/channel.dart'; 13 import 'package:analysis_server/src/channel/channel.dart';
13 import 'package:analysis_server/src/constants.dart'; 14 import 'package:analysis_server/src/constants.dart';
14 import 'package:analysis_server/src/context_manager.dart'; 15 import 'package:analysis_server/src/context_manager.dart';
15 import 'package:analysis_server/src/domain_analysis.dart'; 16 import 'package:analysis_server/src/domain_analysis.dart';
16 import 'package:analysis_server/src/domain_completion.dart'; 17 import 'package:analysis_server/src/domain_completion.dart';
17 import 'package:analysis_server/src/plugin/server_plugin.dart'; 18 import 'package:analysis_server/src/plugin/server_plugin.dart';
18 import 'package:analysis_server/src/protocol.dart'; 19 import 'package:analysis_server/src/protocol.dart';
19 import 'package:analysis_server/src/services/completion/completion_manager.dart' ; 20 import 'package:analysis_server/src/services/completion/completion_manager.dart' ;
20 import 'package:analysis_server/src/services/completion/contribution_sorter.dart '; 21 import 'package:analysis_server/src/services/completion/contribution_sorter.dart ';
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 test_invocation_sdk_relevancy_off() { 475 test_invocation_sdk_relevancy_off() {
475 var originalSorter = DartCompletionManager.defaultContributionSorter; 476 var originalSorter = DartCompletionManager.defaultContributionSorter;
476 var mockSorter = new MockRelevancySorter(); 477 var mockSorter = new MockRelevancySorter();
477 DartCompletionManager.defaultContributionSorter = mockSorter; 478 DartCompletionManager.defaultContributionSorter = mockSorter;
478 addTestFile('main() {Map m; m.^}'); 479 addTestFile('main() {Map m; m.^}');
479 return getSuggestions().then((_) { 480 return getSuggestions().then((_) {
480 // Assert that the CommonUsageComputer has been replaced 481 // Assert that the CommonUsageComputer has been replaced
481 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE), 482 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE),
482 isFalse); 483 isFalse);
483 DartCompletionManager.defaultContributionSorter = originalSorter; 484 DartCompletionManager.defaultContributionSorter = originalSorter;
484 expect(mockSorter.count, 2); 485 mockSorter.enabled = false;
485 }); 486 });
486 } 487 }
487 488
488 test_invocation_sdk_relevancy_on() { 489 test_invocation_sdk_relevancy_on() {
489 addTestFile('main() {Map m; m.^}'); 490 addTestFile('main() {Map m; m.^}');
490 return getSuggestions().then((_) { 491 return getSuggestions().then((_) {
491 // Assert that the CommonUsageComputer is working 492 // Assert that the CommonUsageComputer is working
492 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE), 493 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE),
493 isTrue); 494 isTrue);
494 }); 495 });
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 709
709 @override 710 @override
710 TimestampedData<String> getContents(Source source) { 711 TimestampedData<String> getContents(Source source) {
711 return source.contents; 712 return source.contents;
712 } 713 }
713 714
714 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 715 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
715 } 716 }
716 717
717 class MockRelevancySorter implements ContributionSorter { 718 class MockRelevancySorter implements ContributionSorter {
718 int count = 0; 719 bool enabled = true;
719 720
720 @override 721 @override
721 void sort(DartCompletionRequest request) { 722 void sort(newApi.DartCompletionRequest request,
722 if (++count > 2) { 723 List<CompletionSuggestion> suggestions) {
724 if (!enabled) {
723 throw 'unexpected sort'; 725 throw 'unexpected sort';
724 } 726 }
725 } 727 }
726 } 728 }
727 729
728 /** 730 /**
729 * Mock stream for tracking calls to listen and subscription.cancel. 731 * Mock stream for tracking calls to listen and subscription.cancel.
730 */ 732 */
731 class MockStream<E> implements Stream<E> { 733 class MockStream<E> implements Stream<E> {
732 MockSubscription<E> mockSubscription = new MockSubscription<E>(); 734 MockSubscription<E> mockSubscription = new MockSubscription<E>();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 838 }
837 '''); 839 ''');
838 await waitForTasksFinished(); 840 await waitForTasksFinished();
839 Request request = 841 Request request =
840 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); 842 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0');
841 Response response = handler.handleRequest(request); 843 Response response = handler.handleRequest(request);
842 expect(response.error, isNotNull); 844 expect(response.error, isNotNull);
843 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); 845 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED);
844 } 846 }
845 } 847 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698