| 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.edit.refactoring; | 5 library test.edit.refactoring; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/edit/edit_domain.dart'; | 9 import 'package:analysis_server/src/edit/edit_domain.dart'; |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 test_nameWarning() { | 90 test_nameWarning() { |
| 91 addTestFile(''' | 91 addTestFile(''' |
| 92 main() { | 92 main() { |
| 93 print(1 + 2); | 93 print(1 + 2); |
| 94 } | 94 } |
| 95 '''); | 95 '''); |
| 96 return getRefactoringResult(() { | 96 return getRefactoringResult(() { |
| 97 return sendStringRequest('1 + 2', 'Name', true); | 97 return sendStringRequest('1 + 2', 'Name', true); |
| 98 }).then((result) { | 98 }).then((result) { |
| 99 assertResultProblemsWarning( | 99 assertResultProblemsWarning( |
| 100 result, | 100 result.optionsProblems, |
| 101 'Variable name should start with a lowercase letter.'); | 101 'Variable name should start with a lowercase letter.'); |
| 102 // ...but there is still a change | 102 // ...but there is still a change |
| 103 assertTestRefactoringResult(result, ''' | 103 assertTestRefactoringResult(result, ''' |
| 104 main() { | 104 main() { |
| 105 var Name = 1 + 2; | 105 var Name = 1 + 2; |
| 106 print(Name); | 106 print(Name); |
| 107 } | 107 } |
| 108 '''); | 108 '''); |
| 109 }); | 109 }); |
| 110 } | 110 } |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 expect(feedback.occurrences, 2); | 554 expect(feedback.occurrences, 2); |
| 555 }); | 555 }); |
| 556 } | 556 } |
| 557 | 557 |
| 558 test_init_fatalError_notVariable() { | 558 test_init_fatalError_notVariable() { |
| 559 addTestFile('main() {}'); | 559 addTestFile('main() {}'); |
| 560 return getRefactoringResult(() { | 560 return getRefactoringResult(() { |
| 561 return _sendInlineRequest('main() {}'); | 561 return _sendInlineRequest('main() {}'); |
| 562 }).then((result) { | 562 }).then((result) { |
| 563 assertResultProblemsFatal( | 563 assertResultProblemsFatal( |
| 564 result, | 564 result.initialProblems, |
| 565 'Local variable declaration or reference must be selected to activate
this refactoring.'); | 565 'Local variable declaration or reference must be selected to activate
this refactoring.'); |
| 566 // ...there is no any change | 566 // ...there is no any change |
| 567 expect(result.change, isNull); | 567 expect(result.change, isNull); |
| 568 }); | 568 }); |
| 569 } | 569 } |
| 570 | 570 |
| 571 Future<Response> _sendInlineRequest(String search) { | 571 Future<Response> _sendInlineRequest(String search) { |
| 572 Request request = new EditGetRefactoringParams( | 572 Request request = new EditGetRefactoringParams( |
| 573 RefactoringKind.INLINE_LOCAL_VARIABLE, | 573 RefactoringKind.INLINE_LOCAL_VARIABLE, |
| 574 testFile, | 574 testFile, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 605 expect(feedback.isDeclaration, isTrue); | 605 expect(feedback.isDeclaration, isTrue); |
| 606 }); | 606 }); |
| 607 } | 607 } |
| 608 | 608 |
| 609 test_init_fatalError_noMethod() { | 609 test_init_fatalError_noMethod() { |
| 610 addTestFile('// nothing to inline'); | 610 addTestFile('// nothing to inline'); |
| 611 return getRefactoringResult(() { | 611 return getRefactoringResult(() { |
| 612 return _sendInlineRequest('// nothing'); | 612 return _sendInlineRequest('// nothing'); |
| 613 }).then((result) { | 613 }).then((result) { |
| 614 assertResultProblemsFatal( | 614 assertResultProblemsFatal( |
| 615 result, | 615 result.initialProblems, |
| 616 'Method declaration or reference must be selected to activate this ref
actoring.'); | 616 'Method declaration or reference must be selected to activate this ref
actoring.'); |
| 617 // ...there is no any change | 617 // ...there is no any change |
| 618 expect(result.change, isNull); | 618 expect(result.change, isNull); |
| 619 }); | 619 }); |
| 620 } | 620 } |
| 621 | 621 |
| 622 test_method() { | 622 test_method() { |
| 623 addTestFile(''' | 623 addTestFile(''' |
| 624 class A { | 624 class A { |
| 625 int f; | 625 int f; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 test_class_options_fatalError() { | 830 test_class_options_fatalError() { |
| 831 addTestFile(''' | 831 addTestFile(''' |
| 832 class Test {} | 832 class Test {} |
| 833 main() { | 833 main() { |
| 834 Test v; | 834 Test v; |
| 835 } | 835 } |
| 836 '''); | 836 '''); |
| 837 return getRefactoringResult(() { | 837 return getRefactoringResult(() { |
| 838 return sendRenameRequest('Test {}', ''); | 838 return sendRenameRequest('Test {}', ''); |
| 839 }).then((result) { | 839 }).then((result) { |
| 840 assertResultProblemsFatal(result, 'Class name must not be empty.'); | 840 assertResultProblemsFatal( |
| 841 result.optionsProblems, |
| 842 'Class name must not be empty.'); |
| 841 // ...there is no any change | 843 // ...there is no any change |
| 842 expect(result.change, isNull); | 844 expect(result.change, isNull); |
| 843 }); | 845 }); |
| 844 } | 846 } |
| 845 | 847 |
| 846 test_class_validateOnly() { | 848 test_class_validateOnly() { |
| 847 addTestFile(''' | 849 addTestFile(''' |
| 848 class Test {} | 850 class Test {} |
| 849 main() { | 851 main() { |
| 850 Test v; | 852 Test v; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 865 addTestFile(''' | 867 addTestFile(''' |
| 866 class Test {} | 868 class Test {} |
| 867 main() { | 869 main() { |
| 868 Test v; | 870 Test v; |
| 869 } | 871 } |
| 870 '''); | 872 '''); |
| 871 return getRefactoringResult(() { | 873 return getRefactoringResult(() { |
| 872 return sendRenameRequest('Test {}', 'newName'); | 874 return sendRenameRequest('Test {}', 'newName'); |
| 873 }).then((result) { | 875 }).then((result) { |
| 874 assertResultProblemsWarning( | 876 assertResultProblemsWarning( |
| 875 result, | 877 result.optionsProblems, |
| 876 'Class name should start with an uppercase letter.'); | 878 'Class name should start with an uppercase letter.'); |
| 877 // ...but there is still a change | 879 // ...but there is still a change |
| 878 assertTestRefactoringResult(result, ''' | 880 assertTestRefactoringResult(result, ''' |
| 879 class newName {} | 881 class newName {} |
| 880 main() { | 882 main() { |
| 881 newName v; | 883 newName v; |
| 882 } | 884 } |
| 883 '''); | 885 '''); |
| 884 }).then((_) { | 886 }).then((_) { |
| 885 // "NewName" is a perfectly valid name | 887 // "NewName" is a perfectly valid name |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 print(newName); | 957 print(newName); |
| 956 } | 958 } |
| 957 '''); | 959 '''); |
| 958 } | 960 } |
| 959 | 961 |
| 960 test_init_fatalError_noElement() { | 962 test_init_fatalError_noElement() { |
| 961 addTestFile('// nothing to rename'); | 963 addTestFile('// nothing to rename'); |
| 962 return getRefactoringResult(() { | 964 return getRefactoringResult(() { |
| 963 return sendRenameRequest('// nothing', null); | 965 return sendRenameRequest('// nothing', null); |
| 964 }).then((result) { | 966 }).then((result) { |
| 965 assertResultProblemsFatal(result, 'Unable to create a refactoring'); | 967 assertResultProblemsFatal( |
| 968 result.initialProblems, |
| 969 'Unable to create a refactoring'); |
| 966 // ...there is no any change | 970 // ...there is no any change |
| 967 expect(result.change, isNull); | 971 expect(result.change, isNull); |
| 968 }); | 972 }); |
| 969 } | 973 } |
| 970 | 974 |
| 971 test_localVariable() { | 975 test_localVariable() { |
| 972 addTestFile(''' | 976 addTestFile(''' |
| 973 main() { | 977 main() { |
| 974 int test = 0; | 978 int test = 0; |
| 975 test = 1; | 979 test = 1; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 993 addTestFile(''' | 997 addTestFile(''' |
| 994 main() { | 998 main() { |
| 995 var newName; | 999 var newName; |
| 996 int test = 0; | 1000 int test = 0; |
| 997 print(test); | 1001 print(test); |
| 998 } | 1002 } |
| 999 '''); | 1003 '''); |
| 1000 return getRefactoringResult(() { | 1004 return getRefactoringResult(() { |
| 1001 return sendRenameRequest('test = 0', 'newName'); | 1005 return sendRenameRequest('test = 0', 'newName'); |
| 1002 }).then((result) { | 1006 }).then((result) { |
| 1003 assertResultProblemsError(result, "Duplicate local variable 'newName'."); | 1007 assertResultProblemsError( |
| 1008 result.finalProblems, |
| 1009 "Duplicate local variable 'newName'."); |
| 1004 }); | 1010 }); |
| 1005 } | 1011 } |
| 1006 } | 1012 } |
| 1007 | 1013 |
| 1008 | 1014 |
| 1009 @ReflectiveTestCase() | 1015 @ReflectiveTestCase() |
| 1010 class _AbstractGetRefactoring_Test extends AbstractAnalysisTest { | 1016 class _AbstractGetRefactoring_Test extends AbstractAnalysisTest { |
| 1011 /** | 1017 /** |
| 1012 * Asserts that [result] has a single ERROR problem. | 1018 * Asserts that [problems] has a single ERROR problem. |
| 1013 */ | 1019 */ |
| 1014 void assertResultProblemsError(EditGetRefactoringResult result, | 1020 void assertResultProblemsError(List<RefactoringProblem> problems, |
| 1015 [String message]) { | 1021 [String message]) { |
| 1016 List<RefactoringProblem> problems = result.problems; | |
| 1017 RefactoringProblem problem = problems[0]; | 1022 RefactoringProblem problem = problems[0]; |
| 1018 expect(problems, hasLength(1)); | 1023 expect(problems, hasLength(1)); |
| 1019 expect( | 1024 expect( |
| 1020 problem.severity, | 1025 problem.severity, |
| 1021 RefactoringProblemSeverity.ERROR, | 1026 RefactoringProblemSeverity.ERROR, |
| 1022 reason: problem.toString()); | 1027 reason: problem.toString()); |
| 1023 if (message != null) { | 1028 if (message != null) { |
| 1024 expect(problem.message, message); | 1029 expect(problem.message, message); |
| 1025 } | 1030 } |
| 1026 } | 1031 } |
| 1027 | 1032 |
| 1028 /** | 1033 /** |
| 1029 * Asserts that [result] has a single FATAL problem. | 1034 * Asserts that [result] has a single FATAL problem. |
| 1030 */ | 1035 */ |
| 1031 void assertResultProblemsFatal(EditGetRefactoringResult result, | 1036 void assertResultProblemsFatal(List<RefactoringProblem> problems, |
| 1032 [String message]) { | 1037 [String message]) { |
| 1033 List<RefactoringProblem> problems = result.problems; | |
| 1034 RefactoringProblem problem = problems[0]; | 1038 RefactoringProblem problem = problems[0]; |
| 1035 expect(problems, hasLength(1)); | 1039 expect(problems, hasLength(1)); |
| 1036 expect( | 1040 expect( |
| 1037 problem.severity, | 1041 problem.severity, |
| 1038 RefactoringProblemSeverity.FATAL, | 1042 RefactoringProblemSeverity.FATAL, |
| 1039 reason: problem.toString()); | 1043 reason: problem.toString()); |
| 1040 if (message != null) { | 1044 if (message != null) { |
| 1041 expect(problem.message, message); | 1045 expect(problem.message, message); |
| 1042 } | 1046 } |
| 1043 } | 1047 } |
| 1044 | 1048 |
| 1045 /** | 1049 /** |
| 1046 * Asserts that [result] has no problems at all. | 1050 * Asserts that [result] has no problems at all. |
| 1047 */ | 1051 */ |
| 1048 void assertResultProblemsOK(EditGetRefactoringResult result) { | 1052 void assertResultProblemsOK(EditGetRefactoringResult result) { |
| 1049 expect(result.problems, isEmpty); | 1053 expect(result.initialProblems, isEmpty); |
| 1054 expect(result.optionsProblems, isEmpty); |
| 1055 expect(result.finalProblems, isEmpty); |
| 1050 } | 1056 } |
| 1051 | 1057 |
| 1052 /** | 1058 /** |
| 1053 * Asserts that [result] has a single WARNING problem. | 1059 * Asserts that [result] has a single WARNING problem. |
| 1054 */ | 1060 */ |
| 1055 void assertResultProblemsWarning(EditGetRefactoringResult result, | 1061 void assertResultProblemsWarning(List<RefactoringProblem> problems, |
| 1056 [String message]) { | 1062 [String message]) { |
| 1057 List<RefactoringProblem> problems = result.problems; | |
| 1058 RefactoringProblem problem = problems[0]; | 1063 RefactoringProblem problem = problems[0]; |
| 1059 expect(problems, hasLength(1)); | 1064 expect(problems, hasLength(1)); |
| 1060 expect( | 1065 expect( |
| 1061 problem.severity, | 1066 problem.severity, |
| 1062 RefactoringProblemSeverity.WARNING, | 1067 RefactoringProblemSeverity.WARNING, |
| 1063 reason: problem.toString()); | 1068 reason: problem.toString()); |
| 1064 if (message != null) { | 1069 if (message != null) { |
| 1065 expect(problem.message, message); | 1070 expect(problem.message, message); |
| 1066 } | 1071 } |
| 1067 } | 1072 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 } | 1124 } |
| 1120 | 1125 |
| 1121 @override | 1126 @override |
| 1122 void setUp() { | 1127 void setUp() { |
| 1123 super.setUp(); | 1128 super.setUp(); |
| 1124 server.handlers = [new EditDomainHandler(server),]; | 1129 server.handlers = [new EditDomainHandler(server),]; |
| 1125 createProject(); | 1130 createProject(); |
| 1126 handler = new EditDomainHandler(server); | 1131 handler = new EditDomainHandler(server); |
| 1127 } | 1132 } |
| 1128 } | 1133 } |
| OLD | NEW |