| 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(_ForEachCompletionTest); |
| 20 defineReflectiveTests(_IfCompletionTest); | 20 defineReflectiveTests(_IfCompletionTest); |
| 21 defineReflectiveTests(_SimpleCompletionTest); | 21 defineReflectiveTests(_SimpleCompletionTest); |
| 22 defineReflectiveTests(_SwitchCompletionTest); | 22 defineReflectiveTests(_SwitchCompletionTest); |
| 23 defineReflectiveTests(_TryCompletionTest); |
| 23 defineReflectiveTests(_WhileCompletionTest); | 24 defineReflectiveTests(_WhileCompletionTest); |
| 24 }); | 25 }); |
| 25 } | 26 } |
| 26 | 27 |
| 27 class StatementCompletionTest extends AbstractSingleUnitTest { | 28 class StatementCompletionTest extends AbstractSingleUnitTest { |
| 28 SourceChange change; | 29 SourceChange change; |
| 29 | 30 |
| 30 bool get enableNewAnalysisDriver => true; | 31 bool get enableNewAnalysisDriver => true; |
| 31 | 32 |
| 32 int _after(String source, String match) => | 33 int _after(String source, String match) => |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 switch () { | 655 switch () { |
| 655 //// | 656 //// |
| 656 } | 657 } |
| 657 } | 658 } |
| 658 ''', | 659 ''', |
| 659 (s) => _after(s, 'switch (')); | 660 (s) => _after(s, 'switch (')); |
| 660 } | 661 } |
| 661 } | 662 } |
| 662 | 663 |
| 663 @reflectiveTest | 664 @reflectiveTest |
| 665 class _TryCompletionTest extends StatementCompletionTest { |
| 666 test_catchOnly() async { |
| 667 await _prepareCompletion( |
| 668 'catch', |
| 669 ''' |
| 670 main() { |
| 671 try { |
| 672 } catch(e){} catch //// |
| 673 } |
| 674 ''', |
| 675 atEnd: true); |
| 676 _assertHasChange( |
| 677 'Complete try-statement', |
| 678 ''' |
| 679 main() { |
| 680 try { |
| 681 } catch(e){} catch () { |
| 682 //// |
| 683 } |
| 684 } |
| 685 ''', |
| 686 (s) => _after(s, 'catch (')); |
| 687 } |
| 688 |
| 689 test_finallyOnly() async { |
| 690 await _prepareCompletion( |
| 691 'finally', |
| 692 ''' |
| 693 main() { |
| 694 try { |
| 695 } finally |
| 696 } |
| 697 ''', |
| 698 atEnd: true); |
| 699 _assertHasChange( |
| 700 'Complete try-statement', |
| 701 ''' |
| 702 main() { |
| 703 try { |
| 704 } finally { |
| 705 //// |
| 706 } |
| 707 } |
| 708 ''', |
| 709 (s) => _after(s, ' ')); |
| 710 } |
| 711 |
| 712 test_keywordOnly() async { |
| 713 await _prepareCompletion( |
| 714 'try', |
| 715 ''' |
| 716 main() { |
| 717 try//// |
| 718 } |
| 719 ''', |
| 720 atEnd: true); |
| 721 _assertHasChange( |
| 722 'Complete try-statement', |
| 723 ''' |
| 724 main() { |
| 725 try { |
| 726 //// |
| 727 } |
| 728 } |
| 729 ''', |
| 730 (s) => _after(s, ' ')); |
| 731 } |
| 732 |
| 733 test_keywordSpace() async { |
| 734 await _prepareCompletion( |
| 735 'try', |
| 736 ''' |
| 737 main() { |
| 738 try //// |
| 739 } |
| 740 ''', |
| 741 atEnd: true); |
| 742 _assertHasChange( |
| 743 'Complete try-statement', |
| 744 ''' |
| 745 main() { |
| 746 try { |
| 747 //// |
| 748 } |
| 749 } |
| 750 ''', |
| 751 (s) => _after(s, ' ')); |
| 752 } |
| 753 |
| 754 test_onCatch() async { |
| 755 await _prepareCompletion( |
| 756 'on', |
| 757 ''' |
| 758 main() { |
| 759 try { |
| 760 } on catch |
| 761 } |
| 762 ''', |
| 763 atEnd: true); |
| 764 // It would be better to expect the cursor to follow the on-keyword but |
| 765 // the parser thinks the exception type is 'catch' so it's kinda broken. |
| 766 // See https://github.com/dart-lang/sdk/issues/29410 |
| 767 _assertHasChange( |
| 768 'Complete try-statement', |
| 769 ''' |
| 770 main() { |
| 771 try { |
| 772 } on catch () { |
| 773 //// |
| 774 } |
| 775 } |
| 776 ''', |
| 777 (s) => _after(s, 'catch (')); |
| 778 } |
| 779 |
| 780 test_onOnly() async { |
| 781 await _prepareCompletion( |
| 782 'on', |
| 783 ''' |
| 784 main() { |
| 785 try { |
| 786 } on |
| 787 } |
| 788 ''', |
| 789 atEnd: true); |
| 790 _assertHasChange( |
| 791 'Complete try-statement', |
| 792 ''' |
| 793 main() { |
| 794 try { |
| 795 } on { |
| 796 //// |
| 797 } |
| 798 } |
| 799 ''', |
| 800 (s) => _after(s, ' on ')); |
| 801 } |
| 802 |
| 803 test_onSpace() async { |
| 804 await _prepareCompletion( |
| 805 'on', |
| 806 ''' |
| 807 main() { |
| 808 try { |
| 809 } on //// |
| 810 } |
| 811 ''', |
| 812 atEnd: true); |
| 813 _assertHasChange( |
| 814 'Complete try-statement', |
| 815 ''' |
| 816 main() { |
| 817 try { |
| 818 } on { |
| 819 //// |
| 820 } |
| 821 } |
| 822 ''', |
| 823 (s) => _after(s, ' on ')); |
| 824 } |
| 825 |
| 826 test_onSpaces() async { |
| 827 await _prepareCompletion( |
| 828 'on', |
| 829 ''' |
| 830 main() { |
| 831 try { |
| 832 } on //// |
| 833 } |
| 834 ''', |
| 835 atEnd: true); |
| 836 _assertHasChange( |
| 837 'Complete try-statement', |
| 838 ''' |
| 839 main() { |
| 840 try { |
| 841 } on { |
| 842 //// |
| 843 } |
| 844 } |
| 845 ''', |
| 846 (s) => _after(s, ' on ')); |
| 847 } |
| 848 |
| 849 test_onType() async { |
| 850 await _prepareCompletion( |
| 851 'on', |
| 852 ''' |
| 853 main() { |
| 854 try { |
| 855 } on Exception |
| 856 } |
| 857 ''', |
| 858 atEnd: true); |
| 859 _assertHasChange( |
| 860 'Complete try-statement', |
| 861 ''' |
| 862 main() { |
| 863 try { |
| 864 } on Exception { |
| 865 //// |
| 866 } |
| 867 } |
| 868 ''', |
| 869 (s) => _after(s, ' ')); |
| 870 } |
| 871 } |
| 872 |
| 873 @reflectiveTest |
| 664 class _WhileCompletionTest extends StatementCompletionTest { | 874 class _WhileCompletionTest extends StatementCompletionTest { |
| 665 /* | 875 /* |
| 666 The implementation of completion for while-statements is shared with | 876 The implementation of completion for while-statements is shared with |
| 667 if-statements. Here we check that the wrapper for while-statements | 877 if-statements. Here we check that the wrapper for while-statements |
| 668 functions as expected. The individual test cases are covered by the | 878 functions as expected. The individual test cases are covered by the |
| 669 _IfCompletionTest tests. If the implementation changes then the same | 879 _IfCompletionTest tests. If the implementation changes then the same |
| 670 set of tests defined for if-statements should be duplicated here. | 880 set of tests defined for if-statements should be duplicated here. |
| 671 */ | 881 */ |
| 672 test_keywordOnly() async { | 882 test_keywordOnly() async { |
| 673 await _prepareCompletion( | 883 await _prepareCompletion( |
| 674 'while', | 884 'while', |
| 675 ''' | 885 ''' |
| 676 main() { | 886 main() { |
| 677 while //// | 887 while //// |
| 678 } | 888 } |
| 679 ''', | 889 ''', |
| 680 atEnd: true); | 890 atEnd: true); |
| 681 _assertHasChange( | 891 _assertHasChange( |
| 682 'Complete while-statement', | 892 'Complete while-statement', |
| 683 ''' | 893 ''' |
| 684 main() { | 894 main() { |
| 685 while () { | 895 while () { |
| 686 //// | 896 //// |
| 687 } | 897 } |
| 688 } | 898 } |
| 689 ''', | 899 ''', |
| 690 (s) => _after(s, 'while (')); | 900 (s) => _after(s, 'while (')); |
| 691 } | 901 } |
| 692 } | 902 } |
| OLD | NEW |