| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 | |
| 7 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | |
| 8 import 'package:test/test.dart'; | |
| 9 import 'package:test_reflective_loader/test_reflective_loader.dart'; | |
| 10 | |
| 11 import 'abstract_refactoring.dart'; | |
| 12 | |
| 13 main() { | |
| 14 defineReflectiveSuite(() { | |
| 15 defineReflectiveTests(MoveFileTest); | |
| 16 }); | |
| 17 } | |
| 18 | |
| 19 @reflectiveTest | |
| 20 class MoveFileTest extends RefactoringTest { | |
| 21 MoveFileRefactoring refactoring; | |
| 22 | |
| 23 @failingTest | |
| 24 test_file_definingUnit() async { | |
| 25 fail('The move file refactoring is not supported under the new driver'); | |
| 26 String pathA = '/project/000/1111/a.dart'; | |
| 27 String pathB = '/project/000/1111/b.dart'; | |
| 28 String pathC = '/project/000/1111/22/c.dart'; | |
| 29 String pathD = '/project/000/1111/333/d.dart'; | |
| 30 testFile = '/project/000/1111/test.dart'; | |
| 31 addSource('/absolute/uri.dart', ''); | |
| 32 addSource(pathA, 'part of lib;'); | |
| 33 addSource(pathB, "import 'test.dart';"); | |
| 34 addSource(pathC, ''); | |
| 35 addSource(pathD, ''); | |
| 36 addTestSource(''' | |
| 37 library lib; | |
| 38 import 'dart:math'; | |
| 39 import '22/c.dart'; | |
| 40 export '333/d.dart'; | |
| 41 part 'a.dart'; | |
| 42 part '/absolute/uri.dart'; | |
| 43 '''); | |
| 44 // perform refactoring | |
| 45 _createRefactoring('/project/000/1111/22/new_name.dart'); | |
| 46 await _assertSuccessfulRefactoring(); | |
| 47 assertNoFileChange(pathA); | |
| 48 assertFileChangeResult(pathB, "import '22/new_name.dart';"); | |
| 49 assertNoFileChange(pathC); | |
| 50 assertFileChangeResult(testFile, ''' | |
| 51 library lib; | |
| 52 import 'dart:math'; | |
| 53 import 'c.dart'; | |
| 54 export '../333/d.dart'; | |
| 55 part '../a.dart'; | |
| 56 part '/absolute/uri.dart'; | |
| 57 '''); | |
| 58 } | |
| 59 | |
| 60 @failingTest | |
| 61 test_file_importedLibrary() async { | |
| 62 fail('The move file refactoring is not supported under the new driver'); | |
| 63 String pathA = '/project/000/1111/a.dart'; | |
| 64 testFile = '/project/000/1111/sub/folder/test.dart'; | |
| 65 addSource(pathA, ''' | |
| 66 import 'sub/folder/test.dart'; | |
| 67 '''); | |
| 68 addTestSource(''); | |
| 69 // perform refactoring | |
| 70 _createRefactoring('/project/000/new/folder/name/new_name.dart'); | |
| 71 await _assertSuccessfulRefactoring(); | |
| 72 assertFileChangeResult(pathA, ''' | |
| 73 import '../new/folder/name/new_name.dart'; | |
| 74 '''); | |
| 75 assertNoFileChange(testFile); | |
| 76 } | |
| 77 | |
| 78 @failingTest | |
| 79 test_file_importedLibrary_down() async { | |
| 80 fail('The move file refactoring is not supported under the new driver'); | |
| 81 String pathA = '/project/000/1111/a.dart'; | |
| 82 testFile = '/project/000/1111/test.dart'; | |
| 83 addSource(pathA, ''' | |
| 84 import 'test.dart'; | |
| 85 '''); | |
| 86 addTestSource(''); | |
| 87 // perform refactoring | |
| 88 _createRefactoring('/project/000/1111/22/new_name.dart'); | |
| 89 await _assertSuccessfulRefactoring(); | |
| 90 assertFileChangeResult(pathA, ''' | |
| 91 import '22/new_name.dart'; | |
| 92 '''); | |
| 93 assertNoFileChange(testFile); | |
| 94 } | |
| 95 | |
| 96 @failingTest | |
| 97 test_file_importedLibrary_package() async { | |
| 98 fail('The move file refactoring is not supported under the new driver'); | |
| 99 // configure packages | |
| 100 testFile = '/packages/my_pkg/lib/aaa/test.dart'; | |
| 101 provider.newFile(testFile, ''); | |
| 102 // TODO(brianwilkerson) Figure out what this should be replaced with. | |
| 103 // Map<String, List<Folder>> packageMap = { | |
| 104 // 'my_pkg': <Folder>[provider.getResource('/packages/my_pkg/lib')] | |
| 105 // }; | |
| 106 // context.sourceFactory = new SourceFactory([ | |
| 107 // new DartUriResolver(sdk), | |
| 108 // new PackageMapUriResolver(provider, packageMap), | |
| 109 // resourceResolver | |
| 110 // ]); | |
| 111 // do testing | |
| 112 String pathA = '/project/bin/a.dart'; | |
| 113 addSource(pathA, ''' | |
| 114 import 'package:my_pkg/aaa/test.dart'; | |
| 115 '''); | |
| 116 addTestSource('', Uri.parse('package:my_pkg/aaa/test.dart')); | |
| 117 // perform refactoring | |
| 118 _createRefactoring('/packages/my_pkg/lib/bbb/ccc/new_name.dart'); | |
| 119 await _assertSuccessfulRefactoring(); | |
| 120 assertFileChangeResult(pathA, ''' | |
| 121 import 'package:my_pkg/bbb/ccc/new_name.dart'; | |
| 122 '''); | |
| 123 assertNoFileChange(testFile); | |
| 124 } | |
| 125 | |
| 126 @failingTest | |
| 127 test_file_importedLibrary_up() async { | |
| 128 fail('The move file refactoring is not supported under the new driver'); | |
| 129 String pathA = '/project/000/1111/a.dart'; | |
| 130 testFile = '/project/000/1111/22/test.dart'; | |
| 131 addSource(pathA, ''' | |
| 132 import '22/test.dart'; | |
| 133 '''); | |
| 134 addTestSource(''); | |
| 135 // perform refactoring | |
| 136 _createRefactoring('/project/000/1111/new_name.dart'); | |
| 137 await _assertSuccessfulRefactoring(); | |
| 138 assertFileChangeResult(pathA, ''' | |
| 139 import 'new_name.dart'; | |
| 140 '''); | |
| 141 assertNoFileChange(testFile); | |
| 142 } | |
| 143 | |
| 144 @failingTest | |
| 145 test_file_sourcedUnit() async { | |
| 146 fail('The move file refactoring is not supported under the new driver'); | |
| 147 String pathA = '/project/000/1111/a.dart'; | |
| 148 testFile = '/project/000/1111/22/test.dart'; | |
| 149 addSource(pathA, ''' | |
| 150 library lib; | |
| 151 part '22/test.dart'; | |
| 152 '''); | |
| 153 addTestSource(''' | |
| 154 part of lib; | |
| 155 '''); | |
| 156 // perform refactoring | |
| 157 _createRefactoring('/project/000/1111/22/new_name.dart'); | |
| 158 await _assertSuccessfulRefactoring(); | |
| 159 assertFileChangeResult(pathA, ''' | |
| 160 library lib; | |
| 161 part '22/new_name.dart'; | |
| 162 '''); | |
| 163 assertNoFileChange(testFile); | |
| 164 } | |
| 165 | |
| 166 @failingTest | |
| 167 test_file_sourcedUnit_multipleLibraries() async { | |
| 168 fail('The move file refactoring is not supported under the new driver'); | |
| 169 String pathA = '/project/000/1111/a.dart'; | |
| 170 String pathB = '/project/000/b.dart'; | |
| 171 testFile = '/project/000/1111/22/test.dart'; | |
| 172 addSource(pathA, ''' | |
| 173 library lib; | |
| 174 part '22/test.dart'; | |
| 175 '''); | |
| 176 addSource(pathB, ''' | |
| 177 library lib; | |
| 178 part '1111/22/test.dart'; | |
| 179 '''); | |
| 180 addTestSource(''' | |
| 181 part of lib; | |
| 182 '''); | |
| 183 // perform refactoring | |
| 184 _createRefactoring('/project/000/1111/22/new_name.dart'); | |
| 185 await _assertSuccessfulRefactoring(); | |
| 186 assertFileChangeResult(pathA, ''' | |
| 187 library lib; | |
| 188 part '22/new_name.dart'; | |
| 189 '''); | |
| 190 assertFileChangeResult(pathB, ''' | |
| 191 library lib; | |
| 192 part '1111/22/new_name.dart'; | |
| 193 '''); | |
| 194 assertNoFileChange(testFile); | |
| 195 } | |
| 196 | |
| 197 @failingTest | |
| 198 test_project() async { | |
| 199 fail('The move file refactoring is not supported under the new driver'); | |
| 200 String pubspecPath = '/testName/pubspec.yaml'; | |
| 201 String appPath = '/testName/bin/myApp.dart'; | |
| 202 provider.newFile(pubspecPath, ''' | |
| 203 name: testName | |
| 204 version: 0.0.1 | |
| 205 description: My pubspec file. | |
| 206 '''); | |
| 207 addSource('/testName/lib/myLib.dart', ''); | |
| 208 addSource(appPath, ''' | |
| 209 import 'package:testName/myLib.dart'; | |
| 210 export 'package:testName/myLib.dart'; | |
| 211 '''); | |
| 212 // configure Uri resolves | |
| 213 // TODO(brianwilkerson) Figure out what this should be replaced with. | |
| 214 // context.sourceFactory = new SourceFactory([ | |
| 215 // new DartUriResolver(sdk), | |
| 216 // new PackageMapUriResolver(provider, <String, List<Folder>>{ | |
| 217 // 'testName': <Folder>[provider.getResource('/testName/lib')] | |
| 218 // }), | |
| 219 // resourceResolver, | |
| 220 // ]); | |
| 221 // perform refactoring | |
| 222 refactoring = new MoveFileRefactoring( | |
| 223 provider, searchEngine, null, null, '/testName'); | |
| 224 refactoring.newFile = '/newName'; | |
| 225 await _assertSuccessfulRefactoring(); | |
| 226 assertFileChangeResult(pubspecPath, ''' | |
| 227 name: newName | |
| 228 version: 0.0.1 | |
| 229 description: My pubspec file. | |
| 230 '''); | |
| 231 assertFileChangeResult(appPath, ''' | |
| 232 import 'package:newName/myLib.dart'; | |
| 233 export 'package:newName/myLib.dart'; | |
| 234 '''); | |
| 235 } | |
| 236 | |
| 237 /** | |
| 238 * Checks that all conditions are OK. | |
| 239 */ | |
| 240 Future _assertSuccessfulRefactoring() async { | |
| 241 await assertRefactoringConditionsOK(); | |
| 242 refactoringChange = await refactoring.createChange(); | |
| 243 } | |
| 244 | |
| 245 void _createRefactoring(String newName) { | |
| 246 refactoring = | |
| 247 new MoveFileRefactoring(provider, searchEngine, null, testSource, null); | |
| 248 refactoring.newFile = newName; | |
| 249 } | |
| 250 } | |
| OLD | NEW |