OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'dart:async'; |
| 6 |
| 7 import 'package:analyzer/dart/analysis/results.dart' hide AnalysisResult; |
| 8 import 'package:analyzer/file_system/file_system.dart'; |
| 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 10 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 11 import 'package:analyzer_plugin/plugin/completion_mixin.dart'; |
| 12 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 13 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| 14 import 'package:analyzer_plugin/src/utilities/completion/completion_core.dart'; |
| 15 import 'package:analyzer_plugin/utilities/completion/completion_core.dart'; |
| 16 import 'package:path/src/context.dart'; |
| 17 import 'package:test/test.dart'; |
| 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 19 |
| 20 import 'mocks.dart'; |
| 21 |
| 22 void main() { |
| 23 defineReflectiveTests(CompletionMixinTest); |
| 24 } |
| 25 |
| 26 @reflectiveTest |
| 27 class CompletionMixinTest { |
| 28 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 29 |
| 30 String packagePath1; |
| 31 String filePath1; |
| 32 ContextRoot contextRoot1; |
| 33 |
| 34 MockChannel channel; |
| 35 _TestServerPlugin plugin; |
| 36 |
| 37 void setUp() { |
| 38 Context pathContext = resourceProvider.pathContext; |
| 39 |
| 40 packagePath1 = resourceProvider.convertPath('/package1'); |
| 41 filePath1 = pathContext.join(packagePath1, 'lib', 'test.dart'); |
| 42 resourceProvider.newFile(filePath1, 'int foo = bar;'); |
| 43 contextRoot1 = new ContextRoot(packagePath1, <String>[]); |
| 44 |
| 45 channel = new MockChannel(); |
| 46 plugin = new _TestServerPlugin(resourceProvider); |
| 47 plugin.start(channel); |
| 48 } |
| 49 |
| 50 test_handleCompletionGetSuggestions() async { |
| 51 await plugin.handleAnalysisSetContextRoots( |
| 52 new AnalysisSetContextRootsParams([contextRoot1])); |
| 53 |
| 54 CompletionGetSuggestionsResult result = |
| 55 await plugin.handleCompletionGetSuggestions( |
| 56 new CompletionGetSuggestionsParams(filePath1, 13)); |
| 57 expect(result, isNotNull); |
| 58 expect(result.results, hasLength(3)); |
| 59 } |
| 60 } |
| 61 |
| 62 class _TestCompletionContributor implements CompletionContributor { |
| 63 List<CompletionSuggestion> suggestions; |
| 64 |
| 65 _TestCompletionContributor(this.suggestions); |
| 66 |
| 67 @override |
| 68 Future<Null> computeSuggestions( |
| 69 CompletionRequest request, CompletionCollector collector) async { |
| 70 if ((collector as CompletionCollectorImpl).offset == null) { |
| 71 collector.offset = 1; |
| 72 collector.length = 2; |
| 73 } |
| 74 for (CompletionSuggestion suggestion in suggestions) { |
| 75 collector.addSuggestion(suggestion); |
| 76 } |
| 77 } |
| 78 } |
| 79 |
| 80 class _TestServerPlugin extends MockServerPlugin with CompletionMixin { |
| 81 _TestServerPlugin(ResourceProvider resourceProvider) |
| 82 : super(resourceProvider); |
| 83 |
| 84 CompletionSuggestion createSuggestion() { |
| 85 return new CompletionSuggestion( |
| 86 CompletionSuggestionKind.IDENTIFIER, 1, '', 0, 0, false, false); |
| 87 } |
| 88 |
| 89 @override |
| 90 List<CompletionContributor> getCompletionContributors( |
| 91 AnalysisDriverGeneric driver) { |
| 92 return <CompletionContributor>[ |
| 93 new _TestCompletionContributor( |
| 94 <CompletionSuggestion>[createSuggestion(), createSuggestion()]), |
| 95 new _TestCompletionContributor( |
| 96 <CompletionSuggestion>[createSuggestion()]), |
| 97 ]; |
| 98 } |
| 99 |
| 100 @override |
| 101 Future<ResolveResult> getResolveResultForCompletion( |
| 102 AnalysisDriverGeneric driver, String path) async { |
| 103 return new AnalysisResult( |
| 104 null, null, null, null, null, null, null, null, null, null, null); |
| 105 } |
| 106 } |
OLD | NEW |