| 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.edit.fixes; | |
| 6 | |
| 7 import 'dart:async'; | 5 import 'dart:async'; |
| 8 | 6 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 import 'package:analysis_server/src/edit/edit_domain.dart'; | 8 import 'package:analysis_server/src/edit/edit_domain.dart'; |
| 9 import 'package:analysis_server/src/plugin/plugin_manager.dart'; |
| 10 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; |
| 11 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
| 12 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart' as plugin; |
| 11 import 'package:plugin/manager.dart'; | 13 import 'package:plugin/manager.dart'; |
| 12 import 'package:test/test.dart'; | 14 import 'package:test/test.dart'; |
| 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 14 | 16 |
| 15 import '../analysis_abstract.dart'; | 17 import '../analysis_abstract.dart'; |
| 16 | 18 |
| 17 main() { | 19 main() { |
| 18 defineReflectiveSuite(() { | 20 defineReflectiveSuite(() { |
| 19 defineReflectiveTests(FixesTest); | 21 defineReflectiveTests(FixesTest); |
| 20 }); | 22 }); |
| 21 } | 23 } |
| 22 | 24 |
| 23 @reflectiveTest | 25 @reflectiveTest |
| 24 class FixesTest extends AbstractAnalysisTest { | 26 class FixesTest extends AbstractAnalysisTest { |
| 25 @override | 27 @override |
| 26 void setUp() { | 28 void setUp() { |
| 29 enableNewAnalysisDriver = true; |
| 27 super.setUp(); | 30 super.setUp(); |
| 28 ExtensionManager manager = new ExtensionManager(); | 31 ExtensionManager manager = new ExtensionManager(); |
| 29 manager.processPlugins([server.serverPlugin]); | 32 manager.processPlugins([server.serverPlugin]); |
| 30 handler = new EditDomainHandler(server); | 33 handler = new EditDomainHandler(server); |
| 31 } | 34 } |
| 32 | 35 |
| 33 test_fixUndefinedClass() async { | 36 test_fixUndefinedClass() async { |
| 34 createProject(); | 37 createProject(); |
| 35 addTestFile(''' | 38 addTestFile(''' |
| 36 main() { | 39 main() { |
| 37 Future<String> x = null; | 40 Future<String> x = null; |
| 38 } | 41 } |
| 39 '''); | 42 '''); |
| 40 await waitForTasksFinished(); | 43 await waitForTasksFinished(); |
| 41 List<AnalysisErrorFixes> errorFixes = await _getFixesAt('Future<String>'); | 44 List<AnalysisErrorFixes> errorFixes = await _getFixesAt('Future<String>'); |
| 42 expect(errorFixes, hasLength(1)); | 45 expect(errorFixes, hasLength(1)); |
| 43 AnalysisError error = errorFixes[0].error; | 46 AnalysisError error = errorFixes[0].error; |
| 44 expect(error.severity, AnalysisErrorSeverity.WARNING); | 47 expect(error.severity, AnalysisErrorSeverity.WARNING); |
| 45 expect(error.type, AnalysisErrorType.STATIC_WARNING); | 48 expect(error.type, AnalysisErrorType.STATIC_WARNING); |
| 46 List<SourceChange> fixes = errorFixes[0].fixes; | 49 List<SourceChange> fixes = errorFixes[0].fixes; |
| 47 expect(fixes, hasLength(2)); | 50 expect(fixes, hasLength(2)); |
| 48 expect(fixes[0].message, matches('Import library')); | 51 expect(fixes[0].message, matches('Import library')); |
| 49 expect(fixes[1].message, matches('Create class')); | 52 expect(fixes[1].message, matches('Create class')); |
| 50 } | 53 } |
| 51 | 54 |
| 55 test_fromPlugins() async { |
| 56 PluginInfo info = new PluginInfo('a', 'b', 'c', null, null); |
| 57 plugin.AnalysisErrorFixes fixes = new plugin.AnalysisErrorFixes( |
| 58 new plugin.AnalysisError( |
| 59 plugin.AnalysisErrorSeverity.ERROR, |
| 60 plugin.AnalysisErrorType.HINT, |
| 61 new plugin.Location('', 0, 0, 0, 0), |
| 62 'message', |
| 63 'code')); |
| 64 plugin.EditGetFixesResult result = |
| 65 new plugin.EditGetFixesResult(<plugin.AnalysisErrorFixes>[fixes]); |
| 66 pluginManager.broadcastResults = <PluginInfo, Future<plugin.Response>>{ |
| 67 info: new Future.value(result.toResponse('-')) |
| 68 }; |
| 69 |
| 70 createProject(); |
| 71 addTestFile('main() {}'); |
| 72 await waitForTasksFinished(); |
| 73 List<AnalysisErrorFixes> errorFixes = await _getFixesAt('in('); |
| 74 expect(errorFixes, hasLength(1)); |
| 75 } |
| 76 |
| 52 test_hasFixes() async { | 77 test_hasFixes() async { |
| 53 createProject(); | 78 createProject(); |
| 54 addTestFile(''' | 79 addTestFile(''' |
| 55 foo() { | 80 foo() { |
| 56 print(1) | 81 print(1) |
| 57 } | 82 } |
| 58 bar() { | 83 bar() { |
| 59 print(10) print(20) | 84 print(10) print(20) |
| 60 } | 85 } |
| 61 '''); | 86 '''); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return await _getFixes(offset); | 161 return await _getFixes(offset); |
| 137 } | 162 } |
| 138 | 163 |
| 139 void _isSyntacticErrorWithSingleFix(AnalysisErrorFixes fixes) { | 164 void _isSyntacticErrorWithSingleFix(AnalysisErrorFixes fixes) { |
| 140 AnalysisError error = fixes.error; | 165 AnalysisError error = fixes.error; |
| 141 expect(error.severity, AnalysisErrorSeverity.ERROR); | 166 expect(error.severity, AnalysisErrorSeverity.ERROR); |
| 142 expect(error.type, AnalysisErrorType.SYNTACTIC_ERROR); | 167 expect(error.type, AnalysisErrorType.SYNTACTIC_ERROR); |
| 143 expect(fixes.fixes, hasLength(1)); | 168 expect(fixes.fixes, hasLength(1)); |
| 144 } | 169 } |
| 145 } | 170 } |
| OLD | NEW |