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/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:analysis_server/src/edit/edit_domain.dart'; | 10 import 'package:analysis_server/src/edit/edit_domain.dart'; |
11 import 'package:analysis_server/src/services/index/index.dart'; | 11 import 'package:analysis_server/src/services/index/index.dart'; |
12 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | |
13 import 'package:plugin/manager.dart'; | 12 import 'package:plugin/manager.dart'; |
14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
15 import 'package:unittest/unittest.dart' hide ERROR; | 14 import 'package:unittest/unittest.dart' hide ERROR; |
16 | 15 |
17 import '../analysis_abstract.dart'; | 16 import '../analysis_abstract.dart'; |
18 import '../mocks.dart'; | 17 import '../mocks.dart'; |
19 import '../utils.dart'; | 18 import '../utils.dart'; |
20 | 19 |
21 main() { | 20 main() { |
22 initializeTestEnvironment(); | 21 initializeTestEnvironment(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 var va = a.test(); | 111 var va = a.test(); |
113 var vb = b.test(); | 112 var vb = b.test(); |
114 var vc = c.test(); | 113 var vc = c.test(); |
115 var vd = d.test(); | 114 var vd = d.test(); |
116 } | 115 } |
117 '''); | 116 '''); |
118 } | 117 } |
119 | 118 |
120 Future<Response> _sendConvertRequest(String search) { | 119 Future<Response> _sendConvertRequest(String search) { |
121 Request request = new EditGetRefactoringParams( | 120 Request request = new EditGetRefactoringParams( |
122 RefactoringKind.CONVERT_GETTER_TO_METHOD, | 121 RefactoringKind.CONVERT_GETTER_TO_METHOD, |
123 testFile, | 122 testFile, |
124 findOffset(search), | 123 findOffset(search), |
125 0, | 124 0, |
126 false).toRequest('0'); | 125 false) |
| 126 .toRequest('0'); |
127 return serverChannel.sendRequest(request); | 127 return serverChannel.sendRequest(request); |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 @reflectiveTest | 131 @reflectiveTest |
132 class ConvertMethodToGetterTest extends _AbstractGetRefactoring_Test { | 132 class ConvertMethodToGetterTest extends _AbstractGetRefactoring_Test { |
133 test_function() { | 133 test_function() { |
134 addTestFile(''' | 134 addTestFile(''' |
135 int test() => 42; | 135 int test() => 42; |
136 main() { | 136 main() { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 var va = a.test; | 225 var va = a.test; |
226 var vb = b.test; | 226 var vb = b.test; |
227 var vc = c.test; | 227 var vc = c.test; |
228 var vd = d.test; | 228 var vd = d.test; |
229 } | 229 } |
230 '''); | 230 '''); |
231 } | 231 } |
232 | 232 |
233 Future<Response> _sendConvertRequest(String search) { | 233 Future<Response> _sendConvertRequest(String search) { |
234 Request request = new EditGetRefactoringParams( | 234 Request request = new EditGetRefactoringParams( |
235 RefactoringKind.CONVERT_METHOD_TO_GETTER, | 235 RefactoringKind.CONVERT_METHOD_TO_GETTER, |
236 testFile, | 236 testFile, |
237 findOffset(search), | 237 findOffset(search), |
238 0, | 238 0, |
239 false).toRequest('0'); | 239 false) |
| 240 .toRequest('0'); |
240 return serverChannel.sendRequest(request); | 241 return serverChannel.sendRequest(request); |
241 } | 242 } |
242 } | 243 } |
243 | 244 |
244 @reflectiveTest | 245 @reflectiveTest |
245 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { | 246 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { |
246 Future<Response> sendExtractRequest( | 247 Future<Response> sendExtractRequest( |
247 int offset, int length, String name, bool extractAll) { | 248 int offset, int length, String name, bool extractAll) { |
248 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE; | 249 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE; |
249 ExtractLocalVariableOptions options = | 250 ExtractLocalVariableOptions options = |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 | 723 |
723 /** | 724 /** |
724 * Tests that there is a RENAME refactoring available at the [search] offset. | 725 * Tests that there is a RENAME refactoring available at the [search] offset. |
725 */ | 726 */ |
726 Future assertHasRenameRefactoring(String code, String search) async { | 727 Future assertHasRenameRefactoring(String code, String search) async { |
727 return assertHasKind(code, search, RefactoringKind.RENAME, true); | 728 return assertHasKind(code, search, RefactoringKind.RENAME, true); |
728 } | 729 } |
729 | 730 |
730 @override | 731 @override |
731 Index createIndex() { | 732 Index createIndex() { |
732 return createLocalMemoryIndex(); | 733 return createMemoryIndex(); |
733 } | 734 } |
734 | 735 |
735 /** | 736 /** |
736 * Returns the list of available refactorings for the given [offset] and | 737 * Returns the list of available refactorings for the given [offset] and |
737 * [length]. | 738 * [length]. |
738 */ | 739 */ |
739 Future getRefactorings(int offset, int length) async { | 740 Future getRefactorings(int offset, int length) async { |
740 Request request = new EditGetAvailableRefactoringsParams( | 741 Request request = |
741 testFile, offset, length).toRequest('0'); | 742 new EditGetAvailableRefactoringsParams(testFile, offset, length) |
| 743 .toRequest('0'); |
742 serverChannel.sendRequest(request); | 744 serverChannel.sendRequest(request); |
743 var response = await serverChannel.waitForResponse(request); | 745 var response = await serverChannel.waitForResponse(request); |
744 var result = new EditGetAvailableRefactoringsResult.fromResponse(response); | 746 var result = new EditGetAvailableRefactoringsResult.fromResponse(response); |
745 kinds = result.kinds; | 747 kinds = result.kinds; |
746 } | 748 } |
747 | 749 |
748 /** | 750 /** |
749 * Returns the list of available refactorings at the offset of [search]. | 751 * Returns the list of available refactorings at the offset of [search]. |
750 */ | 752 */ |
751 Future getRefactoringsAtString(String search) { | 753 Future getRefactoringsAtString(String search) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 ''' | 976 ''' |
975 main() { | 977 main() { |
976 int a = 42 + 2; | 978 int a = 42 + 2; |
977 print(42); | 979 print(42); |
978 } | 980 } |
979 '''); | 981 '''); |
980 } | 982 } |
981 | 983 |
982 Future<Response> _sendInlineRequest(String search) { | 984 Future<Response> _sendInlineRequest(String search) { |
983 Request request = new EditGetRefactoringParams( | 985 Request request = new EditGetRefactoringParams( |
984 RefactoringKind.INLINE_LOCAL_VARIABLE, | 986 RefactoringKind.INLINE_LOCAL_VARIABLE, |
985 testFile, | 987 testFile, |
986 findOffset(search), | 988 findOffset(search), |
987 0, | 989 0, |
988 false).toRequest('0'); | 990 false) |
| 991 .toRequest('0'); |
989 return serverChannel.sendRequest(request); | 992 return serverChannel.sendRequest(request); |
990 } | 993 } |
991 } | 994 } |
992 | 995 |
993 @reflectiveTest | 996 @reflectiveTest |
994 class InlineMethodTest extends _AbstractGetRefactoring_Test { | 997 class InlineMethodTest extends _AbstractGetRefactoring_Test { |
995 InlineMethodOptions options = new InlineMethodOptions(true, true); | 998 InlineMethodOptions options = new InlineMethodOptions(true, true); |
996 | 999 |
997 test_feedback() { | 1000 test_feedback() { |
998 addTestFile(''' | 1001 addTestFile(''' |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 } | 1104 } |
1102 main() { | 1105 main() { |
1103 test(1, 2); | 1106 test(1, 2); |
1104 print(10 + 20); | 1107 print(10 + 20); |
1105 } | 1108 } |
1106 '''); | 1109 '''); |
1107 } | 1110 } |
1108 | 1111 |
1109 Future<Response> _sendInlineRequest(String search) { | 1112 Future<Response> _sendInlineRequest(String search) { |
1110 Request request = new EditGetRefactoringParams( | 1113 Request request = new EditGetRefactoringParams( |
1111 RefactoringKind.INLINE_METHOD, testFile, findOffset(search), 0, false, | 1114 RefactoringKind.INLINE_METHOD, |
1112 options: options).toRequest('0'); | 1115 testFile, |
| 1116 findOffset(search), |
| 1117 0, |
| 1118 false, |
| 1119 options: options) |
| 1120 .toRequest('0'); |
1113 return serverChannel.sendRequest(request); | 1121 return serverChannel.sendRequest(request); |
1114 } | 1122 } |
1115 } | 1123 } |
1116 | 1124 |
1117 @reflectiveTest | 1125 @reflectiveTest |
1118 class MoveFileTest extends _AbstractGetRefactoring_Test { | 1126 class MoveFileTest extends _AbstractGetRefactoring_Test { |
1119 MoveFileOptions options; | 1127 MoveFileOptions options; |
1120 | 1128 |
1121 test_OK() { | 1129 test_OK() { |
1122 resourceProvider.newFile('/project/bin/lib.dart', ''); | 1130 resourceProvider.newFile('/project/bin/lib.dart', ''); |
1123 addTestFile(''' | 1131 addTestFile(''' |
1124 import 'dart:math'; | 1132 import 'dart:math'; |
1125 import 'lib.dart'; | 1133 import 'lib.dart'; |
1126 '''); | 1134 '''); |
1127 _setOptions('/project/test.dart'); | 1135 _setOptions('/project/test.dart'); |
1128 return assertSuccessfulRefactoring(() { | 1136 return assertSuccessfulRefactoring(() { |
1129 return _sendMoveRequest(); | 1137 return _sendMoveRequest(); |
1130 }, | 1138 }, |
1131 ''' | 1139 ''' |
1132 import 'dart:math'; | 1140 import 'dart:math'; |
1133 import 'bin/lib.dart'; | 1141 import 'bin/lib.dart'; |
1134 '''); | 1142 '''); |
1135 } | 1143 } |
1136 | 1144 |
1137 Future<Response> _sendMoveRequest() { | 1145 Future<Response> _sendMoveRequest() { |
1138 Request request = new EditGetRefactoringParams( | 1146 Request request = new EditGetRefactoringParams( |
1139 RefactoringKind.MOVE_FILE, testFile, 0, 0, false, | 1147 RefactoringKind.MOVE_FILE, testFile, 0, 0, false, |
1140 options: options).toRequest('0'); | 1148 options: options) |
| 1149 .toRequest('0'); |
1141 return serverChannel.sendRequest(request); | 1150 return serverChannel.sendRequest(request); |
1142 } | 1151 } |
1143 | 1152 |
1144 void _setOptions(String newFile) { | 1153 void _setOptions(String newFile) { |
1145 options = new MoveFileOptions(newFile); | 1154 options = new MoveFileOptions(newFile); |
1146 } | 1155 } |
1147 } | 1156 } |
1148 | 1157 |
1149 @reflectiveTest | 1158 @reflectiveTest |
1150 class RenameTest extends _AbstractGetRefactoring_Test { | 1159 class RenameTest extends _AbstractGetRefactoring_Test { |
1151 Future<Response> sendRenameRequest(String search, String newName, | 1160 Future<Response> sendRenameRequest(String search, String newName, |
1152 {String id: '0', bool validateOnly: false}) { | 1161 {String id: '0', bool validateOnly: false}) { |
1153 RenameOptions options = newName != null ? new RenameOptions(newName) : null; | 1162 RenameOptions options = newName != null ? new RenameOptions(newName) : null; |
1154 Request request = new EditGetRefactoringParams( | 1163 Request request = new EditGetRefactoringParams(RefactoringKind.RENAME, |
1155 RefactoringKind.RENAME, testFile, findOffset(search), 0, validateOnly, | 1164 testFile, findOffset(search), 0, validateOnly, |
1156 options: options).toRequest(id); | 1165 options: options) |
| 1166 .toRequest(id); |
1157 return serverChannel.sendRequest(request); | 1167 return serverChannel.sendRequest(request); |
1158 } | 1168 } |
1159 | 1169 |
1160 test_cancelPendingRequest() async { | 1170 test_cancelPendingRequest() async { |
1161 addTestFile(''' | 1171 addTestFile(''' |
1162 main() { | 1172 main() { |
1163 int test = 0; | 1173 int test = 0; |
1164 print(test); | 1174 print(test); |
1165 } | 1175 } |
1166 '''); | 1176 '''); |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 String actualCode = SourceEdit.applySequence(testCode, fileEdit.edits); | 1856 String actualCode = SourceEdit.applySequence(testCode, fileEdit.edits); |
1847 expect(actualCode, expectedCode); | 1857 expect(actualCode, expectedCode); |
1848 return; | 1858 return; |
1849 } | 1859 } |
1850 } | 1860 } |
1851 fail('No SourceFileEdit for $testFile in $change'); | 1861 fail('No SourceFileEdit for $testFile in $change'); |
1852 } | 1862 } |
1853 | 1863 |
1854 @override | 1864 @override |
1855 Index createIndex() { | 1865 Index createIndex() { |
1856 return createLocalMemoryIndex(); | 1866 return createMemoryIndex(); |
1857 } | 1867 } |
1858 | 1868 |
1859 Future<EditGetRefactoringResult> getRefactoringResult( | 1869 Future<EditGetRefactoringResult> getRefactoringResult( |
1860 Future<Response> requestSender()) { | 1870 Future<Response> requestSender()) { |
1861 return waitForTasksFinished().then((_) { | 1871 return waitForTasksFinished().then((_) { |
1862 return requestSender().then((Response response) { | 1872 return requestSender().then((Response response) { |
1863 return new EditGetRefactoringResult.fromResponse(response); | 1873 return new EditGetRefactoringResult.fromResponse(response); |
1864 }); | 1874 }); |
1865 }); | 1875 }); |
1866 } | 1876 } |
1867 | 1877 |
1868 Future<Response> sendRequest( | 1878 Future<Response> sendRequest( |
1869 RefactoringKind kind, int offset, int length, RefactoringOptions options, | 1879 RefactoringKind kind, int offset, int length, RefactoringOptions options, |
1870 [bool validateOnly = false]) { | 1880 [bool validateOnly = false]) { |
1871 Request request = new EditGetRefactoringParams( | 1881 Request request = new EditGetRefactoringParams( |
1872 kind, testFile, offset, length, validateOnly, | 1882 kind, testFile, offset, length, validateOnly, |
1873 options: options).toRequest('0'); | 1883 options: options) |
| 1884 .toRequest('0'); |
1874 return serverChannel.sendRequest(request); | 1885 return serverChannel.sendRequest(request); |
1875 } | 1886 } |
1876 | 1887 |
1877 @override | 1888 @override |
1878 void setUp() { | 1889 void setUp() { |
1879 super.setUp(); | 1890 super.setUp(); |
1880 createProject(); | 1891 createProject(); |
1881 ExtensionManager manager = new ExtensionManager(); | 1892 ExtensionManager manager = new ExtensionManager(); |
1882 manager.processPlugins([server.serverPlugin]); | 1893 manager.processPlugins([server.serverPlugin]); |
1883 handler = new EditDomainHandler(server); | 1894 handler = new EditDomainHandler(server); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 .toRequest('0'); | 1927 .toRequest('0'); |
1917 return _assertErrorResponseNoIndex(request); | 1928 return _assertErrorResponseNoIndex(request); |
1918 } | 1929 } |
1919 | 1930 |
1920 _assertErrorResponseNoIndex(Request request) async { | 1931 _assertErrorResponseNoIndex(Request request) async { |
1921 Response response = await serverChannel.sendRequest(request); | 1932 Response response = await serverChannel.sendRequest(request); |
1922 expect(response.error, isNotNull); | 1933 expect(response.error, isNotNull); |
1923 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); | 1934 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); |
1924 } | 1935 } |
1925 } | 1936 } |
OLD | NEW |