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

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

Issue 2614033003: Make subclasses of AbstractContextTest asynchronous. (Closed)
Patch Set: Created 3 years, 11 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
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.inline_method; 5 library test.services.refactoring.inline_method;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; 9 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element;
10 import 'package:analysis_server/src/services/correction/status.dart'; 10 import 'package:analysis_server/src/services/correction/status.dart';
(...skipping 11 matching lines...) Expand all
22 }); 22 });
23 } 23 }
24 24
25 @reflectiveTest 25 @reflectiveTest
26 class InlineMethodTest extends RefactoringTest { 26 class InlineMethodTest extends RefactoringTest {
27 InlineMethodRefactoringImpl refactoring; 27 InlineMethodRefactoringImpl refactoring;
28 bool deleteSource; 28 bool deleteSource;
29 bool inlineAll; 29 bool inlineAll;
30 30
31 test_access_FunctionElement() async { 31 test_access_FunctionElement() async {
32 indexTestUnit(r''' 32 await indexTestUnit(r'''
33 test(a, b) { 33 test(a, b) {
34 return a + b; 34 return a + b;
35 } 35 }
36 main() { 36 main() {
37 var res = test(1, 2); 37 var res = test(1, 2);
38 } 38 }
39 '''); 39 ''');
40 _createRefactoring('test(1, 2)'); 40 _createRefactoring('test(1, 2)');
41 // validate state 41 // validate state
42 await refactoring.checkInitialConditions(); 42 await refactoring.checkInitialConditions();
43 expect(refactoring.refactoringName, 'Inline Function'); 43 expect(refactoring.refactoringName, 'Inline Function');
44 expect(refactoring.className, isNull); 44 expect(refactoring.className, isNull);
45 expect(refactoring.methodName, 'test'); 45 expect(refactoring.methodName, 'test');
46 expect(refactoring.isDeclaration, isFalse); 46 expect(refactoring.isDeclaration, isFalse);
47 } 47 }
48 48
49 test_access_MethodElement() async { 49 test_access_MethodElement() async {
50 indexTestUnit(r''' 50 await indexTestUnit(r'''
51 class A { 51 class A {
52 test(a, b) { 52 test(a, b) {
53 return a + b; 53 return a + b;
54 } 54 }
55 main() { 55 main() {
56 var res = test(1, 2); 56 var res = test(1, 2);
57 } 57 }
58 } 58 }
59 '''); 59 ''');
60 _createRefactoring('test(a, b)'); 60 _createRefactoring('test(a, b)');
61 // validate state 61 // validate state
62 await refactoring.checkInitialConditions(); 62 await refactoring.checkInitialConditions();
63 expect(refactoring.refactoringName, 'Inline Method'); 63 expect(refactoring.refactoringName, 'Inline Method');
64 expect(refactoring.className, 'A'); 64 expect(refactoring.className, 'A');
65 expect(refactoring.methodName, 'test'); 65 expect(refactoring.methodName, 'test');
66 expect(refactoring.isDeclaration, isTrue); 66 expect(refactoring.isDeclaration, isTrue);
67 } 67 }
68 68
69 test_bad_async_intoSyncStar() { 69 test_bad_async_intoSyncStar() async {
70 indexTestUnit(r''' 70 await indexTestUnit(r'''
71 import 'dart:async'; 71 import 'dart:async';
72 class A { 72 class A {
73 Future<int> get test async => 42; 73 Future<int> get test async => 42;
74 Iterable<Future<int>> foo() sync* { 74 Iterable<Future<int>> foo() sync* {
75 yield test; 75 yield test;
76 } 76 }
77 } 77 }
78 '''); 78 ''');
79 _createRefactoring('test async'); 79 _createRefactoring('test async');
80 // error 80 // error
81 return _assertConditionsFatal('Cannot inline async into sync*.'); 81 return _assertConditionsFatal('Cannot inline async into sync*.');
82 } 82 }
83 83
84 test_bad_async_targetIsSync_doesNotReturnFuture() { 84 test_bad_async_targetIsSync_doesNotReturnFuture() async {
85 indexTestUnit(r''' 85 await indexTestUnit(r'''
86 import 'dart:async'; 86 import 'dart:async';
87 class A { 87 class A {
88 Future<int> get test async => 42; 88 Future<int> get test async => 42;
89 double foo() { 89 double foo() {
90 test; 90 test;
91 return 1.2; 91 return 1.2;
92 } 92 }
93 } 93 }
94 '''); 94 ''');
95 _createRefactoring('test async'); 95 _createRefactoring('test async');
96 // error 96 // error
97 return _assertConditionsFatal( 97 return _assertConditionsFatal(
98 'Cannot inline async into a function that does not return a Future.'); 98 'Cannot inline async into a function that does not return a Future.');
99 } 99 }
100 100
101 test_bad_asyncStar() { 101 test_bad_asyncStar() async {
102 indexTestUnit(r''' 102 await indexTestUnit(r'''
103 import 'dart:async'; 103 import 'dart:async';
104 class A { 104 class A {
105 Stream<int> test() async* { 105 Stream<int> test() async* {
106 yield 1; 106 yield 1;
107 yield 2; 107 yield 2;
108 } 108 }
109 foo() { 109 foo() {
110 test(); 110 test();
111 } 111 }
112 } 112 }
113 '''); 113 ''');
114 _createRefactoring('test() async*'); 114 _createRefactoring('test() async*');
115 // error 115 // error
116 return _assertConditionsFatal('Cannot inline a generator.'); 116 return _assertConditionsFatal('Cannot inline a generator.');
117 } 117 }
118 118
119 test_bad_cascadeInvocation() async { 119 test_bad_cascadeInvocation() async {
120 indexTestUnit(r''' 120 await indexTestUnit(r'''
121 class A { 121 class A {
122 foo() {} 122 foo() {}
123 bar() {} 123 bar() {}
124 test() {} 124 test() {}
125 } 125 }
126 main() { 126 main() {
127 A a = new A(); 127 A a = new A();
128 a..foo()..test()..bar(); 128 a..foo()..test()..bar();
129 } 129 }
130 '''); 130 ''');
131 _createRefactoring('test() {'); 131 _createRefactoring('test() {');
132 // error 132 // error
133 RefactoringStatus status = await refactoring.checkAllConditions(); 133 RefactoringStatus status = await refactoring.checkAllConditions();
134 var location = new SourceRange(findOffset('..test()'), '..test()'.length); 134 var location = new SourceRange(findOffset('..test()'), '..test()'.length);
135 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, 135 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
136 expectedMessage: 'Cannot inline cascade invocation.', 136 expectedMessage: 'Cannot inline cascade invocation.',
137 expectedContextRange: location); 137 expectedContextRange: location);
138 } 138 }
139 139
140 test_bad_constructor() { 140 test_bad_constructor() async {
141 indexTestUnit(r''' 141 await indexTestUnit(r'''
142 class A { 142 class A {
143 A.named() {} 143 A.named() {}
144 } 144 }
145 '''); 145 ''');
146 _createRefactoring('named() {}'); 146 _createRefactoring('named() {}');
147 // error 147 // error
148 return _assertInvalidSelection(); 148 return _assertInvalidSelection();
149 } 149 }
150 150
151 test_bad_deleteSource_inlineOne() async { 151 test_bad_deleteSource_inlineOne() async {
152 indexTestUnit(r''' 152 await indexTestUnit(r'''
153 test(a, b) { 153 test(a, b) {
154 return a + b; 154 return a + b;
155 } 155 }
156 main() { 156 main() {
157 var res1 = test(1, 2); 157 var res1 = test(1, 2);
158 var res2 = test(10, 20); 158 var res2 = test(10, 20);
159 } 159 }
160 '''); 160 ''');
161 _createRefactoring('test(1, 2)'); 161 _createRefactoring('test(1, 2)');
162 // initial conditions 162 // initial conditions
163 RefactoringStatus status = await refactoring.checkInitialConditions(); 163 RefactoringStatus status = await refactoring.checkInitialConditions();
164 assertRefactoringStatusOK(status); 164 assertRefactoringStatusOK(status);
165 refactoring.deleteSource = true; 165 refactoring.deleteSource = true;
166 refactoring.inlineAll = false; 166 refactoring.inlineAll = false;
167 // final conditions 167 // final conditions
168 status = await refactoring.checkFinalConditions(); 168 status = await refactoring.checkFinalConditions();
169 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, 169 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
170 expectedMessage: 170 expectedMessage:
171 'All references must be inlined to remove the source.'); 171 'All references must be inlined to remove the source.');
172 } 172 }
173 173
174 test_bad_notExecutableElement() { 174 test_bad_notExecutableElement() async {
175 indexTestUnit(r''' 175 await indexTestUnit(r'''
176 main() { 176 main() {
177 } 177 }
178 '''); 178 ''');
179 _createRefactoring(') {'); 179 _createRefactoring(') {');
180 // error 180 // error
181 return _assertInvalidSelection(); 181 return _assertInvalidSelection();
182 } 182 }
183 183
184 test_bad_notSimpleIdentifier() { 184 test_bad_notSimpleIdentifier() async {
185 indexTestUnit(r''' 185 await indexTestUnit(r'''
186 main() { 186 main() {
187 var test = 42; 187 var test = 42;
188 var res = test; 188 var res = test;
189 } 189 }
190 '''); 190 ''');
191 _createRefactoring('test;'); 191 _createRefactoring('test;');
192 // error 192 // error
193 return _assertInvalidSelection(); 193 return _assertInvalidSelection();
194 } 194 }
195 195
196 test_bad_operator() { 196 test_bad_operator() async {
197 indexTestUnit(r''' 197 await indexTestUnit(r'''
198 class A { 198 class A {
199 operator -(other) => this; 199 operator -(other) => this;
200 } 200 }
201 '''); 201 ''');
202 _createRefactoring('-(other)'); 202 _createRefactoring('-(other)');
203 // error 203 // error
204 return _assertConditionsFatal('Cannot inline operator.'); 204 return _assertConditionsFatal('Cannot inline operator.');
205 } 205 }
206 206
207 test_bad_propertyAccessor_synthetic() { 207 test_bad_propertyAccessor_synthetic() async {
208 indexTestUnit(r''' 208 await indexTestUnit(r'''
209 class A { 209 class A {
210 int fff; 210 int fff;
211 } 211 }
212 212
213 main(A a) { 213 main(A a) {
214 print(a.fff); 214 print(a.fff);
215 } 215 }
216 '''); 216 ''');
217 _createRefactoring('fff);'); 217 _createRefactoring('fff);');
218 // error 218 // error
219 return _assertInvalidSelection(); 219 return _assertInvalidSelection();
220 } 220 }
221 221
222 test_bad_reference_toClassMethod() { 222 test_bad_reference_toClassMethod() async {
223 indexTestUnit(r''' 223 await indexTestUnit(r'''
224 class A { 224 class A {
225 test(a, b) { 225 test(a, b) {
226 print(a); 226 print(a);
227 print(b); 227 print(b);
228 } 228 }
229 } 229 }
230 main() { 230 main() {
231 print(new A().test); 231 print(new A().test);
232 } 232 }
233 '''); 233 ''');
234 _createRefactoring('test(a, b)'); 234 _createRefactoring('test(a, b)');
235 // error 235 // error
236 return _assertConditionsFatal('Cannot inline class method reference.'); 236 return _assertConditionsFatal('Cannot inline class method reference.');
237 } 237 }
238 238
239 test_bad_severalReturns() { 239 test_bad_severalReturns() async {
240 indexTestUnit(r''' 240 await indexTestUnit(r'''
241 test() { 241 test() {
242 if (true) { 242 if (true) {
243 return 1; 243 return 1;
244 } 244 }
245 return 2; 245 return 2;
246 } 246 }
247 main() { 247 main() {
248 var res = test(); 248 var res = test();
249 } 249 }
250 '''); 250 ''');
251 _createRefactoring('test() {'); 251 _createRefactoring('test() {');
252 // error 252 // error
253 return _assertConditionsError('Ambiguous return value.'); 253 return _assertConditionsError('Ambiguous return value.');
254 } 254 }
255 255
256 test_fieldAccessor_getter() { 256 test_fieldAccessor_getter() async {
257 indexTestUnit(r''' 257 await indexTestUnit(r'''
258 class A { 258 class A {
259 var f; 259 var f;
260 get foo { 260 get foo {
261 return f * 2; 261 return f * 2;
262 } 262 }
263 } 263 }
264 main() { 264 main() {
265 A a = new A(); 265 A a = new A();
266 print(a.foo); 266 print(a.foo);
267 } 267 }
268 '''); 268 ''');
269 _createRefactoring('foo {'); 269 _createRefactoring('foo {');
270 // validate change 270 // validate change
271 return _assertSuccessfulRefactoring(r''' 271 return _assertSuccessfulRefactoring(r'''
272 class A { 272 class A {
273 var f; 273 var f;
274 } 274 }
275 main() { 275 main() {
276 A a = new A(); 276 A a = new A();
277 print(a.f * 2); 277 print(a.f * 2);
278 } 278 }
279 '''); 279 ''');
280 } 280 }
281 281
282 test_fieldAccessor_getter_PropertyAccess() { 282 test_fieldAccessor_getter_PropertyAccess() async {
283 indexTestUnit(r''' 283 await indexTestUnit(r'''
284 class A { 284 class A {
285 var f; 285 var f;
286 get foo { 286 get foo {
287 return f * 2; 287 return f * 2;
288 } 288 }
289 } 289 }
290 class B { 290 class B {
291 A a = new A(); 291 A a = new A();
292 } 292 }
293 main() { 293 main() {
(...skipping 10 matching lines...) Expand all
304 class B { 304 class B {
305 A a = new A(); 305 A a = new A();
306 } 306 }
307 main() { 307 main() {
308 B b = new B(); 308 B b = new B();
309 print(b.a.f * 2); 309 print(b.a.f * 2);
310 } 310 }
311 '''); 311 ''');
312 } 312 }
313 313
314 test_fieldAccessor_setter() { 314 test_fieldAccessor_setter() async {
315 indexTestUnit(r''' 315 await indexTestUnit(r'''
316 class A { 316 class A {
317 var f; 317 var f;
318 set foo(x) { 318 set foo(x) {
319 f = x; 319 f = x;
320 } 320 }
321 } 321 }
322 main() { 322 main() {
323 A a = new A(); 323 A a = new A();
324 a.foo = 0; 324 a.foo = 0;
325 } 325 }
326 '''); 326 ''');
327 _createRefactoring('foo(x) {'); 327 _createRefactoring('foo(x) {');
328 // validate change 328 // validate change
329 return _assertSuccessfulRefactoring(r''' 329 return _assertSuccessfulRefactoring(r'''
330 class A { 330 class A {
331 var f; 331 var f;
332 } 332 }
333 main() { 333 main() {
334 A a = new A(); 334 A a = new A();
335 a.f = 0; 335 a.f = 0;
336 } 336 }
337 '''); 337 ''');
338 } 338 }
339 339
340 test_fieldAccessor_setter_PropertyAccess() { 340 test_fieldAccessor_setter_PropertyAccess() async {
341 indexTestUnit(r''' 341 await indexTestUnit(r'''
342 class A { 342 class A {
343 var f; 343 var f;
344 set foo(x) { 344 set foo(x) {
345 f = x; 345 f = x;
346 } 346 }
347 } 347 }
348 class B { 348 class B {
349 A a = new A(); 349 A a = new A();
350 } 350 }
351 main() { 351 main() {
(...skipping 10 matching lines...) Expand all
362 class B { 362 class B {
363 A a = new A(); 363 A a = new A();
364 } 364 }
365 main() { 365 main() {
366 B b = new B(); 366 B b = new B();
367 b.a.f = 0; 367 b.a.f = 0;
368 } 368 }
369 '''); 369 ''');
370 } 370 }
371 371
372 test_function_expressionFunctionBody() { 372 test_function_expressionFunctionBody() async {
373 indexTestUnit(r''' 373 await indexTestUnit(r'''
374 test(a, b) => a + b; 374 test(a, b) => a + b;
375 main() { 375 main() {
376 print(test(1, 2)); 376 print(test(1, 2));
377 } 377 }
378 '''); 378 ''');
379 _createRefactoring('test(a, b)'); 379 _createRefactoring('test(a, b)');
380 // validate change 380 // validate change
381 return _assertSuccessfulRefactoring(r''' 381 return _assertSuccessfulRefactoring(r'''
382 main() { 382 main() {
383 print(1 + 2); 383 print(1 + 2);
384 } 384 }
385 '''); 385 ''');
386 } 386 }
387 387
388 test_function_hasReturn_assign() { 388 test_function_hasReturn_assign() async {
389 indexTestUnit(r''' 389 await indexTestUnit(r'''
390 test(a, b) { 390 test(a, b) {
391 print(a); 391 print(a);
392 print(b); 392 print(b);
393 return a + b; 393 return a + b;
394 } 394 }
395 main() { 395 main() {
396 var v; 396 var v;
397 v = test(1, 2); 397 v = test(1, 2);
398 } 398 }
399 '''); 399 ''');
400 _createRefactoring('test(a, b)'); 400 _createRefactoring('test(a, b)');
401 // validate change 401 // validate change
402 return _assertSuccessfulRefactoring(r''' 402 return _assertSuccessfulRefactoring(r'''
403 main() { 403 main() {
404 var v; 404 var v;
405 print(1); 405 print(1);
406 print(2); 406 print(2);
407 v = 1 + 2; 407 v = 1 + 2;
408 } 408 }
409 '''); 409 ''');
410 } 410 }
411 411
412 test_function_hasReturn_hasReturnType() { 412 test_function_hasReturn_hasReturnType() async {
413 indexTestUnit(r''' 413 await indexTestUnit(r'''
414 int test(a, b) { 414 int test(a, b) {
415 return a + b; 415 return a + b;
416 } 416 }
417 main() { 417 main() {
418 var v = test(1, 2); 418 var v = test(1, 2);
419 } 419 }
420 '''); 420 ''');
421 _createRefactoring('test(a, b)'); 421 _createRefactoring('test(a, b)');
422 // validate change 422 // validate change
423 return _assertSuccessfulRefactoring(r''' 423 return _assertSuccessfulRefactoring(r'''
424 main() { 424 main() {
425 var v = 1 + 2; 425 var v = 1 + 2;
426 } 426 }
427 '''); 427 ''');
428 } 428 }
429 429
430 test_function_hasReturn_noVars_oneUsage() { 430 test_function_hasReturn_noVars_oneUsage() async {
431 indexTestUnit(r''' 431 await indexTestUnit(r'''
432 test(a, b) { 432 test(a, b) {
433 print(a); 433 print(a);
434 print(b); 434 print(b);
435 return a + b; 435 return a + b;
436 } 436 }
437 main() { 437 main() {
438 var v = test(1, 2); 438 var v = test(1, 2);
439 } 439 }
440 '''); 440 ''');
441 _createRefactoring('test(a, b)'); 441 _createRefactoring('test(a, b)');
442 // validate change 442 // validate change
443 return _assertSuccessfulRefactoring(r''' 443 return _assertSuccessfulRefactoring(r'''
444 main() { 444 main() {
445 print(1); 445 print(1);
446 print(2); 446 print(2);
447 var v = 1 + 2; 447 var v = 1 + 2;
448 } 448 }
449 '''); 449 ''');
450 } 450 }
451 451
452 test_function_multilineString() { 452 test_function_multilineString() async {
453 indexTestUnit(r""" 453 await indexTestUnit(r"""
454 main() { 454 main() {
455 { 455 {
456 test(); 456 test();
457 } 457 }
458 } 458 }
459 test() { 459 test() {
460 print(''' 460 print('''
461 first line 461 first line
462 second line 462 second line
463 '''); 463 ''');
464 } 464 }
465 """); 465 """);
466 _createRefactoring('test() {'); 466 _createRefactoring('test() {');
467 // validate change 467 // validate change
468 return _assertSuccessfulRefactoring(r""" 468 return _assertSuccessfulRefactoring(r"""
469 main() { 469 main() {
470 { 470 {
471 print(''' 471 print('''
472 first line 472 first line
473 second line 473 second line
474 '''); 474 ''');
475 } 475 }
476 } 476 }
477 """); 477 """);
478 } 478 }
479 479
480 test_function_noReturn_hasVars_hasConflict_fieldSuperClass() { 480 test_function_noReturn_hasVars_hasConflict_fieldSuperClass() async {
481 indexTestUnit(r''' 481 await indexTestUnit(r'''
482 class A { 482 class A {
483 var c; 483 var c;
484 } 484 }
485 class B extends A { 485 class B extends A {
486 foo() { 486 foo() {
487 test(1, 2); 487 test(1, 2);
488 } 488 }
489 } 489 }
490 test(a, b) { 490 test(a, b) {
491 var c = a + b; 491 var c = a + b;
492 print(c); 492 print(c);
493 } 493 }
494 '''); 494 ''');
495 _createRefactoring('test(a, b)'); 495 _createRefactoring('test(a, b)');
496 // validate change 496 // validate change
497 return _assertSuccessfulRefactoring(r''' 497 return _assertSuccessfulRefactoring(r'''
498 class A { 498 class A {
499 var c; 499 var c;
500 } 500 }
501 class B extends A { 501 class B extends A {
502 foo() { 502 foo() {
503 var c2 = 1 + 2; 503 var c2 = 1 + 2;
504 print(c2); 504 print(c2);
505 } 505 }
506 } 506 }
507 '''); 507 ''');
508 } 508 }
509 509
510 test_function_noReturn_hasVars_hasConflict_fieldThisClass() { 510 test_function_noReturn_hasVars_hasConflict_fieldThisClass() async {
511 indexTestUnit(r''' 511 await indexTestUnit(r'''
512 class A { 512 class A {
513 var c; 513 var c;
514 foo() { 514 foo() {
515 test(1, 2); 515 test(1, 2);
516 } 516 }
517 } 517 }
518 test(a, b) { 518 test(a, b) {
519 var c = a + b; 519 var c = a + b;
520 print(c); 520 print(c);
521 } 521 }
522 '''); 522 ''');
523 _createRefactoring('test(a, b)'); 523 _createRefactoring('test(a, b)');
524 // validate change 524 // validate change
525 return _assertSuccessfulRefactoring(r''' 525 return _assertSuccessfulRefactoring(r'''
526 class A { 526 class A {
527 var c; 527 var c;
528 foo() { 528 foo() {
529 var c2 = 1 + 2; 529 var c2 = 1 + 2;
530 print(c2); 530 print(c2);
531 } 531 }
532 } 532 }
533 '''); 533 ''');
534 } 534 }
535 535
536 test_function_noReturn_hasVars_hasConflict_localAfter() { 536 test_function_noReturn_hasVars_hasConflict_localAfter() async {
537 indexTestUnit(r''' 537 await indexTestUnit(r'''
538 test(a, b) { 538 test(a, b) {
539 var c = a + b; 539 var c = a + b;
540 print(c); 540 print(c);
541 } 541 }
542 main() { 542 main() {
543 test(1, 2); 543 test(1, 2);
544 var c = 0; 544 var c = 0;
545 } 545 }
546 '''); 546 ''');
547 _createRefactoring('test(a, b)'); 547 _createRefactoring('test(a, b)');
548 // validate change 548 // validate change
549 return _assertSuccessfulRefactoring(r''' 549 return _assertSuccessfulRefactoring(r'''
550 main() { 550 main() {
551 var c2 = 1 + 2; 551 var c2 = 1 + 2;
552 print(c2); 552 print(c2);
553 var c = 0; 553 var c = 0;
554 } 554 }
555 '''); 555 ''');
556 } 556 }
557 557
558 test_function_noReturn_hasVars_hasConflict_localBefore() { 558 test_function_noReturn_hasVars_hasConflict_localBefore() async {
559 indexTestUnit(r''' 559 await indexTestUnit(r'''
560 test(a, b) { 560 test(a, b) {
561 var c = a + b; 561 var c = a + b;
562 print(c); 562 print(c);
563 } 563 }
564 main() { 564 main() {
565 var c = 0; 565 var c = 0;
566 test(1, 2); 566 test(1, 2);
567 } 567 }
568 '''); 568 ''');
569 _createRefactoring('test(a, b)'); 569 _createRefactoring('test(a, b)');
570 // validate change 570 // validate change
571 return _assertSuccessfulRefactoring(r''' 571 return _assertSuccessfulRefactoring(r'''
572 main() { 572 main() {
573 var c = 0; 573 var c = 0;
574 var c2 = 1 + 2; 574 var c2 = 1 + 2;
575 print(c2); 575 print(c2);
576 } 576 }
577 '''); 577 ''');
578 } 578 }
579 579
580 test_function_noReturn_hasVars_noConflict() { 580 test_function_noReturn_hasVars_noConflict() async {
581 indexTestUnit(r''' 581 await indexTestUnit(r'''
582 test(a, b) { 582 test(a, b) {
583 var c = a + b; 583 var c = a + b;
584 print(c); 584 print(c);
585 } 585 }
586 main() { 586 main() {
587 test(1, 2); 587 test(1, 2);
588 } 588 }
589 '''); 589 ''');
590 _createRefactoring('test(a, b)'); 590 _createRefactoring('test(a, b)');
591 // validate change 591 // validate change
592 return _assertSuccessfulRefactoring(r''' 592 return _assertSuccessfulRefactoring(r'''
593 main() { 593 main() {
594 var c = 1 + 2; 594 var c = 1 + 2;
595 print(c); 595 print(c);
596 } 596 }
597 '''); 597 ''');
598 } 598 }
599 599
600 test_function_noReturn_noVars_oneUsage() { 600 test_function_noReturn_noVars_oneUsage() async {
601 indexTestUnit(r''' 601 await indexTestUnit(r'''
602 test(a, b) { 602 test(a, b) {
603 print(a); 603 print(a);
604 print(b); 604 print(b);
605 } 605 }
606 main() { 606 main() {
607 test(1, 2); 607 test(1, 2);
608 } 608 }
609 '''); 609 ''');
610 _createRefactoring('test(a, b)'); 610 _createRefactoring('test(a, b)');
611 // validate change 611 // validate change
612 return _assertSuccessfulRefactoring(r''' 612 return _assertSuccessfulRefactoring(r'''
613 main() { 613 main() {
614 print(1); 614 print(1);
615 print(2); 615 print(2);
616 } 616 }
617 '''); 617 ''');
618 } 618 }
619 619
620 test_function_noReturn_noVars_useIndentation() { 620 test_function_noReturn_noVars_useIndentation() async {
621 indexTestUnit(r''' 621 await indexTestUnit(r'''
622 test(a, b) { 622 test(a, b) {
623 print(a); 623 print(a);
624 print(b); 624 print(b);
625 } 625 }
626 main() { 626 main() {
627 { 627 {
628 test(1, 2); 628 test(1, 2);
629 } 629 }
630 } 630 }
631 '''); 631 ''');
632 _createRefactoring('test(a, b)'); 632 _createRefactoring('test(a, b)');
633 // validate change 633 // validate change
634 return _assertSuccessfulRefactoring(r''' 634 return _assertSuccessfulRefactoring(r'''
635 main() { 635 main() {
636 { 636 {
637 print(1); 637 print(1);
638 print(2); 638 print(2);
639 } 639 }
640 } 640 }
641 '''); 641 ''');
642 } 642 }
643 643
644 test_function_noReturn_voidReturnType() { 644 test_function_noReturn_voidReturnType() async {
645 indexTestUnit(r''' 645 await indexTestUnit(r'''
646 void test(a, b) { 646 void test(a, b) {
647 print(a + b); 647 print(a + b);
648 } 648 }
649 main() { 649 main() {
650 test(1, 2); 650 test(1, 2);
651 } 651 }
652 '''); 652 ''');
653 _createRefactoring('test(a, b)'); 653 _createRefactoring('test(a, b)');
654 // validate change 654 // validate change
655 return _assertSuccessfulRefactoring(r''' 655 return _assertSuccessfulRefactoring(r'''
656 main() { 656 main() {
657 print(1 + 2); 657 print(1 + 2);
658 } 658 }
659 '''); 659 ''');
660 } 660 }
661 661
662 test_function_notStatement_oneStatement_assign() { 662 test_function_notStatement_oneStatement_assign() async {
663 indexTestUnit(r''' 663 await indexTestUnit(r'''
664 test(int p) { 664 test(int p) {
665 print(p * 2); 665 print(p * 2);
666 } 666 }
667 main() { 667 main() {
668 var v; 668 var v;
669 v = test(0); 669 v = test(0);
670 } 670 }
671 '''); 671 ''');
672 _createRefactoring('test(int p)'); 672 _createRefactoring('test(int p)');
673 // validate change 673 // validate change
674 return _assertSuccessfulRefactoring(r''' 674 return _assertSuccessfulRefactoring(r'''
675 main() { 675 main() {
676 var v; 676 var v;
677 v = (int p) { 677 v = (int p) {
678 print(p * 2); 678 print(p * 2);
679 }(0); 679 }(0);
680 } 680 }
681 '''); 681 ''');
682 } 682 }
683 683
684 test_function_notStatement_oneStatement_variableDeclaration() { 684 test_function_notStatement_oneStatement_variableDeclaration() async {
685 indexTestUnit(r''' 685 await indexTestUnit(r'''
686 test(int p) { 686 test(int p) {
687 print(p * 2); 687 print(p * 2);
688 } 688 }
689 main() { 689 main() {
690 var v = test(0); 690 var v = test(0);
691 } 691 }
692 '''); 692 ''');
693 _createRefactoring('test(int p)'); 693 _createRefactoring('test(int p)');
694 // validate change 694 // validate change
695 return _assertSuccessfulRefactoring(r''' 695 return _assertSuccessfulRefactoring(r'''
696 main() { 696 main() {
697 var v = (int p) { 697 var v = (int p) {
698 print(p * 2); 698 print(p * 2);
699 }(0); 699 }(0);
700 } 700 }
701 '''); 701 ''');
702 } 702 }
703 703
704 test_function_notStatement_severalStatements() { 704 test_function_notStatement_severalStatements() async {
705 indexTestUnit(r''' 705 await indexTestUnit(r'''
706 test(int p) { 706 test(int p) {
707 print(p); 707 print(p);
708 print(p * 2); 708 print(p * 2);
709 } 709 }
710 main() { 710 main() {
711 var v = test(0); 711 var v = test(0);
712 } 712 }
713 '''); 713 ''');
714 _createRefactoring('test(int p)'); 714 _createRefactoring('test(int p)');
715 // validate change 715 // validate change
716 return _assertSuccessfulRefactoring(r''' 716 return _assertSuccessfulRefactoring(r'''
717 main() { 717 main() {
718 var v = (int p) { 718 var v = (int p) {
719 print(p); 719 print(p);
720 print(p * 2); 720 print(p * 2);
721 }(0); 721 }(0);
722 } 722 }
723 '''); 723 ''');
724 } 724 }
725 725
726 test_function_notStatement_zeroStatements() { 726 test_function_notStatement_zeroStatements() async {
727 indexTestUnit(r''' 727 await indexTestUnit(r'''
728 test(int p) { 728 test(int p) {
729 } 729 }
730 main() { 730 main() {
731 var v = test(0); 731 var v = test(0);
732 } 732 }
733 '''); 733 ''');
734 _createRefactoring('test(int p)'); 734 _createRefactoring('test(int p)');
735 // validate change 735 // validate change
736 return _assertSuccessfulRefactoring(r''' 736 return _assertSuccessfulRefactoring(r'''
737 main() { 737 main() {
738 var v = (int p) { 738 var v = (int p) {
739 }(0); 739 }(0);
740 } 740 }
741 '''); 741 ''');
742 } 742 }
743 743
744 test_function_singleStatement() { 744 test_function_singleStatement() async {
745 indexTestUnit(r''' 745 await indexTestUnit(r'''
746 var topLevelField = 0; 746 var topLevelField = 0;
747 test() { 747 test() {
748 print(topLevelField); 748 print(topLevelField);
749 } 749 }
750 main() { 750 main() {
751 test(); 751 test();
752 } 752 }
753 '''); 753 ''');
754 _createRefactoring('test() {'); 754 _createRefactoring('test() {');
755 // validate change 755 // validate change
756 return _assertSuccessfulRefactoring(r''' 756 return _assertSuccessfulRefactoring(r'''
757 var topLevelField = 0; 757 var topLevelField = 0;
758 main() { 758 main() {
759 print(topLevelField); 759 print(topLevelField);
760 } 760 }
761 '''); 761 ''');
762 } 762 }
763 763
764 test_getter_async_targetIsAsync() { 764 test_getter_async_targetIsAsync() async {
765 indexTestUnit(r''' 765 await indexTestUnit(r'''
766 import 'dart:async'; 766 import 'dart:async';
767 class A { 767 class A {
768 Future<int> get test async => 42; 768 Future<int> get test async => 42;
769 Future<int> foo() async { 769 Future<int> foo() async {
770 return test; 770 return test;
771 } 771 }
772 } 772 }
773 '''); 773 ''');
774 _createRefactoring('test async'); 774 _createRefactoring('test async');
775 // validate change 775 // validate change
776 return _assertSuccessfulRefactoring(r''' 776 return _assertSuccessfulRefactoring(r'''
777 import 'dart:async'; 777 import 'dart:async';
778 class A { 778 class A {
779 Future<int> foo() async { 779 Future<int> foo() async {
780 return 42; 780 return 42;
781 } 781 }
782 } 782 }
783 '''); 783 ''');
784 } 784 }
785 785
786 test_getter_async_targetIsAsyncStar() { 786 test_getter_async_targetIsAsyncStar() async {
787 indexTestUnit(r''' 787 await indexTestUnit(r'''
788 import 'dart:async'; 788 import 'dart:async';
789 class A { 789 class A {
790 Future<int> get test async => 42; 790 Future<int> get test async => 42;
791 Stream<int> foo() async { 791 Stream<int> foo() async {
792 return await test; 792 return await test;
793 } 793 }
794 } 794 }
795 '''); 795 ''');
796 _createRefactoring('test async'); 796 _createRefactoring('test async');
797 // validate change 797 // validate change
798 return _assertSuccessfulRefactoring(r''' 798 return _assertSuccessfulRefactoring(r'''
799 import 'dart:async'; 799 import 'dart:async';
800 class A { 800 class A {
801 Stream<int> foo() async { 801 Stream<int> foo() async {
802 return await 42; 802 return await 42;
803 } 803 }
804 } 804 }
805 '''); 805 ''');
806 } 806 }
807 807
808 test_getter_async_targetIsSync() { 808 test_getter_async_targetIsSync() async {
809 indexTestUnit(r''' 809 await indexTestUnit(r'''
810 import 'dart:async'; 810 import 'dart:async';
811 class A { 811 class A {
812 Future<int> get test async => 42; 812 Future<int> get test async => 42;
813 Future<int> foo() { 813 Future<int> foo() {
814 return test; 814 return test;
815 } 815 }
816 } 816 }
817 '''); 817 ''');
818 _createRefactoring('test async'); 818 _createRefactoring('test async');
819 // validate change 819 // validate change
820 return _assertSuccessfulRefactoring(r''' 820 return _assertSuccessfulRefactoring(r'''
821 import 'dart:async'; 821 import 'dart:async';
822 class A { 822 class A {
823 Future<int> foo() async { 823 Future<int> foo() async {
824 return 42; 824 return 42;
825 } 825 }
826 } 826 }
827 '''); 827 ''');
828 } 828 }
829 829
830 test_getter_async_targetIsSync2() { 830 test_getter_async_targetIsSync2() async {
831 indexTestUnit(r''' 831 await indexTestUnit(r'''
832 import 'dart:async'; 832 import 'dart:async';
833 class A { 833 class A {
834 Future<int> get test async => 42; 834 Future<int> get test async => 42;
835 Future<int> foo1() { 835 Future<int> foo1() {
836 return test; 836 return test;
837 } 837 }
838 Future<int> foo2() { 838 Future<int> foo2() {
839 return test; 839 return test;
840 } 840 }
841 } 841 }
842 '''); 842 ''');
843 _createRefactoring('test async'); 843 _createRefactoring('test async');
844 // validate change 844 // validate change
845 return _assertSuccessfulRefactoring(r''' 845 return _assertSuccessfulRefactoring(r'''
846 import 'dart:async'; 846 import 'dart:async';
847 class A { 847 class A {
848 Future<int> foo1() async { 848 Future<int> foo1() async {
849 return 42; 849 return 42;
850 } 850 }
851 Future<int> foo2() async { 851 Future<int> foo2() async {
852 return 42; 852 return 42;
853 } 853 }
854 } 854 }
855 '''); 855 ''');
856 } 856 }
857 857
858 test_getter_classMember_instance() { 858 test_getter_classMember_instance() async {
859 indexTestUnit(r''' 859 await indexTestUnit(r'''
860 class A { 860 class A {
861 int f; 861 int f;
862 int get result => f + 1; 862 int get result => f + 1;
863 } 863 }
864 main(A a) { 864 main(A a) {
865 print(a.result); 865 print(a.result);
866 } 866 }
867 '''); 867 ''');
868 _createRefactoring('result =>'); 868 _createRefactoring('result =>');
869 // validate change 869 // validate change
870 return _assertSuccessfulRefactoring(r''' 870 return _assertSuccessfulRefactoring(r'''
871 class A { 871 class A {
872 int f; 872 int f;
873 } 873 }
874 main(A a) { 874 main(A a) {
875 print(a.f + 1); 875 print(a.f + 1);
876 } 876 }
877 '''); 877 ''');
878 } 878 }
879 879
880 test_getter_classMember_static() { 880 test_getter_classMember_static() async {
881 indexTestUnit(r''' 881 await indexTestUnit(r'''
882 class A { 882 class A {
883 static int get result => 1 + 2; 883 static int get result => 1 + 2;
884 } 884 }
885 main() { 885 main() {
886 print(A.result); 886 print(A.result);
887 } 887 }
888 '''); 888 ''');
889 _createRefactoring('result =>'); 889 _createRefactoring('result =>');
890 // validate change 890 // validate change
891 return _assertSuccessfulRefactoring(r''' 891 return _assertSuccessfulRefactoring(r'''
892 class A { 892 class A {
893 } 893 }
894 main() { 894 main() {
895 print(1 + 2); 895 print(1 + 2);
896 } 896 }
897 '''); 897 ''');
898 } 898 }
899 899
900 test_getter_topLevel() { 900 test_getter_topLevel() async {
901 indexTestUnit(r''' 901 await indexTestUnit(r'''
902 String get message => 'Hello, World!'; 902 String get message => 'Hello, World!';
903 main() { 903 main() {
904 print(message); 904 print(message);
905 } 905 }
906 '''); 906 ''');
907 _createRefactoring('message =>'); 907 _createRefactoring('message =>');
908 // validate change 908 // validate change
909 return _assertSuccessfulRefactoring(r''' 909 return _assertSuccessfulRefactoring(r'''
910 main() { 910 main() {
911 print('Hello, World!'); 911 print('Hello, World!');
912 } 912 }
913 '''); 913 ''');
914 } 914 }
915 915
916 test_initialMode_all() async { 916 test_initialMode_all() async {
917 indexTestUnit(r''' 917 await indexTestUnit(r'''
918 test(a, b) { 918 test(a, b) {
919 return a + b; 919 return a + b;
920 } 920 }
921 main() { 921 main() {
922 var res = test(1, 2); 922 var res = test(1, 2);
923 } 923 }
924 '''); 924 ''');
925 _createRefactoring('test(a, b)'); 925 _createRefactoring('test(a, b)');
926 // validate state 926 // validate state
927 await refactoring.checkInitialConditions(); 927 await refactoring.checkInitialConditions();
928 expect(refactoring.deleteSource, true); 928 expect(refactoring.deleteSource, true);
929 expect(refactoring.inlineAll, true); 929 expect(refactoring.inlineAll, true);
930 } 930 }
931 931
932 test_initialMode_single() async { 932 test_initialMode_single() async {
933 indexTestUnit(r''' 933 await indexTestUnit(r'''
934 test(a, b) { 934 test(a, b) {
935 return a + b; 935 return a + b;
936 } 936 }
937 main() { 937 main() {
938 var res1 = test(1, 2); 938 var res1 = test(1, 2);
939 var res2 = test(10, 20); 939 var res2 = test(10, 20);
940 } 940 }
941 '''); 941 ''');
942 _createRefactoring('test(1, 2)'); 942 _createRefactoring('test(1, 2)');
943 deleteSource = false; 943 deleteSource = false;
944 // validate state 944 // validate state
945 await refactoring.checkInitialConditions(); 945 await refactoring.checkInitialConditions();
946 expect(refactoring.deleteSource, false); 946 expect(refactoring.deleteSource, false);
947 expect(refactoring.inlineAll, false); 947 expect(refactoring.inlineAll, false);
948 } 948 }
949 949
950 test_method_async() { 950 test_method_async() async {
951 indexTestUnit(r''' 951 await indexTestUnit(r'''
952 import 'dart:async'; 952 import 'dart:async';
953 class A { 953 class A {
954 Future<int> test() async => 42; 954 Future<int> test() async => 42;
955 Future<int> foo() { 955 Future<int> foo() {
956 return test(); 956 return test();
957 } 957 }
958 } 958 }
959 '''); 959 ''');
960 _createRefactoring('test() async'); 960 _createRefactoring('test() async');
961 // validate change 961 // validate change
962 return _assertSuccessfulRefactoring(r''' 962 return _assertSuccessfulRefactoring(r'''
963 import 'dart:async'; 963 import 'dart:async';
964 class A { 964 class A {
965 Future<int> foo() async { 965 Future<int> foo() async {
966 return 42; 966 return 42;
967 } 967 }
968 } 968 }
969 '''); 969 ''');
970 } 970 }
971 971
972 test_method_async2() { 972 test_method_async2() async {
973 indexTestUnit(r''' 973 await indexTestUnit(r'''
974 import 'dart:async'; 974 import 'dart:async';
975 class A { 975 class A {
976 Future<int> test() async => 42; 976 Future<int> test() async => 42;
977 Future foo() { 977 Future foo() {
978 return [test(), test()]; 978 return [test(), test()];
979 } 979 }
980 } 980 }
981 '''); 981 ''');
982 _createRefactoring('test() async'); 982 _createRefactoring('test() async');
983 // validate change 983 // validate change
984 return _assertSuccessfulRefactoring(r''' 984 return _assertSuccessfulRefactoring(r'''
985 import 'dart:async'; 985 import 'dart:async';
986 class A { 986 class A {
987 Future foo() async { 987 Future foo() async {
988 return [42, 42]; 988 return [42, 42];
989 } 989 }
990 } 990 }
991 '''); 991 ''');
992 } 992 }
993 993
994 test_method_emptyBody() { 994 test_method_emptyBody() async {
995 indexTestUnit(r''' 995 await indexTestUnit(r'''
996 abstract class A { 996 abstract class A {
997 test(); 997 test();
998 } 998 }
999 main(A a) { 999 main(A a) {
1000 print(a.test()); 1000 print(a.test());
1001 } 1001 }
1002 '''); 1002 ''');
1003 _createRefactoring('test();'); 1003 _createRefactoring('test();');
1004 // error 1004 // error
1005 return _assertConditionsFatal('Cannot inline method without body.'); 1005 return _assertConditionsFatal('Cannot inline method without body.');
1006 } 1006 }
1007 1007
1008 test_method_fieldInstance() { 1008 test_method_fieldInstance() async {
1009 indexTestUnit(r''' 1009 await indexTestUnit(r'''
1010 class A { 1010 class A {
1011 var fA; 1011 var fA;
1012 } 1012 }
1013 class B extends A { 1013 class B extends A {
1014 var fB; 1014 var fB;
1015 test() { 1015 test() {
1016 print(fA); 1016 print(fA);
1017 print(fB); 1017 print(fB);
1018 print(this.fA); 1018 print(this.fA);
1019 print(this.fB); 1019 print(this.fB);
(...skipping 16 matching lines...) Expand all
1036 main() { 1036 main() {
1037 B b = new B(); 1037 B b = new B();
1038 print(b.fA); 1038 print(b.fA);
1039 print(b.fB); 1039 print(b.fB);
1040 print(b.fA); 1040 print(b.fA);
1041 print(b.fB); 1041 print(b.fB);
1042 } 1042 }
1043 '''); 1043 ''');
1044 } 1044 }
1045 1045
1046 test_method_fieldStatic() { 1046 test_method_fieldStatic() async {
1047 indexTestUnit(r''' 1047 await indexTestUnit(r'''
1048 class A { 1048 class A {
1049 static var FA = 1; 1049 static var FA = 1;
1050 } 1050 }
1051 class B extends A { 1051 class B extends A {
1052 static var FB = 2; 1052 static var FB = 2;
1053 test() { 1053 test() {
1054 print(FA); 1054 print(FA);
1055 print(FB); 1055 print(FB);
1056 print(A.FA); 1056 print(A.FA);
1057 print(B.FB); 1057 print(B.FB);
(...skipping 16 matching lines...) Expand all
1074 main() { 1074 main() {
1075 B b = new B(); 1075 B b = new B();
1076 print(A.FA); 1076 print(A.FA);
1077 print(B.FB); 1077 print(B.FB);
1078 print(A.FA); 1078 print(A.FA);
1079 print(B.FB); 1079 print(B.FB);
1080 } 1080 }
1081 '''); 1081 ''');
1082 } 1082 }
1083 1083
1084 test_method_fieldStatic_sameClass() { 1084 test_method_fieldStatic_sameClass() async {
1085 indexTestUnit(r''' 1085 await indexTestUnit(r'''
1086 class A { 1086 class A {
1087 static var F = 1; 1087 static var F = 1;
1088 foo() { 1088 foo() {
1089 test(); 1089 test();
1090 } 1090 }
1091 test() { 1091 test() {
1092 print(A.F); 1092 print(A.F);
1093 } 1093 }
1094 } 1094 }
1095 '''); 1095 ''');
1096 _createRefactoring('test() {'); 1096 _createRefactoring('test() {');
1097 // validate change 1097 // validate change
1098 return _assertSuccessfulRefactoring(r''' 1098 return _assertSuccessfulRefactoring(r'''
1099 class A { 1099 class A {
1100 static var F = 1; 1100 static var F = 1;
1101 foo() { 1101 foo() {
1102 print(A.F); 1102 print(A.F);
1103 } 1103 }
1104 } 1104 }
1105 '''); 1105 ''');
1106 } 1106 }
1107 1107
1108 test_method_methodInstance() { 1108 test_method_methodInstance() async {
1109 indexTestUnit(r''' 1109 await indexTestUnit(r'''
1110 class A { 1110 class A {
1111 ma() {} 1111 ma() {}
1112 } 1112 }
1113 class B extends A { 1113 class B extends A {
1114 test() { 1114 test() {
1115 ma(); 1115 ma();
1116 mb(); 1116 mb();
1117 } 1117 }
1118 mb() {} 1118 mb() {}
1119 } 1119 }
(...skipping 14 matching lines...) Expand all
1134 } 1134 }
1135 mb() {} 1135 mb() {}
1136 } 1136 }
1137 main(B b) { 1137 main(B b) {
1138 b.ma(); 1138 b.ma();
1139 b.mb(); 1139 b.mb();
1140 } 1140 }
1141 '''); 1141 ''');
1142 } 1142 }
1143 1143
1144 test_method_methodStatic() { 1144 test_method_methodStatic() async {
1145 indexTestUnit(r''' 1145 await indexTestUnit(r'''
1146 class A { 1146 class A {
1147 static ma() {} 1147 static ma() {}
1148 } 1148 }
1149 class B extends A { 1149 class B extends A {
1150 static mb() {} 1150 static mb() {}
1151 test() { 1151 test() {
1152 mb(); 1152 mb();
1153 A.ma(); 1153 A.ma();
1154 B.mb(); 1154 B.mb();
1155 } 1155 }
(...skipping 17 matching lines...) Expand all
1173 } 1173 }
1174 } 1174 }
1175 main(B b) { 1175 main(B b) {
1176 B.mb(); 1176 B.mb();
1177 A.ma(); 1177 A.ma();
1178 B.mb(); 1178 B.mb();
1179 } 1179 }
1180 '''); 1180 ''');
1181 } 1181 }
1182 1182
1183 test_method_singleStatement() { 1183 test_method_singleStatement() async {
1184 indexTestUnit(r''' 1184 await indexTestUnit(r'''
1185 class A { 1185 class A {
1186 test() { 1186 test() {
1187 print(0); 1187 print(0);
1188 } 1188 }
1189 foo() { 1189 foo() {
1190 test(); 1190 test();
1191 } 1191 }
1192 } 1192 }
1193 '''); 1193 ''');
1194 _createRefactoring('test() {'); 1194 _createRefactoring('test() {');
1195 // validate change 1195 // validate change
1196 return _assertSuccessfulRefactoring(r''' 1196 return _assertSuccessfulRefactoring(r'''
1197 class A { 1197 class A {
1198 foo() { 1198 foo() {
1199 print(0); 1199 print(0);
1200 } 1200 }
1201 } 1201 }
1202 '''); 1202 ''');
1203 } 1203 }
1204 1204
1205 test_method_this() { 1205 test_method_this() async {
1206 indexTestUnit(r''' 1206 await indexTestUnit(r'''
1207 class A { 1207 class A {
1208 accept(B b) {} 1208 accept(B b) {}
1209 } 1209 }
1210 class B { 1210 class B {
1211 test(A a) { 1211 test(A a) {
1212 print(this); 1212 print(this);
1213 a.accept(this); 1213 a.accept(this);
1214 } 1214 }
1215 } 1215 }
1216 main() { 1216 main() {
(...skipping 12 matching lines...) Expand all
1229 } 1229 }
1230 main() { 1230 main() {
1231 B b = new B(); 1231 B b = new B();
1232 A a = new A(); 1232 A a = new A();
1233 print(b); 1233 print(b);
1234 a.accept(b); 1234 a.accept(b);
1235 } 1235 }
1236 '''); 1236 ''');
1237 } 1237 }
1238 1238
1239 test_method_unqualifiedInvocation() { 1239 test_method_unqualifiedInvocation() async {
1240 indexTestUnit(r''' 1240 await indexTestUnit(r'''
1241 class A { 1241 class A {
1242 test(a, b) { 1242 test(a, b) {
1243 print(a); 1243 print(a);
1244 print(b); 1244 print(b);
1245 return a + b; 1245 return a + b;
1246 } 1246 }
1247 foo() { 1247 foo() {
1248 var v = test(1, 2); 1248 var v = test(1, 2);
1249 } 1249 }
1250 } 1250 }
1251 '''); 1251 ''');
1252 _createRefactoring('test(a, b) {'); 1252 _createRefactoring('test(a, b) {');
1253 // validate change 1253 // validate change
1254 return _assertSuccessfulRefactoring(r''' 1254 return _assertSuccessfulRefactoring(r'''
1255 class A { 1255 class A {
1256 foo() { 1256 foo() {
1257 print(1); 1257 print(1);
1258 print(2); 1258 print(2);
1259 var v = 1 + 2; 1259 var v = 1 + 2;
1260 } 1260 }
1261 } 1261 }
1262 '''); 1262 ''');
1263 } 1263 }
1264 1264
1265 test_namedArgument_inBody() { 1265 test_namedArgument_inBody() async {
1266 indexTestUnit(r''' 1266 await indexTestUnit(r'''
1267 fa(pa) => fb(pb: true); 1267 fa(pa) => fb(pb: true);
1268 fb({pb: false}) {} 1268 fb({pb: false}) {}
1269 main() { 1269 main() {
1270 fa(null); 1270 fa(null);
1271 } 1271 }
1272 '''); 1272 ''');
1273 _createRefactoring('fa(null)'); 1273 _createRefactoring('fa(null)');
1274 // validate change 1274 // validate change
1275 return _assertSuccessfulRefactoring(r''' 1275 return _assertSuccessfulRefactoring(r'''
1276 fa(pa) => fb(pb: true); 1276 fa(pa) => fb(pb: true);
1277 fb({pb: false}) {} 1277 fb({pb: false}) {}
1278 main() { 1278 main() {
1279 fb(pb: true); 1279 fb(pb: true);
1280 } 1280 }
1281 '''); 1281 ''');
1282 } 1282 }
1283 1283
1284 test_namedArguments() { 1284 test_namedArguments() async {
1285 indexTestUnit(r''' 1285 await indexTestUnit(r'''
1286 test({a: 0, b: 2}) { 1286 test({a: 0, b: 2}) {
1287 print(a + b); 1287 print(a + b);
1288 } 1288 }
1289 main() { 1289 main() {
1290 test(a: 10, b: 20); 1290 test(a: 10, b: 20);
1291 test(b: 20, a: 10); 1291 test(b: 20, a: 10);
1292 } 1292 }
1293 '''); 1293 ''');
1294 _createRefactoring('test({'); 1294 _createRefactoring('test({');
1295 // validate change 1295 // validate change
1296 return _assertSuccessfulRefactoring(r''' 1296 return _assertSuccessfulRefactoring(r'''
1297 main() { 1297 main() {
1298 print(10 + 20); 1298 print(10 + 20);
1299 print(10 + 20); 1299 print(10 + 20);
1300 } 1300 }
1301 '''); 1301 ''');
1302 } 1302 }
1303 1303
1304 test_noArgument_named_hasDefault() { 1304 test_noArgument_named_hasDefault() async {
1305 verifyNoTestUnitErrors = false; 1305 verifyNoTestUnitErrors = false;
1306 indexTestUnit(r''' 1306 await indexTestUnit(r'''
1307 test({a: 42}) { 1307 test({a: 42}) {
1308 print(a); 1308 print(a);
1309 } 1309 }
1310 main() { 1310 main() {
1311 test(); 1311 test();
1312 } 1312 }
1313 '''); 1313 ''');
1314 _createRefactoring('test('); 1314 _createRefactoring('test(');
1315 // validate change 1315 // validate change
1316 return _assertSuccessfulRefactoring(r''' 1316 return _assertSuccessfulRefactoring(r'''
1317 main() { 1317 main() {
1318 print(42); 1318 print(42);
1319 } 1319 }
1320 '''); 1320 ''');
1321 } 1321 }
1322 1322
1323 test_noArgument_positional_hasDefault() { 1323 test_noArgument_positional_hasDefault() async {
1324 verifyNoTestUnitErrors = false; 1324 verifyNoTestUnitErrors = false;
1325 indexTestUnit(r''' 1325 await indexTestUnit(r'''
1326 test([a = 42]) { 1326 test([a = 42]) {
1327 print(a); 1327 print(a);
1328 } 1328 }
1329 main() { 1329 main() {
1330 test(); 1330 test();
1331 } 1331 }
1332 '''); 1332 ''');
1333 _createRefactoring('test('); 1333 _createRefactoring('test(');
1334 // validate change 1334 // validate change
1335 return _assertSuccessfulRefactoring(r''' 1335 return _assertSuccessfulRefactoring(r'''
1336 main() { 1336 main() {
1337 print(42); 1337 print(42);
1338 } 1338 }
1339 '''); 1339 ''');
1340 } 1340 }
1341 1341
1342 test_noArgument_positional_noDefault() { 1342 test_noArgument_positional_noDefault() async {
1343 verifyNoTestUnitErrors = false; 1343 verifyNoTestUnitErrors = false;
1344 indexTestUnit(r''' 1344 await indexTestUnit(r'''
1345 test([a]) { 1345 test([a]) {
1346 print(a); 1346 print(a);
1347 } 1347 }
1348 main() { 1348 main() {
1349 test(); 1349 test();
1350 } 1350 }
1351 '''); 1351 ''');
1352 _createRefactoring('test('); 1352 _createRefactoring('test(');
1353 // validate change 1353 // validate change
1354 return _assertSuccessfulRefactoring(r''' 1354 return _assertSuccessfulRefactoring(r'''
1355 main() { 1355 main() {
1356 print(null); 1356 print(null);
1357 } 1357 }
1358 '''); 1358 ''');
1359 } 1359 }
1360 1360
1361 test_noArgument_required() async { 1361 test_noArgument_required() async {
1362 verifyNoTestUnitErrors = false; 1362 verifyNoTestUnitErrors = false;
1363 indexTestUnit(r''' 1363 await indexTestUnit(r'''
1364 test(a) { 1364 test(a) {
1365 print(a); 1365 print(a);
1366 } 1366 }
1367 main() { 1367 main() {
1368 test(); 1368 test();
1369 } 1369 }
1370 '''); 1370 ''');
1371 _createRefactoring('test();'); 1371 _createRefactoring('test();');
1372 // error 1372 // error
1373 RefactoringStatus status = await refactoring.checkAllConditions(); 1373 RefactoringStatus status = await refactoring.checkAllConditions();
1374 var location = new SourceRange(findOffset('test();'), 'test()'.length); 1374 var location = new SourceRange(findOffset('test();'), 'test()'.length);
1375 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, 1375 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
1376 expectedMessage: 'No argument for the parameter "a".', 1376 expectedMessage: 'No argument for the parameter "a".',
1377 expectedContextRange: location); 1377 expectedContextRange: location);
1378 } 1378 }
1379 1379
1380 test_reference_expressionBody() { 1380 test_reference_expressionBody() async {
1381 indexTestUnit(r''' 1381 await indexTestUnit(r'''
1382 String message() => 'Hello, World!'; 1382 String message() => 'Hello, World!';
1383 main() { 1383 main() {
1384 print(message); 1384 print(message);
1385 } 1385 }
1386 '''); 1386 ''');
1387 _createRefactoring('message()'); 1387 _createRefactoring('message()');
1388 // validate change 1388 // validate change
1389 return _assertSuccessfulRefactoring(r''' 1389 return _assertSuccessfulRefactoring(r'''
1390 main() { 1390 main() {
1391 print(() => 'Hello, World!'); 1391 print(() => 'Hello, World!');
1392 } 1392 }
1393 '''); 1393 ''');
1394 } 1394 }
1395 1395
1396 test_reference_noStatement() { 1396 test_reference_noStatement() async {
1397 indexTestUnit(r''' 1397 await indexTestUnit(r'''
1398 test(a, b) { 1398 test(a, b) {
1399 return a || b; 1399 return a || b;
1400 } 1400 }
1401 foo(p1, p2, p3) => p1 && test(p2, p3); 1401 foo(p1, p2, p3) => p1 && test(p2, p3);
1402 bar() => { 1402 bar() => {
1403 'name' : baz(test) 1403 'name' : baz(test)
1404 }; 1404 };
1405 baz(x) {} 1405 baz(x) {}
1406 '''); 1406 ''');
1407 _createRefactoring('test(a, b)'); 1407 _createRefactoring('test(a, b)');
1408 // validate change 1408 // validate change
1409 return _assertSuccessfulRefactoring(r''' 1409 return _assertSuccessfulRefactoring(r'''
1410 foo(p1, p2, p3) => p1 && (p2 || p3); 1410 foo(p1, p2, p3) => p1 && (p2 || p3);
1411 bar() => { 1411 bar() => {
1412 'name' : baz((a, b) { 1412 'name' : baz((a, b) {
1413 return a || b; 1413 return a || b;
1414 }) 1414 })
1415 }; 1415 };
1416 baz(x) {} 1416 baz(x) {}
1417 '''); 1417 ''');
1418 } 1418 }
1419 1419
1420 test_reference_toLocal() { 1420 test_reference_toLocal() async {
1421 indexTestUnit(r''' 1421 await indexTestUnit(r'''
1422 main() { 1422 main() {
1423 test(a, b) { 1423 test(a, b) {
1424 print(a); 1424 print(a);
1425 print(b); 1425 print(b);
1426 } 1426 }
1427 print(test); 1427 print(test);
1428 } 1428 }
1429 '''); 1429 ''');
1430 _createRefactoring('test(a, b)'); 1430 _createRefactoring('test(a, b)');
1431 // validate change 1431 // validate change
1432 return _assertSuccessfulRefactoring(r''' 1432 return _assertSuccessfulRefactoring(r'''
1433 main() { 1433 main() {
1434 print((a, b) { 1434 print((a, b) {
1435 print(a); 1435 print(a);
1436 print(b); 1436 print(b);
1437 }); 1437 });
1438 } 1438 }
1439 '''); 1439 ''');
1440 } 1440 }
1441 1441
1442 test_reference_toTopLevel() { 1442 test_reference_toTopLevel() async {
1443 indexTestUnit(r''' 1443 await indexTestUnit(r'''
1444 test(a, b) { 1444 test(a, b) {
1445 print(a); 1445 print(a);
1446 print(b); 1446 print(b);
1447 } 1447 }
1448 main() { 1448 main() {
1449 print(test); 1449 print(test);
1450 } 1450 }
1451 '''); 1451 ''');
1452 _createRefactoring('test(a, b)'); 1452 _createRefactoring('test(a, b)');
1453 // validate change 1453 // validate change
1454 return _assertSuccessfulRefactoring(r''' 1454 return _assertSuccessfulRefactoring(r'''
1455 main() { 1455 main() {
1456 print((a, b) { 1456 print((a, b) {
1457 print(a); 1457 print(a);
1458 print(b); 1458 print(b);
1459 }); 1459 });
1460 } 1460 }
1461 '''); 1461 ''');
1462 } 1462 }
1463 1463
1464 test_removeEmptyLinesBefore_method() { 1464 test_removeEmptyLinesBefore_method() async {
1465 indexTestUnit(r''' 1465 await indexTestUnit(r'''
1466 class A { 1466 class A {
1467 before() { 1467 before() {
1468 } 1468 }
1469 1469
1470 1470
1471 test() { 1471 test() {
1472 print(0); 1472 print(0);
1473 } 1473 }
1474 1474
1475 foo() { 1475 foo() {
1476 test(); 1476 test();
1477 } 1477 }
1478 } 1478 }
1479 '''); 1479 ''');
1480 _createRefactoring('test() {'); 1480 _createRefactoring('test() {');
1481 // validate change 1481 // validate change
1482 return _assertSuccessfulRefactoring(r''' 1482 return _assertSuccessfulRefactoring(r'''
1483 class A { 1483 class A {
1484 before() { 1484 before() {
1485 } 1485 }
1486 1486
1487 foo() { 1487 foo() {
1488 print(0); 1488 print(0);
1489 } 1489 }
1490 } 1490 }
1491 '''); 1491 ''');
1492 } 1492 }
1493 1493
1494 test_setter_classMember_instance() { 1494 test_setter_classMember_instance() async {
1495 indexTestUnit(r''' 1495 await indexTestUnit(r'''
1496 class A { 1496 class A {
1497 int f; 1497 int f;
1498 void set result(x) { 1498 void set result(x) {
1499 f = x + 1; 1499 f = x + 1;
1500 } 1500 }
1501 } 1501 }
1502 main(A a) { 1502 main(A a) {
1503 a.result = 5; 1503 a.result = 5;
1504 } 1504 }
1505 '''); 1505 ''');
1506 _createRefactoring('result(x)'); 1506 _createRefactoring('result(x)');
1507 // validate change 1507 // validate change
1508 return _assertSuccessfulRefactoring(r''' 1508 return _assertSuccessfulRefactoring(r'''
1509 class A { 1509 class A {
1510 int f; 1510 int f;
1511 } 1511 }
1512 main(A a) { 1512 main(A a) {
1513 a.f = 5 + 1; 1513 a.f = 5 + 1;
1514 } 1514 }
1515 '''); 1515 ''');
1516 } 1516 }
1517 1517
1518 test_setter_topLevel() { 1518 test_setter_topLevel() async {
1519 indexTestUnit(r''' 1519 await indexTestUnit(r'''
1520 void set result(x) { 1520 void set result(x) {
1521 print(x + 1); 1521 print(x + 1);
1522 } 1522 }
1523 main() { 1523 main() {
1524 result = 5; 1524 result = 5;
1525 } 1525 }
1526 '''); 1526 ''');
1527 _createRefactoring('result(x)'); 1527 _createRefactoring('result(x)');
1528 // validate change 1528 // validate change
1529 return _assertSuccessfulRefactoring(r''' 1529 return _assertSuccessfulRefactoring(r'''
1530 main() { 1530 main() {
1531 print(5 + 1); 1531 print(5 + 1);
1532 } 1532 }
1533 '''); 1533 ''');
1534 } 1534 }
1535 1535
1536 test_singleExpression_oneUsage() { 1536 test_singleExpression_oneUsage() async {
1537 indexTestUnit(r''' 1537 await indexTestUnit(r'''
1538 test(a, b) { 1538 test(a, b) {
1539 return a + b; 1539 return a + b;
1540 } 1540 }
1541 main() { 1541 main() {
1542 var res = test(1, 2); 1542 var res = test(1, 2);
1543 } 1543 }
1544 '''); 1544 ''');
1545 _createRefactoring('test(a, b)'); 1545 _createRefactoring('test(a, b)');
1546 // validate change 1546 // validate change
1547 return _assertSuccessfulRefactoring(r''' 1547 return _assertSuccessfulRefactoring(r'''
1548 main() { 1548 main() {
1549 var res = 1 + 2; 1549 var res = 1 + 2;
1550 } 1550 }
1551 '''); 1551 ''');
1552 } 1552 }
1553 1553
1554 test_singleExpression_oneUsage_keepMethod() { 1554 test_singleExpression_oneUsage_keepMethod() async {
1555 indexTestUnit(r''' 1555 await indexTestUnit(r'''
1556 test(a, b) { 1556 test(a, b) {
1557 return a + b; 1557 return a + b;
1558 } 1558 }
1559 main() { 1559 main() {
1560 var res = test(1, 2); 1560 var res = test(1, 2);
1561 } 1561 }
1562 '''); 1562 ''');
1563 _createRefactoring('test(a, b)'); 1563 _createRefactoring('test(a, b)');
1564 deleteSource = false; 1564 deleteSource = false;
1565 // validate change 1565 // validate change
1566 return _assertSuccessfulRefactoring(r''' 1566 return _assertSuccessfulRefactoring(r'''
1567 test(a, b) { 1567 test(a, b) {
1568 return a + b; 1568 return a + b;
1569 } 1569 }
1570 main() { 1570 main() {
1571 var res = 1 + 2; 1571 var res = 1 + 2;
1572 } 1572 }
1573 '''); 1573 ''');
1574 } 1574 }
1575 1575
1576 test_singleExpression_twoUsages() { 1576 test_singleExpression_twoUsages() async {
1577 indexTestUnit(r''' 1577 await indexTestUnit(r'''
1578 test(a, b) { 1578 test(a, b) {
1579 return a + b; 1579 return a + b;
1580 } 1580 }
1581 main() { 1581 main() {
1582 var res1 = test(1, 2); 1582 var res1 = test(1, 2);
1583 var res2 = test(10, 20); 1583 var res2 = test(10, 20);
1584 } 1584 }
1585 '''); 1585 ''');
1586 _createRefactoring('test(a, b)'); 1586 _createRefactoring('test(a, b)');
1587 // validate change 1587 // validate change
1588 return _assertSuccessfulRefactoring(r''' 1588 return _assertSuccessfulRefactoring(r'''
1589 main() { 1589 main() {
1590 var res1 = 1 + 2; 1590 var res1 = 1 + 2;
1591 var res2 = 10 + 20; 1591 var res2 = 10 + 20;
1592 } 1592 }
1593 '''); 1593 ''');
1594 } 1594 }
1595 1595
1596 test_singleExpression_twoUsages_inlineOne() { 1596 test_singleExpression_twoUsages_inlineOne() async {
1597 indexTestUnit(r''' 1597 await indexTestUnit(r'''
1598 test(a, b) { 1598 test(a, b) {
1599 return a + b; 1599 return a + b;
1600 } 1600 }
1601 main() { 1601 main() {
1602 var res1 = test(1, 2); 1602 var res1 = test(1, 2);
1603 var res2 = test(10, 20); 1603 var res2 = test(10, 20);
1604 } 1604 }
1605 '''); 1605 ''');
1606 _createRefactoring('test(1, 2)'); 1606 _createRefactoring('test(1, 2)');
1607 // validate change 1607 // validate change
1608 return _assertSuccessfulRefactoring(r''' 1608 return _assertSuccessfulRefactoring(r'''
1609 test(a, b) { 1609 test(a, b) {
1610 return a + b; 1610 return a + b;
1611 } 1611 }
1612 main() { 1612 main() {
1613 var res1 = 1 + 2; 1613 var res1 = 1 + 2;
1614 var res2 = test(10, 20); 1614 var res2 = test(10, 20);
1615 } 1615 }
1616 '''); 1616 ''');
1617 } 1617 }
1618 1618
1619 test_singleExpression_wrapIntoParenthesized_alreadyInMethod() { 1619 test_singleExpression_wrapIntoParenthesized_alreadyInMethod() async {
1620 indexTestUnit(r''' 1620 await indexTestUnit(r'''
1621 test(a, b) { 1621 test(a, b) {
1622 return a * (b); 1622 return a * (b);
1623 } 1623 }
1624 main() { 1624 main() {
1625 var res = test(1, 2 + 3); 1625 var res = test(1, 2 + 3);
1626 } 1626 }
1627 '''); 1627 ''');
1628 _createRefactoring('test(a, b)'); 1628 _createRefactoring('test(a, b)');
1629 // validate change 1629 // validate change
1630 return _assertSuccessfulRefactoring(r''' 1630 return _assertSuccessfulRefactoring(r'''
1631 main() { 1631 main() {
1632 var res = 1 * (2 + 3); 1632 var res = 1 * (2 + 3);
1633 } 1633 }
1634 '''); 1634 ''');
1635 } 1635 }
1636 1636
1637 test_singleExpression_wrapIntoParenthesized_asNeeded() { 1637 test_singleExpression_wrapIntoParenthesized_asNeeded() async {
1638 indexTestUnit(r''' 1638 await indexTestUnit(r'''
1639 test(a, b) { 1639 test(a, b) {
1640 return a * b; 1640 return a * b;
1641 } 1641 }
1642 main() { 1642 main() {
1643 var res1 = test(1, 2 + 3); 1643 var res1 = test(1, 2 + 3);
1644 var res2 = test(1, (2 + 3)); 1644 var res2 = test(1, (2 + 3));
1645 } 1645 }
1646 '''); 1646 ''');
1647 _createRefactoring('test(a, b)'); 1647 _createRefactoring('test(a, b)');
1648 // validate change 1648 // validate change
1649 return _assertSuccessfulRefactoring(r''' 1649 return _assertSuccessfulRefactoring(r'''
1650 main() { 1650 main() {
1651 var res1 = 1 * (2 + 3); 1651 var res1 = 1 * (2 + 3);
1652 var res2 = 1 * (2 + 3); 1652 var res2 = 1 * (2 + 3);
1653 } 1653 }
1654 '''); 1654 ''');
1655 } 1655 }
1656 1656
1657 test_singleExpression_wrapIntoParenthesized_bool() { 1657 test_singleExpression_wrapIntoParenthesized_bool() async {
1658 indexTestUnit(r''' 1658 await indexTestUnit(r'''
1659 test(bool a, bool b) { 1659 test(bool a, bool b) {
1660 return a || b; 1660 return a || b;
1661 } 1661 }
1662 main(bool p, bool p2, bool p3) { 1662 main(bool p, bool p2, bool p3) {
1663 var res1 = p && test(p2, p3); 1663 var res1 = p && test(p2, p3);
1664 var res2 = p || test(p2, p3); 1664 var res2 = p || test(p2, p3);
1665 } 1665 }
1666 '''); 1666 ''');
1667 _createRefactoring('test(bool a, bool b)'); 1667 _createRefactoring('test(bool a, bool b)');
1668 // validate change 1668 // validate change
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 this.refactoringChange = change; 1709 this.refactoringChange = change;
1710 assertTestChangeResult(expectedCode); 1710 assertTestChangeResult(expectedCode);
1711 } 1711 }
1712 1712
1713 void _createRefactoring(String search) { 1713 void _createRefactoring(String search) {
1714 int offset = findOffset(search); 1714 int offset = findOffset(search);
1715 refactoring = new InlineMethodRefactoring( 1715 refactoring = new InlineMethodRefactoring(
1716 searchEngine, getResolvedUnitWithElement, testUnit, offset); 1716 searchEngine, getResolvedUnitWithElement, testUnit, offset);
1717 } 1717 }
1718 } 1718 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698