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

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

Issue 908463004: Convert refactoring tests to use 'await'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
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/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; 10 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
(...skipping 11 matching lines...) Expand all
22 main() { 22 main() {
23 groupSep = ' | '; 23 groupSep = ' | ';
24 runReflectiveTests(MoveFileTest); 24 runReflectiveTests(MoveFileTest);
25 } 25 }
26 26
27 27
28 @reflectiveTest 28 @reflectiveTest
29 class MoveFileTest extends RefactoringTest { 29 class MoveFileTest extends RefactoringTest {
30 MoveFileRefactoring refactoring; 30 MoveFileRefactoring refactoring;
31 31
32 test_definingUnit() { 32 test_definingUnit() async {
33 String pathA = '/project/000/1111/a.dart'; 33 String pathA = '/project/000/1111/a.dart';
34 String pathB = '/project/000/1111/b.dart'; 34 String pathB = '/project/000/1111/b.dart';
35 String pathC = '/project/000/1111/22/c.dart'; 35 String pathC = '/project/000/1111/22/c.dart';
36 String pathD = '/project/000/1111/333/d.dart'; 36 String pathD = '/project/000/1111/333/d.dart';
37 testFile = '/project/000/1111/test.dart'; 37 testFile = '/project/000/1111/test.dart';
38 addSource('/absolute/uri.dart', ''); 38 addSource('/absolute/uri.dart', '');
39 addSource(pathA, 'part of lib;'); 39 addSource(pathA, 'part of lib;');
40 addSource(pathB, "import 'test.dart';"); 40 addSource(pathB, "import 'test.dart';");
41 addSource(pathC, ''); 41 addSource(pathC, '');
42 addSource(pathD, ''); 42 addSource(pathD, '');
43 addTestSource(''' 43 addTestSource('''
44 library lib; 44 library lib;
45 import 'dart:math'; 45 import 'dart:math';
46 import '22/c.dart'; 46 import '22/c.dart';
47 export '333/d.dart'; 47 export '333/d.dart';
48 part 'a.dart'; 48 part 'a.dart';
49 part '/absolute/uri.dart'; 49 part '/absolute/uri.dart';
50 '''); 50 ''');
51 _performAnalysis(); 51 _performAnalysis();
52 // perform refactoring 52 // perform refactoring
53 _createRefactoring('/project/000/1111/22/new_name.dart'); 53 _createRefactoring('/project/000/1111/22/new_name.dart');
54 return _assertSuccessfulRefactoring().then((_) { 54 await _assertSuccessfulRefactoring();
55 assertNoFileChange(pathA); 55 assertNoFileChange(pathA);
56 assertFileChangeResult(pathB, "import '22/new_name.dart';"); 56 assertFileChangeResult(pathB, "import '22/new_name.dart';");
57 assertNoFileChange(pathC); 57 assertNoFileChange(pathC);
58 assertFileChangeResult(testFile, ''' 58 assertFileChangeResult(testFile, '''
59 library lib; 59 library lib;
60 import 'dart:math'; 60 import 'dart:math';
61 import 'c.dart'; 61 import 'c.dart';
62 export '../333/d.dart'; 62 export '../333/d.dart';
63 part '../a.dart'; 63 part '../a.dart';
64 part '/absolute/uri.dart'; 64 part '/absolute/uri.dart';
65 '''); 65 ''');
66 });
67 } 66 }
68 67
69 test_importedLibrary() { 68 test_importedLibrary() async {
70 String pathA = '/project/000/1111/a.dart'; 69 String pathA = '/project/000/1111/a.dart';
71 testFile = '/project/000/1111/sub/folder/test.dart'; 70 testFile = '/project/000/1111/sub/folder/test.dart';
72 addSource(pathA, ''' 71 addSource(pathA, '''
73 import 'sub/folder/test.dart'; 72 import 'sub/folder/test.dart';
74 '''); 73 ''');
75 addTestSource(''); 74 addTestSource('');
76 _performAnalysis(); 75 _performAnalysis();
77 // perform refactoring 76 // perform refactoring
78 _createRefactoring('/project/000/new/folder/name/new_name.dart'); 77 _createRefactoring('/project/000/new/folder/name/new_name.dart');
79 return _assertSuccessfulRefactoring().then((_) { 78 await _assertSuccessfulRefactoring();
80 assertFileChangeResult(pathA, ''' 79 assertFileChangeResult(pathA, '''
81 import '../new/folder/name/new_name.dart'; 80 import '../new/folder/name/new_name.dart';
82 '''); 81 ''');
83 assertNoFileChange(testFile); 82 assertNoFileChange(testFile);
84 });
85 } 83 }
86 84
87 test_importedLibrary_down() { 85 test_importedLibrary_down() async {
88 String pathA = '/project/000/1111/a.dart'; 86 String pathA = '/project/000/1111/a.dart';
89 testFile = '/project/000/1111/test.dart'; 87 testFile = '/project/000/1111/test.dart';
90 addSource(pathA, ''' 88 addSource(pathA, '''
91 import 'test.dart'; 89 import 'test.dart';
92 '''); 90 ''');
93 addTestSource(''); 91 addTestSource('');
94 _performAnalysis(); 92 _performAnalysis();
95 // perform refactoring 93 // perform refactoring
96 _createRefactoring('/project/000/1111/22/new_name.dart'); 94 _createRefactoring('/project/000/1111/22/new_name.dart');
97 return _assertSuccessfulRefactoring().then((_) { 95 await _assertSuccessfulRefactoring();
98 assertFileChangeResult(pathA, ''' 96 assertFileChangeResult(pathA, '''
99 import '22/new_name.dart'; 97 import '22/new_name.dart';
100 '''); 98 ''');
101 assertNoFileChange(testFile); 99 assertNoFileChange(testFile);
102 });
103 } 100 }
104 101
105 test_importedLibrary_package() { 102 test_importedLibrary_package() async {
106 // configure packages 103 // configure packages
107 testFile = '/packages/my_pkg/aaa/test.dart'; 104 testFile = '/packages/my_pkg/aaa/test.dart';
108 provider.newFile(testFile, ''); 105 provider.newFile(testFile, '');
109 Map<String, List<Folder>> packageMap = { 106 Map<String, List<Folder>> packageMap = {
110 'my_pkg': [provider.getResource('/packages/my_pkg')] 107 'my_pkg': [provider.getResource('/packages/my_pkg')]
111 }; 108 };
112 context.sourceFactory = new SourceFactory( 109 context.sourceFactory = new SourceFactory(
113 [ 110 [
114 AbstractContextTest.SDK_RESOLVER, 111 AbstractContextTest.SDK_RESOLVER,
115 resourceResolver, 112 resourceResolver,
116 new PackageMapUriResolver(provider, packageMap)]); 113 new PackageMapUriResolver(provider, packageMap)]);
117 // do testing 114 // do testing
118 String pathA = '/project/bin/a.dart'; 115 String pathA = '/project/bin/a.dart';
119 addSource(pathA, ''' 116 addSource(pathA, '''
120 import 'package:my_pkg/aaa/test.dart'; 117 import 'package:my_pkg/aaa/test.dart';
121 '''); 118 ''');
122 addTestSource(''); 119 addTestSource('');
123 _performAnalysis(); 120 _performAnalysis();
124 // perform refactoring 121 // perform refactoring
125 _createRefactoring('/packages/my_pkg/bbb/ccc/new_name.dart'); 122 _createRefactoring('/packages/my_pkg/bbb/ccc/new_name.dart');
126 return _assertSuccessfulRefactoring().then((_) { 123 await _assertSuccessfulRefactoring();
127 assertFileChangeResult(pathA, ''' 124 assertFileChangeResult(pathA, '''
128 import 'package:my_pkg/bbb/ccc/new_name.dart'; 125 import 'package:my_pkg/bbb/ccc/new_name.dart';
129 '''); 126 ''');
130 assertNoFileChange(testFile); 127 assertNoFileChange(testFile);
131 });
132 } 128 }
133 129
134 test_importedLibrary_up() { 130 test_importedLibrary_up() async {
135 String pathA = '/project/000/1111/a.dart'; 131 String pathA = '/project/000/1111/a.dart';
136 testFile = '/project/000/1111/22/test.dart'; 132 testFile = '/project/000/1111/22/test.dart';
137 addSource(pathA, ''' 133 addSource(pathA, '''
138 import '22/test.dart'; 134 import '22/test.dart';
139 '''); 135 ''');
140 addTestSource(''); 136 addTestSource('');
141 _performAnalysis(); 137 _performAnalysis();
142 // perform refactoring 138 // perform refactoring
143 _createRefactoring('/project/000/1111/new_name.dart'); 139 _createRefactoring('/project/000/1111/new_name.dart');
144 return _assertSuccessfulRefactoring().then((_) { 140 await _assertSuccessfulRefactoring();
145 assertFileChangeResult(pathA, ''' 141 assertFileChangeResult(pathA, '''
146 import 'new_name.dart'; 142 import 'new_name.dart';
147 '''); 143 ''');
148 assertNoFileChange(testFile); 144 assertNoFileChange(testFile);
149 });
150 } 145 }
151 146
152 test_sourcedUnit() { 147 test_sourcedUnit() async {
153 String pathA = '/project/000/1111/a.dart'; 148 String pathA = '/project/000/1111/a.dart';
154 testFile = '/project/000/1111/22/test.dart'; 149 testFile = '/project/000/1111/22/test.dart';
155 addSource(pathA, ''' 150 addSource(pathA, '''
156 part '22/test.dart'; 151 part '22/test.dart';
157 '''); 152 ''');
158 addTestSource(''); 153 addTestSource('');
159 _performAnalysis(); 154 _performAnalysis();
160 // perform refactoring 155 // perform refactoring
161 _createRefactoring('/project/000/1111/22/new_name.dart'); 156 _createRefactoring('/project/000/1111/22/new_name.dart');
162 return _assertSuccessfulRefactoring().then((_) { 157 await _assertSuccessfulRefactoring();
163 assertFileChangeResult(pathA, ''' 158 assertFileChangeResult(pathA, '''
164 part '22/new_name.dart'; 159 part '22/new_name.dart';
165 '''); 160 ''');
166 assertNoFileChange(testFile); 161 assertNoFileChange(testFile);
167 });
168 } 162 }
169 163
170 test_sourcedUnit_multipleLibraries() { 164 test_sourcedUnit_multipleLibraries() async {
171 String pathA = '/project/000/1111/a.dart'; 165 String pathA = '/project/000/1111/a.dart';
172 String pathB = '/project/000/b.dart'; 166 String pathB = '/project/000/b.dart';
173 testFile = '/project/000/1111/22/test.dart'; 167 testFile = '/project/000/1111/22/test.dart';
174 addSource(pathA, ''' 168 addSource(pathA, '''
175 part '22/test.dart'; 169 part '22/test.dart';
176 '''); 170 ''');
177 addSource(pathB, ''' 171 addSource(pathB, '''
178 part '1111/22/test.dart'; 172 part '1111/22/test.dart';
179 '''); 173 ''');
180 addTestSource(''); 174 addTestSource('');
181 _performAnalysis(); 175 _performAnalysis();
182 // perform refactoring 176 // perform refactoring
183 _createRefactoring('/project/000/1111/22/new_name.dart'); 177 _createRefactoring('/project/000/1111/22/new_name.dart');
184 return _assertSuccessfulRefactoring().then((_) { 178 await _assertSuccessfulRefactoring();
185 assertFileChangeResult(pathA, ''' 179 assertFileChangeResult(pathA, '''
186 part '22/new_name.dart'; 180 part '22/new_name.dart';
187 '''); 181 ''');
188 assertFileChangeResult(pathB, ''' 182 assertFileChangeResult(pathB, '''
189 part '1111/22/new_name.dart'; 183 part '1111/22/new_name.dart';
190 '''); 184 ''');
191 assertNoFileChange(testFile); 185 assertNoFileChange(testFile);
192 });
193 } 186 }
194 187
195 /** 188 /**
196 * Checks that all conditions are OK. 189 * Checks that all conditions are OK.
197 */ 190 */
198 Future _assertSuccessfulRefactoring() { 191 Future _assertSuccessfulRefactoring() async {
199 return assertRefactoringConditionsOK().then((_) { 192 await assertRefactoringConditionsOK();
200 return refactoring.createChange().then((SourceChange refactoringChange) { 193 refactoringChange = await refactoring.createChange();
201 this.refactoringChange = refactoringChange;
202 });
203 });
204 } 194 }
205 195
206 void _createRefactoring(String newName) { 196 void _createRefactoring(String newName) {
207 refactoring = new MoveFileRefactoring( 197 refactoring = new MoveFileRefactoring(
208 provider.pathContext, 198 provider.pathContext,
209 searchEngine, 199 searchEngine,
210 context, 200 context,
211 testSource); 201 testSource);
212 refactoring.newFile = newName; 202 refactoring.newFile = newName;
213 } 203 }
214 204
215 void _performAnalysis() { 205 void _performAnalysis() {
216 while (true) { 206 while (true) {
217 AnalysisResult result = context.performAnalysisTask(); 207 AnalysisResult result = context.performAnalysisTask();
218 if (!result.hasMoreWork) { 208 if (!result.hasMoreWork) {
219 break; 209 break;
220 } 210 }
221 for (ChangeNotice notice in result.changeNotices) { 211 for (ChangeNotice notice in result.changeNotices) {
222 if (notice.source.fullName.startsWith('/project/')) { 212 if (notice.source.fullName.startsWith('/project/')) {
223 index.indexUnit(context, notice.resolvedDartUnit); 213 index.indexUnit(context, notice.resolvedDartUnit);
224 } 214 }
225 } 215 }
226 } 216 }
227 } 217 }
228 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698