| 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.services.correction.fix; | 5 library test.services.correction.fix; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 10 import 'package:analysis_server/plugin/protocol/protocol.dart' | 10 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 */ | 38 */ |
| 39 class BaseFixProcessorTest extends AbstractSingleUnitTest { | 39 class BaseFixProcessorTest extends AbstractSingleUnitTest { |
| 40 AnalysisErrorFilter errorFilter = (AnalysisError error) { | 40 AnalysisErrorFilter errorFilter = (AnalysisError error) { |
| 41 return error.errorCode != HintCode.UNUSED_CATCH_CLAUSE && | 41 return error.errorCode != HintCode.UNUSED_CATCH_CLAUSE && |
| 42 error.errorCode != HintCode.UNUSED_CATCH_STACK && | 42 error.errorCode != HintCode.UNUSED_CATCH_STACK && |
| 43 error.errorCode != HintCode.UNUSED_ELEMENT && | 43 error.errorCode != HintCode.UNUSED_ELEMENT && |
| 44 error.errorCode != HintCode.UNUSED_FIELD && | 44 error.errorCode != HintCode.UNUSED_FIELD && |
| 45 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; | 45 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 String myPkgLibPath = '/packages/my_pkg/lib'; |
| 49 |
| 48 Fix fix; | 50 Fix fix; |
| 49 SourceChange change; | 51 SourceChange change; |
| 50 String resultCode; | 52 String resultCode; |
| 51 | 53 |
| 52 assert_undefinedFunction_create_returnType_bool(String lineWithTest) async { | 54 assert_undefinedFunction_create_returnType_bool(String lineWithTest) async { |
| 53 resolveTestUnit(''' | 55 resolveTestUnit(''' |
| 54 main() { | 56 main() { |
| 55 bool b = true; | 57 bool b = true; |
| 56 $lineWithTest | 58 $lineWithTest |
| 57 } | 59 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 DefaultFixContributor contributor = new DefaultFixContributor(); | 148 DefaultFixContributor contributor = new DefaultFixContributor(); |
| 147 return contributor.computeFixes(fixContext); | 149 return contributor.computeFixes(fixContext); |
| 148 } | 150 } |
| 149 | 151 |
| 150 /** | 152 /** |
| 151 * Configures the [SourceFactory] to have the `my_pkg` package in | 153 * Configures the [SourceFactory] to have the `my_pkg` package in |
| 152 * `/packages/my_pkg/lib` folder. | 154 * `/packages/my_pkg/lib` folder. |
| 153 */ | 155 */ |
| 154 void _configureMyPkg(Map<String, String> pathToCode) { | 156 void _configureMyPkg(Map<String, String> pathToCode) { |
| 155 pathToCode.forEach((path, code) { | 157 pathToCode.forEach((path, code) { |
| 156 provider.newFile('/packages/my_pkg/lib/$path', code); | 158 provider.newFile('$myPkgLibPath/$path', code); |
| 157 }); | 159 }); |
| 158 // configure SourceFactory | 160 // configure SourceFactory |
| 159 Folder myPkgFolder = provider.getResource('/packages/my_pkg/lib'); | 161 Folder myPkgFolder = provider.getResource(myPkgLibPath); |
| 160 UriResolver pkgResolver = new PackageMapUriResolver(provider, { | 162 UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
| 161 'my_pkg': [myPkgFolder] | 163 'my_pkg': [myPkgFolder] |
| 162 }); | 164 }); |
| 163 context.sourceFactory = new SourceFactory( | 165 context.sourceFactory = new SourceFactory( |
| 164 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); | 166 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); |
| 165 // force 'my_pkg' resolution | 167 // force 'my_pkg' resolution |
| 166 addSource( | 168 addSource( |
| 167 '/tmp/other.dart', | 169 '/tmp/other.dart', |
| 168 pathToCode.keys | 170 pathToCode.keys |
| 169 .map((path) => "import 'package:my_pkg/$path';") | 171 .map((path) => "import 'package:my_pkg/$path';") |
| (...skipping 2938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3108 DartFixKind.IMPORT_LIBRARY_PROJECT2, | 3110 DartFixKind.IMPORT_LIBRARY_PROJECT2, |
| 3109 ''' | 3111 ''' |
| 3110 import 'package:my_pkg/a.dart'; | 3112 import 'package:my_pkg/a.dart'; |
| 3111 | 3113 |
| 3112 main() { | 3114 main() { |
| 3113 Test test = null; | 3115 Test test = null; |
| 3114 } | 3116 } |
| 3115 '''); | 3117 '''); |
| 3116 } | 3118 } |
| 3117 | 3119 |
| 3120 test_importLibraryPackage_preferDirectOverExport_src() async { |
| 3121 myPkgLibPath = '/my/src/packages/my_pkg/lib'; |
| 3122 _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); |
| 3123 resolveTestUnit(''' |
| 3124 main() { |
| 3125 Test test = null; |
| 3126 } |
| 3127 '''); |
| 3128 performAllAnalysisTasks(); |
| 3129 await assertHasFix( |
| 3130 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3131 ''' |
| 3132 import 'package:my_pkg/b.dart'; |
| 3133 |
| 3134 main() { |
| 3135 Test test = null; |
| 3136 } |
| 3137 '''); |
| 3138 await assertHasFix( |
| 3139 DartFixKind.IMPORT_LIBRARY_PROJECT2, |
| 3140 ''' |
| 3141 import 'package:my_pkg/a.dart'; |
| 3142 |
| 3143 main() { |
| 3144 Test test = null; |
| 3145 } |
| 3146 '''); |
| 3147 } |
| 3148 |
| 3118 test_importLibraryPackage_preferPublicOverPrivate() async { | 3149 test_importLibraryPackage_preferPublicOverPrivate() async { |
| 3119 _configureMyPkg( | 3150 _configureMyPkg( |
| 3120 {'src/a.dart': 'class Test {}', 'b.dart': "export 'src/a.dart';"}); | 3151 {'src/a.dart': 'class Test {}', 'b.dart': "export 'src/a.dart';"}); |
| 3121 resolveTestUnit(''' | 3152 resolveTestUnit(''' |
| 3122 main() { | 3153 main() { |
| 3123 Test test = null; | 3154 Test test = null; |
| 3124 } | 3155 } |
| 3125 '''); | 3156 '''); |
| 3126 performAllAnalysisTasks(); | 3157 performAllAnalysisTasks(); |
| 3127 await assertHasFix( | 3158 await assertHasFix( |
| (...skipping 2377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5505 var v = 42; | 5536 var v = 42; |
| 5506 print('v: $v'); | 5537 print('v: $v'); |
| 5507 } | 5538 } |
| 5508 '''); | 5539 '''); |
| 5509 } | 5540 } |
| 5510 | 5541 |
| 5511 void verifyResult(String expectedResult) { | 5542 void verifyResult(String expectedResult) { |
| 5512 expect(resultCode, expectedResult); | 5543 expect(resultCode, expectedResult); |
| 5513 } | 5544 } |
| 5514 } | 5545 } |
| OLD | NEW |