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

Side by Side Diff: pkg/analysis_server/test/services/completion/statement/statement_completion_test.dart

Issue 2842523002: Fix detection of bad catch-clauses and try-statements (Closed)
Patch Set: Created 3 years, 8 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) 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';
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 } 585 }
586 } 586 }
587 ''', 587 ''',
588 (s) => _after(s, 'in ')); 588 (s) => _after(s, 'in '));
589 } 589 }
590 } 590 }
591 591
592 @reflectiveTest 592 @reflectiveTest
593 class _IfCompletionTest extends StatementCompletionTest { 593 class _IfCompletionTest extends StatementCompletionTest {
594 test_afterCondition_BAD() async { 594 test_afterCondition_BAD() async {
595 // TODO(messick): Fix the code to make this like test_completeIfWithConditio n. 595 // TODO(messick) Stop inserting the space after the closing brace.
596 // Recap: Finding the node at the selectionOffset returns the block, not the
597 // if-statement. Need to understand if that only happens when the if-stateme nt
598 // is the only statement in the block, or perhaps first or last? And what
599 // happens when it is in the middle of other statements?
600 await _prepareCompletion( 596 await _prepareCompletion(
601 'if (true) ', // Trigger completion after space. 597 'if (true) ', // Trigger completion after space.
602 ''' 598 '''
603 main() { 599 main() {
604 if (true) //// 600 if (true) ////
605 } 601 }
606 ''', 602 ''',
607 atEnd: true); 603 atEnd: true);
608 _assertHasChange( 604 _assertHasChange(
609 // Note: This is not what we want. 605 'Complete if-statement',
610 'Insert a newline at the end of the current line',
611 ''' 606 '''
612 main() { 607 main() {
613 if (true) //// 608 if (true) {
614 } 609 ////
610 } ////
615 } 611 }
616 ''', 612 ''',
617 (s) => _after(s, 'if (true) ')); 613 (s) => _after(s, ' '));
618 } 614 }
619 615
620 test_emptyCondition() async { 616 test_emptyCondition() async {
621 await _prepareCompletion( 617 await _prepareCompletion(
622 'if ()', 618 'if ()',
623 ''' 619 '''
624 main() { 620 main() {
625 if () 621 if ()
626 } 622 }
627 ''', 623 ''',
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 } 826 }
831 ''', 827 ''',
832 (s) => _after(s, 'switch (')); 828 (s) => _after(s, 'switch ('));
833 } 829 }
834 } 830 }
835 831
836 @reflectiveTest 832 @reflectiveTest
837 class _TryCompletionTest extends StatementCompletionTest { 833 class _TryCompletionTest extends StatementCompletionTest {
838 test_catchOnly() async { 834 test_catchOnly() async {
839 await _prepareCompletion( 835 await _prepareCompletion(
840 'catch', 836 '{} catch',
841 ''' 837 '''
842 main() { 838 main() {
843 try { 839 try {
844 } catch(e){} catch //// 840 } catch(e){} catch ////
845 } 841 }
846 ''', 842 ''',
847 atEnd: true); 843 atEnd: true);
848 _assertHasChange( 844 _assertHasChange(
849 'Complete try-statement', 845 'Complete try-statement',
850 ''' 846 '''
851 main() { 847 main() {
852 try { 848 try {
853 } catch(e){} catch () { 849 } catch(e){} catch () {
854 //// 850 ////
855 } 851 }
856 } 852 }
857 ''', 853 ''',
858 (s) => _after(s, 'catch (')); 854 (s) => _after(s, 'catch ('));
859 } 855 }
860 856
857 test_catchSecond() async {
858 await _prepareCompletion(
859 '} catch ',
860 '''
861 main() {
862 try {
863 } catch() {
864 } catch(e){} catch ////
865 }
866 ''',
867 atEnd: true);
868 _assertHasChange(
869 'Complete try-statement',
870 '''
871 main() {
872 try {
873 } catch() {
874 } catch(e){} catch () {
875 ////
876 }
877 }
878 ''',
879 (s) => _afterLast(s, 'catch ('));
880 }
881
861 test_finallyOnly() async { 882 test_finallyOnly() async {
862 await _prepareCompletion( 883 await _prepareCompletion(
863 'finally', 884 'finally',
864 ''' 885 '''
865 main() { 886 main() {
866 try { 887 try {
867 } finally 888 } finally
868 } 889 }
869 ''', 890 ''',
870 atEnd: true); 891 atEnd: true);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 ''' 1086 '''
1066 main() { 1087 main() {
1067 while () { 1088 while () {
1068 //// 1089 ////
1069 } 1090 }
1070 } 1091 }
1071 ''', 1092 ''',
1072 (s) => _after(s, 'while (')); 1093 (s) => _after(s, 'while ('));
1073 } 1094 }
1074 } 1095 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698