| 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'; |
| 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'; | 12 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
| 13 import 'package:analysis_server/src/services/json.dart'; | 13 import 'package:analysis_server/src/services/json.dart'; |
| 14 import '../reflective_tests.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'; |
| 17 import '../reflective_tests.dart'; |
| 18 | 18 |
| 19 | 19 |
| 20 main() { | 20 main() { |
| 21 groupSep = ' | '; | 21 groupSep = ' | '; |
| 22 runReflectiveTests(ExtractLocalVariableTest); | 22 runReflectiveTests(ExtractLocalVariableTest); |
| 23 runReflectiveTests(ExtractMethodTest); | 23 runReflectiveTests(ExtractMethodTest); |
| 24 runReflectiveTests(InlineLocalTest); |
| 24 runReflectiveTests(InlineMethodTest); | 25 runReflectiveTests(InlineMethodTest); |
| 25 runReflectiveTests(GetAvailableRefactoringsTest); | 26 runReflectiveTests(GetAvailableRefactoringsTest); |
| 26 runReflectiveTests(RenameTest); | 27 runReflectiveTests(RenameTest); |
| 27 } | 28 } |
| 28 | 29 |
| 29 | 30 |
| 30 @ReflectiveTestCase() | 31 @ReflectiveTestCase() |
| 31 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { | 32 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { |
| 32 Future<Response> sendExtractRequest(int offset, int length, String name, | 33 Future<Response> sendExtractRequest(int offset, int length, String name, |
| 33 bool extractAll) { | 34 bool extractAll) { |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 return waitForTasksFinished().then((_) { | 516 return waitForTasksFinished().then((_) { |
| 516 List<RefactoringKind> kinds = | 517 List<RefactoringKind> kinds = |
| 517 getRefactoringsAtString('// not an element'); | 518 getRefactoringsAtString('// not an element'); |
| 518 expect(kinds, isNot(contains(RefactoringKind.RENAME))); | 519 expect(kinds, isNot(contains(RefactoringKind.RENAME))); |
| 519 }); | 520 }); |
| 520 } | 521 } |
| 521 } | 522 } |
| 522 | 523 |
| 523 | 524 |
| 524 @ReflectiveTestCase() | 525 @ReflectiveTestCase() |
| 526 class InlineLocalTest extends _AbstractGetRefactoring_Test { |
| 527 test_OK() { |
| 528 addTestFile(''' |
| 529 main() { |
| 530 int test = 42; |
| 531 int a = test + 2; |
| 532 print(test); |
| 533 } |
| 534 '''); |
| 535 return assertSuccessfulRefactoring(() { |
| 536 return _sendInlineRequest('test + 2'); |
| 537 }, ''' |
| 538 main() { |
| 539 int a = 42 + 2; |
| 540 print(42); |
| 541 } |
| 542 '''); |
| 543 } |
| 544 |
| 545 test_init_fatalError_notVariable() { |
| 546 addTestFile('main() {}'); |
| 547 return getRefactoringResult(() { |
| 548 return _sendInlineRequest('main() {}'); |
| 549 }).then((result) { |
| 550 assertResultProblemsFatal( |
| 551 result, |
| 552 'Local variable declaration or reference must be selected to activate
this refactoring.'); |
| 553 // ...there is no any change |
| 554 expect(result.change, isNull); |
| 555 }); |
| 556 } |
| 557 |
| 558 Future<Response> _sendInlineRequest(String search) { |
| 559 Request request = new EditGetRefactoringParams( |
| 560 RefactoringKind.INLINE_LOCAL_VARIABLE, |
| 561 testFile, |
| 562 findOffset(search), |
| 563 0, |
| 564 false).toRequest('0'); |
| 565 return serverChannel.sendRequest(request); |
| 566 } |
| 567 } |
| 568 |
| 569 |
| 570 @ReflectiveTestCase() |
| 525 class InlineMethodTest extends _AbstractGetRefactoring_Test { | 571 class InlineMethodTest extends _AbstractGetRefactoring_Test { |
| 526 InlineMethodOptions options = new InlineMethodOptions(true, true); | 572 InlineMethodOptions options = new InlineMethodOptions(true, true); |
| 527 | 573 |
| 528 test_init_fatalError_noMethod() { | 574 test_init_fatalError_noMethod() { |
| 529 addTestFile('// nothing to inline'); | 575 addTestFile('// nothing to inline'); |
| 530 return getRefactoringResult(() { | 576 return getRefactoringResult(() { |
| 531 return _sendInlineRequest('// nothing'); | 577 return _sendInlineRequest('// nothing'); |
| 532 }).then((result) { | 578 }).then((result) { |
| 533 assertResultProblemsFatal( | 579 assertResultProblemsFatal( |
| 534 result, | 580 result, |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 } | 1057 } |
| 1012 | 1058 |
| 1013 @override | 1059 @override |
| 1014 void setUp() { | 1060 void setUp() { |
| 1015 super.setUp(); | 1061 super.setUp(); |
| 1016 server.handlers = [new EditDomainHandler(server),]; | 1062 server.handlers = [new EditDomainHandler(server),]; |
| 1017 createProject(); | 1063 createProject(); |
| 1018 handler = new EditDomainHandler(server); | 1064 handler = new EditDomainHandler(server); |
| 1019 } | 1065 } |
| 1020 } | 1066 } |
| OLD | NEW |