| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.completion.statement; | 5 library test.services.completion.statement; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol_server.dart'; | 7 import 'package:analysis_server/src/protocol_server.dart'; |
| 8 import 'package:analysis_server/src/services/completion/statement/statement_comp
letion.dart'; | 8 import 'package:analysis_server/src/services/completion/statement/statement_comp
letion.dart'; |
| 9 import 'package:analyzer/src/dart/analysis/driver.dart'; | 9 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 12 | 12 |
| 13 import '../../../abstract_single_unit.dart'; | 13 import '../../../abstract_single_unit.dart'; |
| 14 | 14 |
| 15 main() { | 15 main() { |
| 16 defineReflectiveSuite(() { | 16 defineReflectiveSuite(() { |
| 17 defineReflectiveTests(_DoCompletionTest); | 17 defineReflectiveTests(_DoCompletionTest); |
| 18 defineReflectiveTests(_ForCompletionTest); | 18 defineReflectiveTests(_ForCompletionTest); |
| 19 defineReflectiveTests(_ForEachCompletionTest); |
| 19 defineReflectiveTests(_IfCompletionTest); | 20 defineReflectiveTests(_IfCompletionTest); |
| 20 defineReflectiveTests(_SimpleCompletionTest); | 21 defineReflectiveTests(_SimpleCompletionTest); |
| 22 defineReflectiveTests(_SwitchCompletionTest); |
| 21 defineReflectiveTests(_WhileCompletionTest); | 23 defineReflectiveTests(_WhileCompletionTest); |
| 22 }); | 24 }); |
| 23 } | 25 } |
| 24 | 26 |
| 25 class StatementCompletionTest extends AbstractSingleUnitTest { | 27 class StatementCompletionTest extends AbstractSingleUnitTest { |
| 26 SourceChange change; | 28 SourceChange change; |
| 27 | 29 |
| 28 bool get enableNewAnalysisDriver => true; | 30 bool get enableNewAnalysisDriver => true; |
| 29 | 31 |
| 30 int _after(String source, String match) => | 32 int _after(String source, String match) => |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 main() { | 344 main() { |
| 343 for (int i = 0; ) { | 345 for (int i = 0; ) { |
| 344 } | 346 } |
| 345 } | 347 } |
| 346 ''', | 348 ''', |
| 347 (s) => _after(s, '0; ')); | 349 (s) => _after(s, '0; ')); |
| 348 } | 350 } |
| 349 } | 351 } |
| 350 | 352 |
| 351 @reflectiveTest | 353 @reflectiveTest |
| 354 class _ForEachCompletionTest extends StatementCompletionTest { |
| 355 test_emptyIdentifier() async { |
| 356 await _prepareCompletion( |
| 357 'in xs)', |
| 358 ''' |
| 359 main() { |
| 360 for (in xs) |
| 361 } |
| 362 ''', |
| 363 atEnd: true); |
| 364 _assertHasChange( |
| 365 'Complete for-each-statement', |
| 366 ''' |
| 367 main() { |
| 368 for ( in xs) { |
| 369 //// |
| 370 } |
| 371 } |
| 372 ''', |
| 373 (s) => _after(s, 'for (')); |
| 374 } |
| 375 |
| 376 test_emptyIdentifierAndIterable() async { |
| 377 await _prepareCompletion( |
| 378 'in)', |
| 379 ''' |
| 380 main() { |
| 381 for (in) |
| 382 } |
| 383 ''', |
| 384 atEnd: true); |
| 385 _assertHasChange( |
| 386 'Complete for-each-statement', |
| 387 ''' |
| 388 main() { |
| 389 for ( in ) { |
| 390 //// |
| 391 } |
| 392 } |
| 393 ''', |
| 394 (s) => _after(s, 'for (')); |
| 395 } |
| 396 |
| 397 test_emptyIterable() async { |
| 398 await _prepareCompletion( |
| 399 'in)', |
| 400 ''' |
| 401 main() { |
| 402 for (var x in) |
| 403 } |
| 404 ''', |
| 405 atEnd: true); |
| 406 _assertHasChange( |
| 407 'Complete for-each-statement', |
| 408 ''' |
| 409 main() { |
| 410 for (var x in ) { |
| 411 //// |
| 412 } |
| 413 } |
| 414 ''', |
| 415 (s) => _after(s, 'in ')); |
| 416 } |
| 417 } |
| 418 |
| 419 @reflectiveTest |
| 352 class _IfCompletionTest extends StatementCompletionTest { | 420 class _IfCompletionTest extends StatementCompletionTest { |
| 353 test_afterCondition_BAD() async { | 421 test_afterCondition_BAD() async { |
| 354 // TODO(messick): Fix the code to make this like test_completeIfWithConditio
n. | 422 // TODO(messick): Fix the code to make this like test_completeIfWithConditio
n. |
| 355 // Recap: Finding the node at the selectionOffset returns the block, not the | 423 // Recap: Finding the node at the selectionOffset returns the block, not the |
| 356 // if-statement. Need to understand if that only happens when the if-stateme
nt | 424 // if-statement. Need to understand if that only happens when the if-stateme
nt |
| 357 // is the only statement in the block, or perhaps first or last? And what | 425 // is the only statement in the block, or perhaps first or last? And what |
| 358 // happens when it is in the middle of other statements? | 426 // happens when it is in the middle of other statements? |
| 359 await _prepareCompletion( | 427 await _prepareCompletion( |
| 360 'if (true) ', // Trigger completion after space. | 428 'if (true) ', // Trigger completion after space. |
| 361 ''' | 429 ''' |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 main() { | 588 main() { |
| 521 int v = 1; | 589 int v = 1; |
| 522 //// | 590 //// |
| 523 } | 591 } |
| 524 ''', | 592 ''', |
| 525 (s) => _afterLast(s, ' ')); | 593 (s) => _afterLast(s, ' ')); |
| 526 } | 594 } |
| 527 } | 595 } |
| 528 | 596 |
| 529 @reflectiveTest | 597 @reflectiveTest |
| 598 class _SwitchCompletionTest extends StatementCompletionTest { |
| 599 test_emptyCondition() async { |
| 600 await _prepareCompletion( |
| 601 'switch', |
| 602 ''' |
| 603 main() { |
| 604 switch () |
| 605 } |
| 606 ''', |
| 607 atEnd: true); |
| 608 _assertHasChange( |
| 609 'Complete switch-statement', |
| 610 ''' |
| 611 main() { |
| 612 switch () { |
| 613 //// |
| 614 } |
| 615 } |
| 616 ''', |
| 617 (s) => _after(s, 'switch (')); |
| 618 } |
| 619 |
| 620 test_keywordOnly() async { |
| 621 await _prepareCompletion( |
| 622 'switch', |
| 623 ''' |
| 624 main() { |
| 625 switch//// |
| 626 } |
| 627 ''', |
| 628 atEnd: true); |
| 629 _assertHasChange( |
| 630 'Complete switch-statement', |
| 631 ''' |
| 632 main() { |
| 633 switch () { |
| 634 //// |
| 635 } |
| 636 } |
| 637 ''', |
| 638 (s) => _after(s, 'switch (')); |
| 639 } |
| 640 |
| 641 test_keywordSpace() async { |
| 642 await _prepareCompletion( |
| 643 'switch', |
| 644 ''' |
| 645 main() { |
| 646 switch //// |
| 647 } |
| 648 ''', |
| 649 atEnd: true); |
| 650 _assertHasChange( |
| 651 'Complete switch-statement', |
| 652 ''' |
| 653 main() { |
| 654 switch () { |
| 655 //// |
| 656 } |
| 657 } |
| 658 ''', |
| 659 (s) => _after(s, 'switch (')); |
| 660 } |
| 661 } |
| 662 |
| 663 @reflectiveTest |
| 530 class _WhileCompletionTest extends StatementCompletionTest { | 664 class _WhileCompletionTest extends StatementCompletionTest { |
| 531 /* | 665 /* |
| 532 The implementation of completion for while-statements is shared with | 666 The implementation of completion for while-statements is shared with |
| 533 if-statements. Here we check that the wrapper for while-statements | 667 if-statements. Here we check that the wrapper for while-statements |
| 534 functions as expected. The individual test cases are covered by the | 668 functions as expected. The individual test cases are covered by the |
| 535 _IfCompletionTest tests. If the implementation changes then the same | 669 _IfCompletionTest tests. If the implementation changes then the same |
| 536 set of tests defined for if-statements should be duplicated here. | 670 set of tests defined for if-statements should be duplicated here. |
| 537 */ | 671 */ |
| 538 test_keywordOnly() async { | 672 test_keywordOnly() async { |
| 539 await _prepareCompletion( | 673 await _prepareCompletion( |
| 540 'while', | 674 'while', |
| 541 ''' | 675 ''' |
| 542 main() { | 676 main() { |
| 543 while //// | 677 while //// |
| 544 } | 678 } |
| 545 ''', | 679 ''', |
| 546 atEnd: true); | 680 atEnd: true); |
| 547 _assertHasChange( | 681 _assertHasChange( |
| 548 'Complete while-statement', | 682 'Complete while-statement', |
| 549 ''' | 683 ''' |
| 550 main() { | 684 main() { |
| 551 while () { | 685 while () { |
| 552 //// | 686 //// |
| 553 } | 687 } |
| 554 } | 688 } |
| 555 ''', | 689 ''', |
| 556 (s) => _after(s, 'while (')); | 690 (s) => _after(s, 'while (')); |
| 557 } | 691 } |
| 558 } | 692 } |
| OLD | NEW |