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 12 matching lines...) Expand all Loading... |
23 runReflectiveTests(ExtractLocalVariableTest); | 23 runReflectiveTests(ExtractLocalVariableTest); |
24 runReflectiveTests(ExtractMethodTest); | 24 runReflectiveTests(ExtractMethodTest); |
25 runReflectiveTests(GetAvailableRefactoringsTest); | 25 runReflectiveTests(GetAvailableRefactoringsTest); |
26 runReflectiveTests(InlineLocalTest); | 26 runReflectiveTests(InlineLocalTest); |
27 runReflectiveTests(InlineMethodTest); | 27 runReflectiveTests(InlineMethodTest); |
28 runReflectiveTests(MoveFileTest); | 28 runReflectiveTests(MoveFileTest); |
29 runReflectiveTests(RenameTest); | 29 runReflectiveTests(RenameTest); |
30 } | 30 } |
31 | 31 |
32 | 32 |
33 @ReflectiveTestCase() | 33 @reflectiveTest |
34 class ConvertGetterMethodToMethodTest extends _AbstractGetRefactoring_Test { | 34 class ConvertGetterMethodToMethodTest extends _AbstractGetRefactoring_Test { |
35 test_function() { | 35 test_function() { |
36 addTestFile(''' | 36 addTestFile(''' |
37 int get test => 42; | 37 int get test => 42; |
38 main() { | 38 main() { |
39 var a = 1 + test; | 39 var a = 1 + test; |
40 var b = 2 + test; | 40 var b = 2 + test; |
41 } | 41 } |
42 '''); | 42 '''); |
43 return assertSuccessfulRefactoring(() { | 43 return assertSuccessfulRefactoring(() { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 RefactoringKind.CONVERT_GETTER_TO_METHOD, | 119 RefactoringKind.CONVERT_GETTER_TO_METHOD, |
120 testFile, | 120 testFile, |
121 findOffset(search), | 121 findOffset(search), |
122 0, | 122 0, |
123 false).toRequest('0'); | 123 false).toRequest('0'); |
124 return serverChannel.sendRequest(request); | 124 return serverChannel.sendRequest(request); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 | 128 |
129 @ReflectiveTestCase() | 129 @reflectiveTest |
130 class ConvertMethodToGetterTest extends _AbstractGetRefactoring_Test { | 130 class ConvertMethodToGetterTest extends _AbstractGetRefactoring_Test { |
131 test_function() { | 131 test_function() { |
132 addTestFile(''' | 132 addTestFile(''' |
133 int test() => 42; | 133 int test() => 42; |
134 main() { | 134 main() { |
135 var a = 1 + test(); | 135 var a = 1 + test(); |
136 var b = 2 + test(); | 136 var b = 2 + test(); |
137 } | 137 } |
138 '''); | 138 '''); |
139 return assertSuccessfulRefactoring(() { | 139 return assertSuccessfulRefactoring(() { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 RefactoringKind.CONVERT_METHOD_TO_GETTER, | 233 RefactoringKind.CONVERT_METHOD_TO_GETTER, |
234 testFile, | 234 testFile, |
235 findOffset(search), | 235 findOffset(search), |
236 0, | 236 0, |
237 false).toRequest('0'); | 237 false).toRequest('0'); |
238 return serverChannel.sendRequest(request); | 238 return serverChannel.sendRequest(request); |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 | 242 |
243 @ReflectiveTestCase() | 243 @reflectiveTest |
244 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { | 244 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { |
245 Future<Response> sendExtractRequest(int offset, int length, String name, | 245 Future<Response> sendExtractRequest(int offset, int length, String name, |
246 bool extractAll) { | 246 bool extractAll) { |
247 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE; | 247 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE; |
248 ExtractLocalVariableOptions options = | 248 ExtractLocalVariableOptions options = |
249 name != null ? new ExtractLocalVariableOptions(name, extractAll) : null; | 249 name != null ? new ExtractLocalVariableOptions(name, extractAll) : null; |
250 return sendRequest(kind, offset, length, options, false); | 250 return sendRequest(kind, offset, length, options, false); |
251 } | 251 } |
252 | 252 |
253 Future<Response> sendStringRequest(String search, String name, | 253 Future<Response> sendStringRequest(String search, String name, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 return waitForTasksFinished().then((_) { | 404 return waitForTasksFinished().then((_) { |
405 return sendStringRequest('1 + 2', 'res', true).then((response) { | 405 return sendStringRequest('1 + 2', 'res', true).then((response) { |
406 expect(response.error, isNotNull); | 406 expect(response.error, isNotNull); |
407 expect(response.error.code, RequestErrorCode.SERVER_ERROR); | 407 expect(response.error.code, RequestErrorCode.SERVER_ERROR); |
408 }); | 408 }); |
409 }); | 409 }); |
410 } | 410 } |
411 } | 411 } |
412 | 412 |
413 | 413 |
414 @ReflectiveTestCase() | 414 @reflectiveTest |
415 class ExtractMethodTest extends _AbstractGetRefactoring_Test { | 415 class ExtractMethodTest extends _AbstractGetRefactoring_Test { |
416 int offset; | 416 int offset; |
417 int length; | 417 int length; |
418 String name = 'res'; | 418 String name = 'res'; |
419 ExtractMethodOptions options; | 419 ExtractMethodOptions options; |
420 | 420 |
421 test_expression() { | 421 test_expression() { |
422 addTestFile(''' | 422 addTestFile(''' |
423 main() { | 423 main() { |
424 print(1 + 2); | 424 print(1 + 2); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 length = findOffset('// end') - offset; | 617 length = findOffset('// end') - offset; |
618 } | 618 } |
619 | 619 |
620 void _setOffsetLengthForString(String search) { | 620 void _setOffsetLengthForString(String search) { |
621 offset = findOffset(search); | 621 offset = findOffset(search); |
622 length = search.length; | 622 length = search.length; |
623 } | 623 } |
624 } | 624 } |
625 | 625 |
626 | 626 |
627 @ReflectiveTestCase() | 627 @reflectiveTest |
628 class GetAvailableRefactoringsTest extends AbstractAnalysisTest { | 628 class GetAvailableRefactoringsTest extends AbstractAnalysisTest { |
629 /** | 629 /** |
630 * Tests that there is a RENAME refactoring available at the [search] offset. | 630 * Tests that there is a RENAME refactoring available at the [search] offset. |
631 */ | 631 */ |
632 Future assertHasRenameRefactoring(String code, String search) { | 632 Future assertHasRenameRefactoring(String code, String search) { |
633 addTestFile(code); | 633 addTestFile(code); |
634 return waitForTasksFinished().then((_) { | 634 return waitForTasksFinished().then((_) { |
635 List<RefactoringKind> kinds = getRefactoringsAtString(search); | 635 List<RefactoringKind> kinds = getRefactoringsAtString(search); |
636 expect(kinds, contains(RefactoringKind.RENAME)); | 636 expect(kinds, contains(RefactoringKind.RENAME)); |
637 }); | 637 }); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 '''); | 798 '''); |
799 return waitForTasksFinished().then((_) { | 799 return waitForTasksFinished().then((_) { |
800 List<RefactoringKind> kinds = | 800 List<RefactoringKind> kinds = |
801 getRefactoringsAtString('// not an element'); | 801 getRefactoringsAtString('// not an element'); |
802 expect(kinds, isNot(contains(RefactoringKind.RENAME))); | 802 expect(kinds, isNot(contains(RefactoringKind.RENAME))); |
803 }); | 803 }); |
804 } | 804 } |
805 } | 805 } |
806 | 806 |
807 | 807 |
808 @ReflectiveTestCase() | 808 @reflectiveTest |
809 class InlineLocalTest extends _AbstractGetRefactoring_Test { | 809 class InlineLocalTest extends _AbstractGetRefactoring_Test { |
810 test_feedback() { | 810 test_feedback() { |
811 addTestFile(''' | 811 addTestFile(''' |
812 main() { | 812 main() { |
813 int test = 42; | 813 int test = 42; |
814 print(test); | 814 print(test); |
815 print(test); | 815 print(test); |
816 } | 816 } |
817 '''); | 817 '''); |
818 return getRefactoringResult(() { | 818 return getRefactoringResult(() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 RefactoringKind.INLINE_LOCAL_VARIABLE, | 860 RefactoringKind.INLINE_LOCAL_VARIABLE, |
861 testFile, | 861 testFile, |
862 findOffset(search), | 862 findOffset(search), |
863 0, | 863 0, |
864 false).toRequest('0'); | 864 false).toRequest('0'); |
865 return serverChannel.sendRequest(request); | 865 return serverChannel.sendRequest(request); |
866 } | 866 } |
867 } | 867 } |
868 | 868 |
869 | 869 |
870 @ReflectiveTestCase() | 870 @reflectiveTest |
871 class InlineMethodTest extends _AbstractGetRefactoring_Test { | 871 class InlineMethodTest extends _AbstractGetRefactoring_Test { |
872 InlineMethodOptions options = new InlineMethodOptions(true, true); | 872 InlineMethodOptions options = new InlineMethodOptions(true, true); |
873 | 873 |
874 test_feedback() { | 874 test_feedback() { |
875 addTestFile(''' | 875 addTestFile(''' |
876 class A { | 876 class A { |
877 int f; | 877 int f; |
878 test(int p) { | 878 test(int p) { |
879 print(f + p); | 879 print(f + p); |
880 } | 880 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 testFile, | 987 testFile, |
988 findOffset(search), | 988 findOffset(search), |
989 0, | 989 0, |
990 false, | 990 false, |
991 options: options).toRequest('0'); | 991 options: options).toRequest('0'); |
992 return serverChannel.sendRequest(request); | 992 return serverChannel.sendRequest(request); |
993 } | 993 } |
994 } | 994 } |
995 | 995 |
996 | 996 |
997 @ReflectiveTestCase() | 997 @reflectiveTest |
998 class MoveFileTest extends _AbstractGetRefactoring_Test { | 998 class MoveFileTest extends _AbstractGetRefactoring_Test { |
999 MoveFileOptions options = new MoveFileOptions(null); | 999 MoveFileOptions options = new MoveFileOptions(null); |
1000 | 1000 |
1001 test_OK() { | 1001 test_OK() { |
1002 resourceProvider.newFile('/project/bin/lib.dart', ''); | 1002 resourceProvider.newFile('/project/bin/lib.dart', ''); |
1003 addTestFile(''' | 1003 addTestFile(''' |
1004 import 'dart:math'; | 1004 import 'dart:math'; |
1005 import 'lib.dart'; | 1005 import 'lib.dart'; |
1006 '''); | 1006 '''); |
1007 options.newFile = '/project/test.dart'; | 1007 options.newFile = '/project/test.dart'; |
(...skipping 11 matching lines...) Expand all Loading... |
1019 testFile, | 1019 testFile, |
1020 0, | 1020 0, |
1021 0, | 1021 0, |
1022 false, | 1022 false, |
1023 options: options).toRequest('0'); | 1023 options: options).toRequest('0'); |
1024 return serverChannel.sendRequest(request); | 1024 return serverChannel.sendRequest(request); |
1025 } | 1025 } |
1026 } | 1026 } |
1027 | 1027 |
1028 | 1028 |
1029 @ReflectiveTestCase() | 1029 @reflectiveTest |
1030 class RenameTest extends _AbstractGetRefactoring_Test { | 1030 class RenameTest extends _AbstractGetRefactoring_Test { |
1031 Future<Response> sendRenameRequest(String search, String newName, | 1031 Future<Response> sendRenameRequest(String search, String newName, |
1032 [bool validateOnly = false]) { | 1032 [bool validateOnly = false]) { |
1033 RenameOptions options = newName != null ? new RenameOptions(newName) : null; | 1033 RenameOptions options = newName != null ? new RenameOptions(newName) : null; |
1034 Request request = new EditGetRefactoringParams( | 1034 Request request = new EditGetRefactoringParams( |
1035 RefactoringKind.RENAME, | 1035 RefactoringKind.RENAME, |
1036 testFile, | 1036 testFile, |
1037 findOffset(search), | 1037 findOffset(search), |
1038 0, | 1038 0, |
1039 validateOnly, | 1039 validateOnly, |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 if (edit.id == id) { | 1573 if (edit.id == id) { |
1574 potentialEdit = edit; | 1574 potentialEdit = edit; |
1575 } | 1575 } |
1576 }); | 1576 }); |
1577 }); | 1577 }); |
1578 return potentialEdit; | 1578 return potentialEdit; |
1579 } | 1579 } |
1580 } | 1580 } |
1581 | 1581 |
1582 | 1582 |
1583 @ReflectiveTestCase() | 1583 @reflectiveTest |
1584 class _AbstractGetRefactoring_Test extends AbstractAnalysisTest { | 1584 class _AbstractGetRefactoring_Test extends AbstractAnalysisTest { |
1585 /** | 1585 /** |
1586 * Asserts that [problems] has a single ERROR problem. | 1586 * Asserts that [problems] has a single ERROR problem. |
1587 */ | 1587 */ |
1588 void assertResultProblemsError(List<RefactoringProblem> problems, | 1588 void assertResultProblemsError(List<RefactoringProblem> problems, |
1589 [String message]) { | 1589 [String message]) { |
1590 RefactoringProblem problem = problems[0]; | 1590 RefactoringProblem problem = problems[0]; |
1591 expect( | 1591 expect( |
1592 problem.severity, | 1592 problem.severity, |
1593 RefactoringProblemSeverity.ERROR, | 1593 RefactoringProblemSeverity.ERROR, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 } | 1691 } |
1692 | 1692 |
1693 @override | 1693 @override |
1694 void setUp() { | 1694 void setUp() { |
1695 super.setUp(); | 1695 super.setUp(); |
1696 server.handlers = [new EditDomainHandler(server),]; | 1696 server.handlers = [new EditDomainHandler(server),]; |
1697 createProject(); | 1697 createProject(); |
1698 handler = new EditDomainHandler(server); | 1698 handler = new EditDomainHandler(server); |
1699 } | 1699 } |
1700 } | 1700 } |
OLD | NEW |