| 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.correction.fix; | 5 library test.services.correction.fix; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; | 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 345 |
| 346 part of my.lib; | 346 part of my.lib; |
| 347 | 347 |
| 348 class A {} | 348 class A {} |
| 349 '''); | 349 '''); |
| 350 } | 350 } |
| 351 | 351 |
| 352 test_addSync_asyncFor() async { | 352 test_addSync_asyncFor() async { |
| 353 resolveTestUnit(''' | 353 resolveTestUnit(''' |
| 354 import 'dart:async'; | 354 import 'dart:async'; |
| 355 main(Stream<String> names) { | 355 void main(Stream<String> names) { |
| 356 await for (String name in names) { | 356 await for (String name in names) { |
| 357 print(name); | 357 print(name); |
| 358 } | 358 } |
| 359 } | 359 } |
| 360 '''); | 360 '''); |
| 361 await assertHasFix( | 361 await assertHasFix( |
| 362 DartFixKind.ADD_ASYNC, | 362 DartFixKind.ADD_ASYNC, |
| 363 ''' | 363 ''' |
| 364 import 'dart:async'; | 364 import 'dart:async'; |
| 365 main(Stream<String> names) async { | 365 Future main(Stream<String> names) async { |
| 366 await for (String name in names) { | 366 await for (String name in names) { |
| 367 print(name); | 367 print(name); |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 '''); | 370 '''); |
| 371 } | 371 } |
| 372 | 372 |
| 373 test_addSync_BAD_nullFunctionBody() async { | 373 test_addSync_BAD_nullFunctionBody() async { |
| 374 resolveTestUnit(''' | 374 resolveTestUnit(''' |
| 375 var F = await; | 375 var F = await; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 main() => await foo(); | 426 main() => await foo(); |
| 427 '''); | 427 '''); |
| 428 await assertHasFix( | 428 await assertHasFix( |
| 429 DartFixKind.ADD_ASYNC, | 429 DartFixKind.ADD_ASYNC, |
| 430 ''' | 430 ''' |
| 431 foo() {} | 431 foo() {} |
| 432 main() async => await foo(); | 432 main() async => await foo(); |
| 433 '''); | 433 '''); |
| 434 } | 434 } |
| 435 | 435 |
| 436 test_addSync_returnFuture() async { |
| 437 errorFilter = (AnalysisError error) { |
| 438 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
| 439 }; |
| 440 resolveTestUnit(''' |
| 441 foo() {} |
| 442 int main() { |
| 443 await foo(); |
| 444 return 42; |
| 445 } |
| 446 '''); |
| 447 await assertHasFix( |
| 448 DartFixKind.ADD_ASYNC, |
| 449 ''' |
| 450 import 'dart:async'; |
| 451 |
| 452 foo() {} |
| 453 Future<int> main() async { |
| 454 await foo(); |
| 455 return 42; |
| 456 } |
| 457 '''); |
| 458 } |
| 459 |
| 460 test_addSync_returnFuture_alreadyFuture() async { |
| 461 errorFilter = (AnalysisError error) { |
| 462 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
| 463 }; |
| 464 resolveTestUnit(''' |
| 465 import 'dart:async'; |
| 466 foo() {} |
| 467 Future<int> main() { |
| 468 await foo(); |
| 469 return 42; |
| 470 } |
| 471 '''); |
| 472 await assertHasFix( |
| 473 DartFixKind.ADD_ASYNC, |
| 474 ''' |
| 475 import 'dart:async'; |
| 476 foo() {} |
| 477 Future<int> main() async { |
| 478 await foo(); |
| 479 return 42; |
| 480 } |
| 481 '''); |
| 482 } |
| 483 |
| 484 test_addSync_returnFuture_dynamic() async { |
| 485 errorFilter = (AnalysisError error) { |
| 486 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
| 487 }; |
| 488 resolveTestUnit(''' |
| 489 foo() {} |
| 490 dynamic main() { |
| 491 await foo(); |
| 492 return 42; |
| 493 } |
| 494 '''); |
| 495 await assertHasFix( |
| 496 DartFixKind.ADD_ASYNC, |
| 497 ''' |
| 498 foo() {} |
| 499 dynamic main() async { |
| 500 await foo(); |
| 501 return 42; |
| 502 } |
| 503 '''); |
| 504 } |
| 505 |
| 506 test_addSync_returnFuture_noType() async { |
| 507 errorFilter = (AnalysisError error) { |
| 508 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
| 509 }; |
| 510 resolveTestUnit(''' |
| 511 foo() {} |
| 512 main() { |
| 513 await foo(); |
| 514 return 42; |
| 515 } |
| 516 '''); |
| 517 await assertHasFix( |
| 518 DartFixKind.ADD_ASYNC, |
| 519 ''' |
| 520 foo() {} |
| 521 main() async { |
| 522 await foo(); |
| 523 return 42; |
| 524 } |
| 525 '''); |
| 526 } |
| 527 |
| 436 test_boolean() async { | 528 test_boolean() async { |
| 437 resolveTestUnit(''' | 529 resolveTestUnit(''' |
| 438 main() { | 530 main() { |
| 439 boolean v; | 531 boolean v; |
| 440 } | 532 } |
| 441 '''); | 533 '''); |
| 442 await assertHasFix( | 534 await assertHasFix( |
| 443 DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, | 535 DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, |
| 444 ''' | 536 ''' |
| 445 main() { | 537 main() { |
| (...skipping 4389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4835 int offset = resultCode.indexOf(search); | 4927 int offset = resultCode.indexOf(search); |
| 4836 positions.add(new Position(testFile, offset)); | 4928 positions.add(new Position(testFile, offset)); |
| 4837 } | 4929 } |
| 4838 return positions; | 4930 return positions; |
| 4839 } | 4931 } |
| 4840 | 4932 |
| 4841 void _performAnalysis() { | 4933 void _performAnalysis() { |
| 4842 while (context.performAnalysisTask().hasMoreWork); | 4934 while (context.performAnalysisTask().hasMoreWork); |
| 4843 } | 4935 } |
| 4844 } | 4936 } |
| OLD | NEW |