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/error/error.dart'; |
| 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 11 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 12 import 'package:analyzer/src/error/codes.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:analyzer_plugin/plugin/fix_mixin.dart'; |
| 15 import 'package:analyzer_plugin/protocol/protocol_common.dart' |
| 16 hide AnalysisError; |
| 17 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| 18 import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; |
| 19 import 'package:path/src/context.dart'; |
| 20 import 'package:test/test.dart'; |
| 21 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 22 |
| 23 import 'mocks.dart'; |
| 24 |
| 25 void main() { |
| 26 defineReflectiveTests(FixesMixinTest); |
| 27 } |
| 28 |
| 29 @reflectiveTest |
| 30 class FixesMixinTest { |
| 31 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 32 |
| 33 String packagePath1; |
| 34 String filePath1; |
| 35 ContextRoot contextRoot1; |
| 36 |
| 37 MockChannel channel; |
| 38 _TestServerPlugin plugin; |
| 39 |
| 40 void setUp() { |
| 41 Context pathContext = resourceProvider.pathContext; |
| 42 |
| 43 packagePath1 = resourceProvider.convertPath('/package1'); |
| 44 filePath1 = pathContext.join(packagePath1, 'lib', 'test.dart'); |
| 45 resourceProvider.newFile(filePath1, ''); |
| 46 contextRoot1 = new ContextRoot(packagePath1, <String>[]); |
| 47 |
| 48 channel = new MockChannel(); |
| 49 plugin = new _TestServerPlugin(resourceProvider); |
| 50 plugin.start(channel); |
| 51 } |
| 52 |
| 53 test_handleEditGetFixes() async { |
| 54 await plugin.handleAnalysisSetContextRoots( |
| 55 new AnalysisSetContextRootsParams([contextRoot1])); |
| 56 |
| 57 EditGetFixesResult result = |
| 58 await plugin.handleEditGetFixes(new EditGetFixesParams(filePath1, 13)); |
| 59 expect(result, isNotNull); |
| 60 List<AnalysisErrorFixes> fixes = result.fixes; |
| 61 expect(fixes, hasLength(1)); |
| 62 expect(fixes[0].fixes, hasLength(3)); |
| 63 } |
| 64 } |
| 65 |
| 66 class _TestFixContributor implements FixContributor { |
| 67 List<PrioritizedSourceChange> changes; |
| 68 |
| 69 _TestFixContributor(this.changes); |
| 70 |
| 71 @override |
| 72 void computeFixes(FixesRequest request, FixCollector collector) { |
| 73 for (PrioritizedSourceChange change in changes) { |
| 74 collector.addFix(request.error, change); |
| 75 } |
| 76 } |
| 77 } |
| 78 |
| 79 class _TestServerPlugin extends MockServerPlugin with FixesMixin { |
| 80 _TestServerPlugin(ResourceProvider resourceProvider) |
| 81 : super(resourceProvider); |
| 82 |
| 83 PrioritizedSourceChange createChange() { |
| 84 return new PrioritizedSourceChange(0, new SourceChange('')); |
| 85 } |
| 86 |
| 87 @override |
| 88 List<FixContributor> getFixContributors(AnalysisDriverGeneric driver) { |
| 89 return <FixContributor>[ |
| 90 new _TestFixContributor(<PrioritizedSourceChange>[createChange()]), |
| 91 new _TestFixContributor( |
| 92 <PrioritizedSourceChange>[createChange(), createChange()]) |
| 93 ]; |
| 94 } |
| 95 |
| 96 @override |
| 97 Future<ResolveResult> getResolveResultForFixes( |
| 98 AnalysisDriverGeneric driver, String path) async { |
| 99 AnalysisError error = new AnalysisError( |
| 100 new MockSource(), 0, 0, CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT); |
| 101 return new AnalysisResult(null, null, null, null, null, null, |
| 102 new LineInfo([0, 20]), null, null, [error], null); |
| 103 } |
| 104 } |
OLD | NEW |