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

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

Issue 591083003: Integrate CONVERT_METHOD_TO_GETTER 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:unittest/unittest.dart' hide ERROR; 13 import 'package:unittest/unittest.dart' hide ERROR;
14 14
15 import '../analysis_abstract.dart'; 15 import '../analysis_abstract.dart';
16 import '../reflective_tests.dart'; 16 import '../reflective_tests.dart';
17 17
18 18
19 main() { 19 main() {
20 groupSep = ' | '; 20 groupSep = ' | ';
21 runReflectiveTests(ConvertMethodToGetterTest);
21 runReflectiveTests(ExtractLocalVariableTest); 22 runReflectiveTests(ExtractLocalVariableTest);
22 runReflectiveTests(ExtractMethodTest); 23 runReflectiveTests(ExtractMethodTest);
23 runReflectiveTests(GetAvailableRefactoringsTest); 24 runReflectiveTests(GetAvailableRefactoringsTest);
24 runReflectiveTests(InlineLocalTest); 25 runReflectiveTests(InlineLocalTest);
25 runReflectiveTests(InlineMethodTest); 26 runReflectiveTests(InlineMethodTest);
26 runReflectiveTests(MoveFileTest); 27 runReflectiveTests(MoveFileTest);
27 runReflectiveTests(RenameTest); 28 runReflectiveTests(RenameTest);
28 } 29 }
29 30
30 31
31 @ReflectiveTestCase() 32 @ReflectiveTestCase()
33 class ConvertMethodToGetterTest extends _AbstractGetRefactoring_Test {
34 test_function() {
35 addTestFile('''
36 int test() => 42;
37 main() {
38 var a = 1 + test();
39 var b = 2 + test();
40 }
41 ''');
42 return assertSuccessfulRefactoring(() {
43 return _sendConvertRequest('test() =>');
44 }, '''
45 int get test => 42;
46 main() {
47 var a = 1 + test;
48 var b = 2 + test;
49 }
50 ''');
51 }
52
53 test_init_fatalError_hasParameters() {
54 addTestFile('''
55 int test(p) => p + 1;
56 main() {
57 var v = test(2);
58 }
59 ''');
60 return getRefactoringResult(() {
61 return _sendConvertRequest('test(p)');
62 }).then((result) {
63 assertResultProblemsFatal(
64 result.initialProblems,
65 'Only methods without parameters can be converted to getters.');
66 // ...there is no any change
67 expect(result.change, isNull);
68 });
69 }
70
71 test_init_fatalError_notExecutableElement() {
72 addTestFile('''
73 main() {
74 int abc = 1;
75 print(abc);
76 }
77 ''');
78 return getRefactoringResult(() {
79 return _sendConvertRequest('abc');
80 }).then((result) {
81 assertResultProblemsFatal(
82 result.initialProblems,
83 'Unable to create a refactoring');
84 // ...there is no any change
85 expect(result.change, isNull);
86 });
87 }
88
89 test_method() {
90 addTestFile('''
91 class A {
92 int test() => 1;
93 }
94 class B extends A {
95 int test() => 2;
96 }
97 class C extends B {
98 int test() => 3;
99 }
100 class D extends A {
101 int test() => 4;
102 }
103 main(A a, B b, C c, D d) {
104 var va = a.test();
105 var vb = b.test();
106 var vc = c.test();
107 var vd = d.test();
108 }
109 ''');
110 return assertSuccessfulRefactoring(() {
111 return _sendConvertRequest('test() => 2');
112 }, '''
113 class A {
114 int get test => 1;
115 }
116 class B extends A {
117 int get test => 2;
118 }
119 class C extends B {
120 int get test => 3;
121 }
122 class D extends A {
123 int get test => 4;
124 }
125 main(A a, B b, C c, D d) {
126 var va = a.test;
127 var vb = b.test;
128 var vc = c.test;
129 var vd = d.test;
130 }
131 ''');
132 }
133
134 Future<Response> _sendConvertRequest(String search) {
135 Request request = new EditGetRefactoringParams(
136 RefactoringKind.CONVERT_METHOD_TO_GETTER,
137 testFile,
138 findOffset(search),
139 0,
140 false).toRequest('0');
141 return serverChannel.sendRequest(request);
142 }
143 }
144
145
146 @ReflectiveTestCase()
32 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { 147 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test {
33 Future<Response> sendExtractRequest(int offset, int length, String name, 148 Future<Response> sendExtractRequest(int offset, int length, String name,
34 bool extractAll) { 149 bool extractAll) {
35 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE; 150 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE;
36 ExtractLocalVariableOptions options = 151 ExtractLocalVariableOptions options =
37 name != null ? new ExtractLocalVariableOptions(name, extractAll) : null; 152 name != null ? new ExtractLocalVariableOptions(name, extractAll) : null;
38 return sendRequest(kind, offset, length, options, false); 153 return sendRequest(kind, offset, length, options, false);
39 } 154 }
40 155
41 Future<Response> sendStringRequest(String search, String name, 156 Future<Response> sendStringRequest(String search, String name,
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 } 1306 }
1192 1307
1193 @override 1308 @override
1194 void setUp() { 1309 void setUp() {
1195 super.setUp(); 1310 super.setUp();
1196 server.handlers = [new EditDomainHandler(server),]; 1311 server.handlers = [new EditDomainHandler(server),];
1197 createProject(); 1312 createProject();
1198 handler = new EditDomainHandler(server); 1313 handler = new EditDomainHandler(server);
1199 } 1314 }
1200 } 1315 }
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