Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: pkg/analysis_server/test/services/refactoring/move_file_test.dart

Issue 1015513003: Issue 22757. Create pubspec.yaml file change on project rename. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:unittest/unittest.dart'; 14 import 'package:unittest/unittest.dart';
15 15
16 import '../../abstract_context.dart'; 16 import '../../abstract_context.dart';
17 import '../../reflective_tests.dart'; 17 import '../../reflective_tests.dart';
18 import 'abstract_refactoring.dart'; 18 import 'abstract_refactoring.dart';
19 19
20 main() { 20 main() {
21 groupSep = ' | '; 21 groupSep = ' | ';
22 runReflectiveTests(MoveFileTest); 22 runReflectiveTests(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 test_definingUnit() async { 29 test_file_definingUnit() async {
30 String pathA = '/project/000/1111/a.dart'; 30 String pathA = '/project/000/1111/a.dart';
31 String pathB = '/project/000/1111/b.dart'; 31 String pathB = '/project/000/1111/b.dart';
32 String pathC = '/project/000/1111/22/c.dart'; 32 String pathC = '/project/000/1111/22/c.dart';
33 String pathD = '/project/000/1111/333/d.dart'; 33 String pathD = '/project/000/1111/333/d.dart';
34 testFile = '/project/000/1111/test.dart'; 34 testFile = '/project/000/1111/test.dart';
35 addSource('/absolute/uri.dart', ''); 35 addSource('/absolute/uri.dart', '');
36 addSource(pathA, 'part of lib;'); 36 addSource(pathA, 'part of lib;');
37 addSource(pathB, "import 'test.dart';"); 37 addSource(pathB, "import 'test.dart';");
38 addSource(pathC, ''); 38 addSource(pathC, '');
39 addSource(pathD, ''); 39 addSource(pathD, '');
(...skipping 15 matching lines...) Expand all
55 assertFileChangeResult(testFile, ''' 55 assertFileChangeResult(testFile, '''
56 library lib; 56 library lib;
57 import 'dart:math'; 57 import 'dart:math';
58 import 'c.dart'; 58 import 'c.dart';
59 export '../333/d.dart'; 59 export '../333/d.dart';
60 part '../a.dart'; 60 part '../a.dart';
61 part '/absolute/uri.dart'; 61 part '/absolute/uri.dart';
62 '''); 62 ''');
63 } 63 }
64 64
65 test_importedLibrary() async { 65 test_file_importedLibrary() async {
66 String pathA = '/project/000/1111/a.dart'; 66 String pathA = '/project/000/1111/a.dart';
67 testFile = '/project/000/1111/sub/folder/test.dart'; 67 testFile = '/project/000/1111/sub/folder/test.dart';
68 addSource(pathA, ''' 68 addSource(pathA, '''
69 import 'sub/folder/test.dart'; 69 import 'sub/folder/test.dart';
70 '''); 70 ''');
71 addTestSource(''); 71 addTestSource('');
72 _performAnalysis(); 72 _performAnalysis();
73 // perform refactoring 73 // perform refactoring
74 _createRefactoring('/project/000/new/folder/name/new_name.dart'); 74 _createRefactoring('/project/000/new/folder/name/new_name.dart');
75 await _assertSuccessfulRefactoring(); 75 await _assertSuccessfulRefactoring();
76 assertFileChangeResult(pathA, ''' 76 assertFileChangeResult(pathA, '''
77 import '../new/folder/name/new_name.dart'; 77 import '../new/folder/name/new_name.dart';
78 '''); 78 ''');
79 assertNoFileChange(testFile); 79 assertNoFileChange(testFile);
80 } 80 }
81 81
82 test_importedLibrary_down() async { 82 test_file_importedLibrary_down() async {
83 String pathA = '/project/000/1111/a.dart'; 83 String pathA = '/project/000/1111/a.dart';
84 testFile = '/project/000/1111/test.dart'; 84 testFile = '/project/000/1111/test.dart';
85 addSource(pathA, ''' 85 addSource(pathA, '''
86 import 'test.dart'; 86 import 'test.dart';
87 '''); 87 ''');
88 addTestSource(''); 88 addTestSource('');
89 _performAnalysis(); 89 _performAnalysis();
90 // perform refactoring 90 // perform refactoring
91 _createRefactoring('/project/000/1111/22/new_name.dart'); 91 _createRefactoring('/project/000/1111/22/new_name.dart');
92 await _assertSuccessfulRefactoring(); 92 await _assertSuccessfulRefactoring();
93 assertFileChangeResult(pathA, ''' 93 assertFileChangeResult(pathA, '''
94 import '22/new_name.dart'; 94 import '22/new_name.dart';
95 '''); 95 ''');
96 assertNoFileChange(testFile); 96 assertNoFileChange(testFile);
97 } 97 }
98 98
99 test_importedLibrary_package() async { 99 test_file_importedLibrary_package() async {
100 // configure packages 100 // configure packages
101 testFile = '/packages/my_pkg/aaa/test.dart'; 101 testFile = '/packages/my_pkg/aaa/test.dart';
102 provider.newFile(testFile, ''); 102 provider.newFile(testFile, '');
103 Map<String, List<Folder>> packageMap = { 103 Map<String, List<Folder>> packageMap = {
104 'my_pkg': [provider.getResource('/packages/my_pkg')] 104 'my_pkg': [provider.getResource('/packages/my_pkg')]
105 }; 105 };
106 context.sourceFactory = new SourceFactory([ 106 context.sourceFactory = new SourceFactory([
107 AbstractContextTest.SDK_RESOLVER, 107 AbstractContextTest.SDK_RESOLVER,
108 resourceResolver, 108 resourceResolver,
109 new PackageMapUriResolver(provider, packageMap) 109 new PackageMapUriResolver(provider, packageMap)
110 ]); 110 ]);
111 // do testing 111 // do testing
112 String pathA = '/project/bin/a.dart'; 112 String pathA = '/project/bin/a.dart';
113 addSource(pathA, ''' 113 addSource(pathA, '''
114 import 'package:my_pkg/aaa/test.dart'; 114 import 'package:my_pkg/aaa/test.dart';
115 '''); 115 ''');
116 addTestSource(''); 116 addTestSource('');
117 _performAnalysis(); 117 _performAnalysis();
118 // perform refactoring 118 // perform refactoring
119 _createRefactoring('/packages/my_pkg/bbb/ccc/new_name.dart'); 119 _createRefactoring('/packages/my_pkg/bbb/ccc/new_name.dart');
120 await _assertSuccessfulRefactoring(); 120 await _assertSuccessfulRefactoring();
121 assertFileChangeResult(pathA, ''' 121 assertFileChangeResult(pathA, '''
122 import 'package:my_pkg/bbb/ccc/new_name.dart'; 122 import 'package:my_pkg/bbb/ccc/new_name.dart';
123 '''); 123 ''');
124 assertNoFileChange(testFile); 124 assertNoFileChange(testFile);
125 } 125 }
126 126
127 test_importedLibrary_up() async { 127 test_file_importedLibrary_up() async {
128 String pathA = '/project/000/1111/a.dart'; 128 String pathA = '/project/000/1111/a.dart';
129 testFile = '/project/000/1111/22/test.dart'; 129 testFile = '/project/000/1111/22/test.dart';
130 addSource(pathA, ''' 130 addSource(pathA, '''
131 import '22/test.dart'; 131 import '22/test.dart';
132 '''); 132 ''');
133 addTestSource(''); 133 addTestSource('');
134 _performAnalysis(); 134 _performAnalysis();
135 // perform refactoring 135 // perform refactoring
136 _createRefactoring('/project/000/1111/new_name.dart'); 136 _createRefactoring('/project/000/1111/new_name.dart');
137 await _assertSuccessfulRefactoring(); 137 await _assertSuccessfulRefactoring();
138 assertFileChangeResult(pathA, ''' 138 assertFileChangeResult(pathA, '''
139 import 'new_name.dart'; 139 import 'new_name.dart';
140 '''); 140 ''');
141 assertNoFileChange(testFile); 141 assertNoFileChange(testFile);
142 } 142 }
143 143
144 test_sourcedUnit() async { 144 test_file_sourcedUnit() async {
145 String pathA = '/project/000/1111/a.dart'; 145 String pathA = '/project/000/1111/a.dart';
146 testFile = '/project/000/1111/22/test.dart'; 146 testFile = '/project/000/1111/22/test.dart';
147 addSource(pathA, ''' 147 addSource(pathA, '''
148 part '22/test.dart'; 148 part '22/test.dart';
149 '''); 149 ''');
150 addTestSource(''); 150 addTestSource('');
151 _performAnalysis(); 151 _performAnalysis();
152 // perform refactoring 152 // perform refactoring
153 _createRefactoring('/project/000/1111/22/new_name.dart'); 153 _createRefactoring('/project/000/1111/22/new_name.dart');
154 await _assertSuccessfulRefactoring(); 154 await _assertSuccessfulRefactoring();
155 assertFileChangeResult(pathA, ''' 155 assertFileChangeResult(pathA, '''
156 part '22/new_name.dart'; 156 part '22/new_name.dart';
157 '''); 157 ''');
158 assertNoFileChange(testFile); 158 assertNoFileChange(testFile);
159 } 159 }
160 160
161 test_sourcedUnit_multipleLibraries() async { 161 test_file_sourcedUnit_multipleLibraries() async {
162 String pathA = '/project/000/1111/a.dart'; 162 String pathA = '/project/000/1111/a.dart';
163 String pathB = '/project/000/b.dart'; 163 String pathB = '/project/000/b.dart';
164 testFile = '/project/000/1111/22/test.dart'; 164 testFile = '/project/000/1111/22/test.dart';
165 addSource(pathA, ''' 165 addSource(pathA, '''
166 part '22/test.dart'; 166 part '22/test.dart';
167 '''); 167 ''');
168 addSource(pathB, ''' 168 addSource(pathB, '''
169 part '1111/22/test.dart'; 169 part '1111/22/test.dart';
170 '''); 170 ''');
171 addTestSource(''); 171 addTestSource('');
172 _performAnalysis(); 172 _performAnalysis();
173 // perform refactoring 173 // perform refactoring
174 _createRefactoring('/project/000/1111/22/new_name.dart'); 174 _createRefactoring('/project/000/1111/22/new_name.dart');
175 await _assertSuccessfulRefactoring(); 175 await _assertSuccessfulRefactoring();
176 assertFileChangeResult(pathA, ''' 176 assertFileChangeResult(pathA, '''
177 part '22/new_name.dart'; 177 part '22/new_name.dart';
178 '''); 178 ''');
179 assertFileChangeResult(pathB, ''' 179 assertFileChangeResult(pathB, '''
180 part '1111/22/new_name.dart'; 180 part '1111/22/new_name.dart';
181 '''); 181 ''');
182 assertNoFileChange(testFile); 182 assertNoFileChange(testFile);
183 } 183 }
184 184
185 test_project() async {
186 String pubspecPath = '/testName/pubspec.yaml';
187 String appPath = '/testName/bin/myApp.dart';
188 provider.newFile(pubspecPath, '''
189 name: testName
190 version: 0.0.1
191 description: My pubspec file.
192 ''');
193 addSource('/testName/lib/myLib.dart', '');
194 addSource(appPath, '''
195 import 'package:testName/myLib.dart';
196 ''');
197 addTestSource('');
198 _performAnalysis();
199 // perform refactoring
200 refactoring = new MoveFileRefactoring(
201 provider, searchEngine, context, null, '/testName');
202 refactoring.newFile = '/newName';
203 await _assertSuccessfulRefactoring();
204 // print(refactoringChange);
205 assertFileChangeResult(pubspecPath, '''
206 name: newName
207 version: 0.0.1
208 description: My pubspec file.
209 ''');
210 // TODO(scheglov) update self references
211 // assertFileChangeResult(appPath, '''
212 //import 'package:newName/myLib.dart';
213 //''');
214 }
215
185 /** 216 /**
186 * Checks that all conditions are OK. 217 * Checks that all conditions are OK.
187 */ 218 */
188 Future _assertSuccessfulRefactoring() async { 219 Future _assertSuccessfulRefactoring() async {
189 await assertRefactoringConditionsOK(); 220 await assertRefactoringConditionsOK();
190 refactoringChange = await refactoring.createChange(); 221 refactoringChange = await refactoring.createChange();
191 } 222 }
192 223
193 void _createRefactoring(String newName) { 224 void _createRefactoring(String newName) {
194 refactoring = new MoveFileRefactoring( 225 refactoring = new MoveFileRefactoring(
195 provider.pathContext, searchEngine, context, testSource); 226 provider, searchEngine, context, testSource, null);
196 refactoring.newFile = newName; 227 refactoring.newFile = newName;
197 } 228 }
198 229
199 void _performAnalysis() { 230 void _performAnalysis() {
200 while (true) { 231 while (true) {
201 AnalysisResult result = context.performAnalysisTask(); 232 AnalysisResult result = context.performAnalysisTask();
202 if (!result.hasMoreWork) { 233 if (!result.hasMoreWork) {
203 break; 234 break;
204 } 235 }
205 for (ChangeNotice notice in result.changeNotices) { 236 for (ChangeNotice notice in result.changeNotices) {
206 if (notice.source.fullName.startsWith('/project/')) { 237 if (notice.source.fullName.startsWith('/project/')) {
207 index.indexUnit(context, notice.resolvedDartUnit); 238 index.indexUnit(context, notice.resolvedDartUnit);
208 } 239 }
209 } 240 }
210 } 241 }
211 } 242 }
212 } 243 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698