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/assist_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/utilities/assist/assist.dart'; |
| 15 import 'package:path/src/context.dart'; |
| 16 import 'package:test/test.dart'; |
| 17 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 18 |
| 19 import 'mocks.dart'; |
| 20 |
| 21 void main() { |
| 22 defineReflectiveTests(AssistsMixinTest); |
| 23 } |
| 24 |
| 25 @reflectiveTest |
| 26 class AssistsMixinTest { |
| 27 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 28 |
| 29 String packagePath1; |
| 30 String filePath1; |
| 31 ContextRoot contextRoot1; |
| 32 |
| 33 MockChannel channel; |
| 34 _TestServerPlugin plugin; |
| 35 |
| 36 void setUp() { |
| 37 Context pathContext = resourceProvider.pathContext; |
| 38 |
| 39 packagePath1 = resourceProvider.convertPath('/package1'); |
| 40 filePath1 = pathContext.join(packagePath1, 'lib', 'test.dart'); |
| 41 resourceProvider.newFile(filePath1, ''); |
| 42 contextRoot1 = new ContextRoot(packagePath1, <String>[]); |
| 43 |
| 44 channel = new MockChannel(); |
| 45 plugin = new _TestServerPlugin(resourceProvider); |
| 46 plugin.start(channel); |
| 47 } |
| 48 |
| 49 test_handleEditGetAssists() async { |
| 50 await plugin.handleAnalysisSetContextRoots( |
| 51 new AnalysisSetContextRootsParams([contextRoot1])); |
| 52 |
| 53 EditGetAssistsResult result = await plugin |
| 54 .handleEditGetAssists(new EditGetAssistsParams(filePath1, 10, 0)); |
| 55 expect(result, isNotNull); |
| 56 expect(result.assists, hasLength(3)); |
| 57 } |
| 58 } |
| 59 |
| 60 class _TestAssistContributor implements AssistContributor { |
| 61 List<PrioritizedSourceChange> changes; |
| 62 |
| 63 _TestAssistContributor(this.changes); |
| 64 |
| 65 @override |
| 66 void computeAssists(AssistRequest request, AssistCollector collector) { |
| 67 for (PrioritizedSourceChange change in changes) { |
| 68 collector.addAssist(change); |
| 69 } |
| 70 } |
| 71 } |
| 72 |
| 73 class _TestServerPlugin extends MockServerPlugin with AssistsMixin { |
| 74 _TestServerPlugin(ResourceProvider resourceProvider) |
| 75 : super(resourceProvider); |
| 76 |
| 77 PrioritizedSourceChange createChange() { |
| 78 return new PrioritizedSourceChange(0, new SourceChange('')); |
| 79 } |
| 80 |
| 81 @override |
| 82 List<AssistContributor> getAssistContributors(AnalysisDriverGeneric driver) { |
| 83 return <AssistContributor>[ |
| 84 new _TestAssistContributor(<PrioritizedSourceChange>[createChange()]), |
| 85 new _TestAssistContributor( |
| 86 <PrioritizedSourceChange>[createChange(), createChange()]) |
| 87 ]; |
| 88 } |
| 89 |
| 90 @override |
| 91 Future<ResolveResult> getResolveResultForAssists( |
| 92 AnalysisDriverGeneric driver, String path) async { |
| 93 return new AnalysisResult( |
| 94 null, null, null, null, null, null, null, null, null, null, null); |
| 95 } |
| 96 } |
OLD | NEW |