Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: pkg/analysis_server/test/edit/refactoring_test.dart

Issue 538583002: Integrate INLINE_METHOD into the server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/edit/edit_domain.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'package:analysis_testing/reflective_tests.dart'; 14 import 'package:analysis_testing/reflective_tests.dart';
15 import 'package:unittest/unittest.dart' hide ERROR; 15 import 'package:unittest/unittest.dart' hide ERROR;
16 16
17 import '../analysis_abstract.dart'; 17 import '../analysis_abstract.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(InlineMethodTest);
24 runReflectiveTests(GetAvailableRefactoringsTest); 25 runReflectiveTests(GetAvailableRefactoringsTest);
25 runReflectiveTests(RenameTest); 26 runReflectiveTests(RenameTest);
26 } 27 }
27 28
28 29
29 @ReflectiveTestCase() 30 @ReflectiveTestCase()
30 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { 31 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test {
31 Future<Response> sendExtractRequest(int offset, int length, String name, 32 Future<Response> sendExtractRequest(int offset, int length, String name,
32 bool extractAll) { 33 bool extractAll) {
33 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE; 34 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE;
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 return waitForTasksFinished().then((_) { 515 return waitForTasksFinished().then((_) {
515 List<RefactoringKind> kinds = 516 List<RefactoringKind> kinds =
516 getRefactoringsAtString('// not an element'); 517 getRefactoringsAtString('// not an element');
517 expect(kinds, isNot(contains(RefactoringKind.RENAME))); 518 expect(kinds, isNot(contains(RefactoringKind.RENAME)));
518 }); 519 });
519 } 520 }
520 } 521 }
521 522
522 523
523 @ReflectiveTestCase() 524 @ReflectiveTestCase()
525 class InlineMethodTest extends _AbstractGetRefactoring_Test {
526 InlineMethodOptions options = new InlineMethodOptions(true, true);
527
528 test_init_fatalError_noMethod() {
529 addTestFile('// nothing to inline');
530 return getRefactoringResult(() {
531 return _sendInlineRequest('// nothing');
532 }).then((result) {
533 assertResultProblemsFatal(
534 result,
535 'Method declaration or reference must be selected to activate this ref actoring.');
536 // ...there is no any change
537 expect(result.change, isNull);
538 });
539 }
540
541 test_method() {
542 addTestFile('''
543 class A {
544 int f;
545 test(int p) {
546 print(f + p);
547 }
548 main() {
549 test(1);
550 }
551 }
552 main(A a) {
553 a.test(2);
554 }
555 ''');
556 return assertSuccessfulRefactoring(() {
557 return _sendInlineRequest('test(int p)');
558 }, '''
559 class A {
560 int f;
561 main() {
562 print(f + 1);
563 }
564 }
565 main(A a) {
566 print(a.f + 2);
567 }
568 ''');
569 }
570
571 test_topLevelFunction() {
572 addTestFile('''
573 test(a, b) {
574 print(a + b);
575 }
576 main() {
577 test(1, 2);
578 test(10, 20);
579 }
580 ''');
581 return assertSuccessfulRefactoring(() {
582 return _sendInlineRequest('test(a');
583 }, '''
584 main() {
585 print(1 + 2);
586 print(10 + 20);
587 }
588 ''');
589 }
590
591 test_topLevelFunction_oneInvocation() {
592 addTestFile('''
593 test(a, b) {
594 print(a + b);
595 }
596 main() {
597 test(1, 2);
598 test(10, 20);
599 }
600 ''');
601 options.deleteSource = false;
602 options.inlineAll = false;
603 return assertSuccessfulRefactoring(() {
604 return _sendInlineRequest('test(10,');
605 }, '''
606 test(a, b) {
607 print(a + b);
608 }
609 main() {
610 test(1, 2);
611 print(10 + 20);
612 }
613 ''');
614 }
615
616 Future<Response> _sendInlineRequest(String search) {
617 Request request = new EditGetRefactoringParams(
618 RefactoringKind.INLINE_METHOD,
619 testFile,
620 findOffset(search),
621 0,
622 false,
623 options: options.toJson()).toRequest('0');
624 return serverChannel.sendRequest(request);
625 }
626 }
627
628
629 @ReflectiveTestCase()
524 class RenameTest extends _AbstractGetRefactoring_Test { 630 class RenameTest extends _AbstractGetRefactoring_Test {
525 Future<Response> sendRenameRequest(String search, String newName, 631 Future<Response> sendRenameRequest(String search, String newName,
526 [bool validateOnly = false]) { 632 [bool validateOnly = false]) {
527 Request request = new EditGetRefactoringParams( 633 Request request = new EditGetRefactoringParams(
528 RefactoringKind.RENAME, 634 RefactoringKind.RENAME,
529 testFile, 635 testFile,
530 findOffset(search), 636 findOffset(search),
531 0, 637 0,
532 validateOnly, 638 validateOnly,
533 options: new RenameOptions(newName).toJson()).toRequest('0'); 639 options: new RenameOptions(newName).toJson()).toRequest('0');
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 } 1011 }
906 1012
907 @override 1013 @override
908 void setUp() { 1014 void setUp() {
909 super.setUp(); 1015 super.setUp();
910 server.handlers = [new EditDomainHandler(server),]; 1016 server.handlers = [new EditDomainHandler(server),];
911 createProject(); 1017 createProject();
912 handler = new EditDomainHandler(server); 1018 handler = new EditDomainHandler(server);
913 } 1019 }
914 } 1020 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/edit/edit_domain.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698