| 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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 0, | 1022 0, |
| 1023 false, | 1023 false, |
| 1024 options: options).toRequest('0'); | 1024 options: options).toRequest('0'); |
| 1025 return serverChannel.sendRequest(request); | 1025 return serverChannel.sendRequest(request); |
| 1026 } | 1026 } |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 | 1029 |
| 1030 @reflectiveTest | 1030 @reflectiveTest |
| 1031 class RenameTest extends _AbstractGetRefactoring_Test { | 1031 class RenameTest extends _AbstractGetRefactoring_Test { |
| 1032 Future<Response> sendRenameRequest(String search, String newName, | 1032 Future<Response> sendRenameRequest(String search, String newName, {String id: |
| 1033 {String id: '0', bool validateOnly: false}) { | 1033 '0', bool validateOnly: false}) { |
| 1034 RenameOptions options = newName != null ? new RenameOptions(newName) : null; | 1034 RenameOptions options = newName != null ? new RenameOptions(newName) : null; |
| 1035 Request request = new EditGetRefactoringParams( | 1035 Request request = new EditGetRefactoringParams( |
| 1036 RefactoringKind.RENAME, | 1036 RefactoringKind.RENAME, |
| 1037 testFile, | 1037 testFile, |
| 1038 findOffset(search), | 1038 findOffset(search), |
| 1039 0, | 1039 0, |
| 1040 validateOnly, | 1040 validateOnly, |
| 1041 options: options).toRequest(id); | 1041 options: options).toRequest(id); |
| 1042 return serverChannel.sendRequest(request); | 1042 return serverChannel.sendRequest(request); |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 test_cancelPendingRequest() async { | 1045 test_cancelPendingRequest() async { |
| 1046 addTestFile(''' | 1046 addTestFile(''' |
| 1047 main() { | 1047 main() { |
| 1048 int test = 0; | 1048 int test = 0; |
| 1049 print(test); | 1049 print(test); |
| 1050 } | 1050 } |
| 1051 '''); | 1051 '''); |
| 1052 // send the "1" request, but don't wait for it | 1052 // send the "1" request, but don't wait for it |
| 1053 Future<Response> futureA = sendRenameRequest('test =', 'nameA', id: '1'); | 1053 Future<Response> futureA = sendRenameRequest('test =', 'nameA', id: '1'); |
| 1054 // send the "2" request and wait for it | 1054 // send the "2" request and wait for it |
| 1055 Response responseB = await sendRenameRequest('test =', 'nameB', id: '2'); | 1055 Response responseB = await sendRenameRequest('test =', 'nameB', id: '2'); |
| 1056 // wait for the (delayed) "1" response | 1056 // wait for the (delayed) "1" response |
| 1057 Response responseA = await futureA; | 1057 Response responseA = await futureA; |
| 1058 // "1" was cancelled | 1058 // "1" was cancelled |
| 1059 // "2" is successful | 1059 // "2" is successful |
| 1060 expect(responseA, isResponseFailure('1', RequestErrorCode.REFACTORING_REQUES
T_CANCELLED)); | 1060 expect( |
| 1061 responseA, |
| 1062 isResponseFailure('1', RequestErrorCode.REFACTORING_REQUEST_CANCELLED)); |
| 1061 expect(responseB, isResponseSuccess('2')); | 1063 expect(responseB, isResponseSuccess('2')); |
| 1062 } | 1064 } |
| 1063 | 1065 |
| 1064 test_class() { | 1066 test_class() { |
| 1065 addTestFile(''' | 1067 addTestFile(''' |
| 1066 class Test { | 1068 class Test { |
| 1067 Test() {} | 1069 Test() {} |
| 1068 Test.named() {} | 1070 Test.named() {} |
| 1069 } | 1071 } |
| 1070 main() { | 1072 main() { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 }, ''' | 1321 }, ''' |
| 1320 class A { | 1322 class A { |
| 1321 set newName(x) {} | 1323 set newName(x) {} |
| 1322 main() { | 1324 main() { |
| 1323 newName = 0; | 1325 newName = 0; |
| 1324 } | 1326 } |
| 1325 } | 1327 } |
| 1326 '''); | 1328 '''); |
| 1327 } | 1329 } |
| 1328 | 1330 |
| 1331 test_constructor_fromFactoryRedirectingConstructor_onClassName() { |
| 1332 addTestFile(''' |
| 1333 class A { |
| 1334 A() = B; |
| 1335 } |
| 1336 class B { |
| 1337 B() {} |
| 1338 } |
| 1339 '''); |
| 1340 return assertSuccessfulRefactoring(() { |
| 1341 return sendRenameRequest('B;', 'newName'); |
| 1342 }, ''' |
| 1343 class A { |
| 1344 A() = B.newName; |
| 1345 } |
| 1346 class B { |
| 1347 B.newName() {} |
| 1348 } |
| 1349 '''); |
| 1350 } |
| 1351 |
| 1329 test_constructor_fromInstanceCreation() { | 1352 test_constructor_fromInstanceCreation() { |
| 1330 addTestFile(''' | 1353 addTestFile(''' |
| 1331 class A { | 1354 class A { |
| 1332 A.test() {} | 1355 A.test() {} |
| 1333 } | 1356 } |
| 1334 main() { | 1357 main() { |
| 1335 new A.test(); | 1358 new A.test(); |
| 1336 } | 1359 } |
| 1337 '''); | 1360 '''); |
| 1338 return assertSuccessfulRefactoring(() { | 1361 return assertSuccessfulRefactoring(() { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 // update the file | 1592 // update the file |
| 1570 modifyTestFile(''' | 1593 modifyTestFile(''' |
| 1571 main() { | 1594 main() { |
| 1572 int otherName = 0; | 1595 int otherName = 0; |
| 1573 print(otherName); | 1596 print(otherName); |
| 1574 } | 1597 } |
| 1575 '''); | 1598 '''); |
| 1576 // send the second request, with the same kind, file and offset | 1599 // send the second request, with the same kind, file and offset |
| 1577 return waitForTasksFinished().then((_) { | 1600 return waitForTasksFinished().then((_) { |
| 1578 return getRefactoringResult(() { | 1601 return getRefactoringResult(() { |
| 1579 return sendRenameRequest('otherName =', 'newName', validateOnly: true)
; | 1602 return sendRenameRequest( |
| 1603 'otherName =', |
| 1604 'newName', |
| 1605 validateOnly: true); |
| 1580 }).then((result) { | 1606 }).then((result) { |
| 1581 RenameFeedback feedback = result.feedback; | 1607 RenameFeedback feedback = result.feedback; |
| 1582 // the refactoring was reset, so we don't get a stale result | 1608 // the refactoring was reset, so we don't get a stale result |
| 1583 expect(feedback.oldName, 'otherName'); | 1609 expect(feedback.oldName, 'otherName'); |
| 1584 }); | 1610 }); |
| 1585 }); | 1611 }); |
| 1586 }); | 1612 }); |
| 1587 } | 1613 } |
| 1588 | 1614 |
| 1589 SourceEdit _findEditWithId(SourceChange change, String id) { | 1615 SourceEdit _findEditWithId(SourceChange change, String id) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 } | 1737 } |
| 1712 | 1738 |
| 1713 @override | 1739 @override |
| 1714 void setUp() { | 1740 void setUp() { |
| 1715 super.setUp(); | 1741 super.setUp(); |
| 1716 server.handlers = [new EditDomainHandler(server),]; | 1742 server.handlers = [new EditDomainHandler(server),]; |
| 1717 createProject(); | 1743 createProject(); |
| 1718 handler = new EditDomainHandler(server); | 1744 handler = new EditDomainHandler(server); |
| 1719 } | 1745 } |
| 1720 } | 1746 } |
| OLD | NEW |