| 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.refactoring.move_files; | 5 library test.services.refactoring.move_files; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/source/package_map_resolver.dart'; | 11 import 'package:analyzer/source/package_map_resolver.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 | 15 |
| 16 import '../../abstract_context.dart'; | 16 import '../../abstract_context.dart'; |
| 17 import '../../utils.dart'; | 17 import '../../utils.dart'; |
| 18 import 'abstract_refactoring.dart'; | 18 import 'abstract_refactoring.dart'; |
| 19 | 19 |
| 20 main() { | 20 main() { |
| 21 initializeTestEnvironment(); | 21 initializeTestEnvironment(); |
| 22 defineReflectiveTests(MoveFileTest); | 22 defineReflectiveTests(MoveFileTest); |
| 23 } | 23 } |
| 24 | 24 |
| 25 @reflectiveTest | 25 @reflectiveTest |
| 26 class MoveFileTest extends RefactoringTest { | 26 class MoveFileTest extends RefactoringTest { |
| 27 MoveFileRefactoring refactoring; | 27 MoveFileRefactoring refactoring; |
| 28 | 28 |
| 29 /** | |
| 30 * TODO(scheglov) fix search of units | |
| 31 */ | |
| 32 fail_file_importedLibrary_package() async { | |
| 33 // configure packages | |
| 34 testFile = '/packages/my_pkg/aaa/test.dart'; | |
| 35 provider.newFile(testFile, ''); | |
| 36 Map<String, List<Folder>> packageMap = { | |
| 37 'my_pkg': [provider.getResource('/packages/my_pkg')] | |
| 38 }; | |
| 39 context.sourceFactory = new SourceFactory([ | |
| 40 AbstractContextTest.SDK_RESOLVER, | |
| 41 new PackageMapUriResolver(provider, packageMap), | |
| 42 resourceResolver | |
| 43 ]); | |
| 44 // do testing | |
| 45 String pathA = '/project/bin/a.dart'; | |
| 46 addSource( | |
| 47 pathA, | |
| 48 ''' | |
| 49 import 'package:my_pkg/aaa/test.dart'; | |
| 50 '''); | |
| 51 addTestSource(''); | |
| 52 _performAnalysis(); | |
| 53 // perform refactoring | |
| 54 _createRefactoring('/packages/my_pkg/bbb/ccc/new_name.dart'); | |
| 55 await _assertSuccessfulRefactoring(); | |
| 56 assertFileChangeResult( | |
| 57 pathA, | |
| 58 ''' | |
| 59 import 'package:my_pkg/bbb/ccc/new_name.dart'; | |
| 60 '''); | |
| 61 assertNoFileChange(testFile); | |
| 62 } | |
| 63 | |
| 64 test_file_definingUnit() async { | 29 test_file_definingUnit() async { |
| 65 String pathA = '/project/000/1111/a.dart'; | 30 String pathA = '/project/000/1111/a.dart'; |
| 66 String pathB = '/project/000/1111/b.dart'; | 31 String pathB = '/project/000/1111/b.dart'; |
| 67 String pathC = '/project/000/1111/22/c.dart'; | 32 String pathC = '/project/000/1111/22/c.dart'; |
| 68 String pathD = '/project/000/1111/333/d.dart'; | 33 String pathD = '/project/000/1111/333/d.dart'; |
| 69 testFile = '/project/000/1111/test.dart'; | 34 testFile = '/project/000/1111/test.dart'; |
| 70 addSource('/absolute/uri.dart', ''); | 35 addSource('/absolute/uri.dart', ''); |
| 71 addSource(pathA, 'part of lib;'); | 36 addSource(pathA, 'part of lib;'); |
| 72 addSource(pathB, "import 'test.dart';"); | 37 addSource(pathB, "import 'test.dart';"); |
| 73 addSource(pathC, ''); | 38 addSource(pathC, ''); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 _createRefactoring('/project/000/1111/22/new_name.dart'); | 99 _createRefactoring('/project/000/1111/22/new_name.dart'); |
| 135 await _assertSuccessfulRefactoring(); | 100 await _assertSuccessfulRefactoring(); |
| 136 assertFileChangeResult( | 101 assertFileChangeResult( |
| 137 pathA, | 102 pathA, |
| 138 ''' | 103 ''' |
| 139 import '22/new_name.dart'; | 104 import '22/new_name.dart'; |
| 140 '''); | 105 '''); |
| 141 assertNoFileChange(testFile); | 106 assertNoFileChange(testFile); |
| 142 } | 107 } |
| 143 | 108 |
| 109 test_file_importedLibrary_package() async { |
| 110 // configure packages |
| 111 testFile = '/packages/my_pkg/lib/aaa/test.dart'; |
| 112 provider.newFile(testFile, ''); |
| 113 Map<String, List<Folder>> packageMap = { |
| 114 'my_pkg': [provider.getResource('/packages/my_pkg/lib')] |
| 115 }; |
| 116 context.sourceFactory = new SourceFactory([ |
| 117 AbstractContextTest.SDK_RESOLVER, |
| 118 new PackageMapUriResolver(provider, packageMap), |
| 119 resourceResolver |
| 120 ]); |
| 121 // do testing |
| 122 String pathA = '/project/bin/a.dart'; |
| 123 addSource( |
| 124 pathA, |
| 125 ''' |
| 126 import 'package:my_pkg/aaa/test.dart'; |
| 127 '''); |
| 128 addTestSource('', Uri.parse('package:my_pkg/aaa/test.dart')); |
| 129 _performAnalysis(); |
| 130 // perform refactoring |
| 131 _createRefactoring('/packages/my_pkg/lib/bbb/ccc/new_name.dart'); |
| 132 await _assertSuccessfulRefactoring(); |
| 133 assertFileChangeResult( |
| 134 pathA, |
| 135 ''' |
| 136 import 'package:my_pkg/bbb/ccc/new_name.dart'; |
| 137 '''); |
| 138 assertNoFileChange(testFile); |
| 139 } |
| 140 |
| 144 test_file_importedLibrary_up() async { | 141 test_file_importedLibrary_up() async { |
| 145 String pathA = '/project/000/1111/a.dart'; | 142 String pathA = '/project/000/1111/a.dart'; |
| 146 testFile = '/project/000/1111/22/test.dart'; | 143 testFile = '/project/000/1111/22/test.dart'; |
| 147 addSource( | 144 addSource( |
| 148 pathA, | 145 pathA, |
| 149 ''' | 146 ''' |
| 150 import '22/test.dart'; | 147 import '22/test.dart'; |
| 151 '''); | 148 '''); |
| 152 addTestSource(''); | 149 addTestSource(''); |
| 153 _performAnalysis(); | 150 _performAnalysis(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 break; | 290 break; |
| 294 } | 291 } |
| 295 for (ChangeNotice notice in result.changeNotices) { | 292 for (ChangeNotice notice in result.changeNotices) { |
| 296 if (notice.source.fullName.startsWith('/project/')) { | 293 if (notice.source.fullName.startsWith('/project/')) { |
| 297 index.indexUnit(notice.resolvedDartUnit); | 294 index.indexUnit(notice.resolvedDartUnit); |
| 298 } | 295 } |
| 299 } | 296 } |
| 300 } | 297 } |
| 301 } | 298 } |
| 302 } | 299 } |
| OLD | NEW |