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

Side by Side Diff: pkg/analysis_server/test/services/refactoring/rename_constructor_test.dart

Issue 2614033003: Make subclasses of AbstractContextTest asynchronous. (Closed)
Patch Set: Created 3 years, 11 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
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.services.refactoring.rename_constructor; 5 library test.services.refactoring.rename_constructor;
6 6
7 import 'package:analysis_server/plugin/protocol/protocol.dart'; 7 import 'package:analysis_server/plugin/protocol/protocol.dart';
8 import 'package:analysis_server/src/services/correction/status.dart'; 8 import 'package:analysis_server/src/services/correction/status.dart';
9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
11 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
12 import 'package:test/test.dart'; 12 import 'package:test/test.dart';
13 import 'package:test_reflective_loader/test_reflective_loader.dart'; 13 import 'package:test_reflective_loader/test_reflective_loader.dart';
14 14
15 import 'abstract_rename.dart'; 15 import 'abstract_rename.dart';
16 16
17 main() { 17 main() {
18 defineReflectiveSuite(() { 18 defineReflectiveSuite(() {
19 defineReflectiveTests(RenameConstructorTest); 19 defineReflectiveTests(RenameConstructorTest);
20 }); 20 });
21 } 21 }
22 22
23 @reflectiveTest 23 @reflectiveTest
24 class RenameConstructorTest extends RenameRefactoringTest { 24 class RenameConstructorTest extends RenameRefactoringTest {
25 test_checkInitialConditions_inSDK() async { 25 test_checkInitialConditions_inSDK() async {
26 indexTestUnit(''' 26 await indexTestUnit('''
27 main() { 27 main() {
28 new String.fromCharCodes([]); 28 new String.fromCharCodes([]);
29 } 29 }
30 '''); 30 ''');
31 createRenameRefactoringAtString('fromCharCodes('); 31 createRenameRefactoringAtString('fromCharCodes(');
32 // check status 32 // check status
33 refactoring.newName = 'newName'; 33 refactoring.newName = 'newName';
34 RefactoringStatus status = await refactoring.checkInitialConditions(); 34 RefactoringStatus status = await refactoring.checkInitialConditions();
35 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, 35 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL,
36 expectedMessage: 36 expectedMessage:
37 "The constructor 'String.fromCharCodes' is defined in the SDK, so ca nnot be renamed."); 37 "The constructor 'String.fromCharCodes' is defined in the SDK, so ca nnot be renamed.");
38 } 38 }
39 39
40 test_checkNewName() { 40 test_checkNewName() async {
41 indexTestUnit(''' 41 await indexTestUnit('''
42 class A { 42 class A {
43 A.test() {} 43 A.test() {}
44 } 44 }
45 '''); 45 ''');
46 createRenameRefactoringAtString('test() {}'); 46 createRenameRefactoringAtString('test() {}');
47 expect(refactoring.oldName, 'test'); 47 expect(refactoring.oldName, 'test');
48 // null 48 // null
49 refactoring.newName = null; 49 refactoring.newName = null;
50 assertRefactoringStatus( 50 assertRefactoringStatus(
51 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, 51 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL,
52 expectedMessage: "Constructor name must not be null."); 52 expectedMessage: "Constructor name must not be null.");
53 // same 53 // same
54 refactoring.newName = 'test'; 54 refactoring.newName = 'test';
55 assertRefactoringStatus( 55 assertRefactoringStatus(
56 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, 56 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL,
57 expectedMessage: 57 expectedMessage:
58 "The new name must be different than the current name."); 58 "The new name must be different than the current name.");
59 // empty 59 // empty
60 refactoring.newName = ''; 60 refactoring.newName = '';
61 assertRefactoringStatusOK(refactoring.checkNewName()); 61 assertRefactoringStatusOK(refactoring.checkNewName());
62 // OK 62 // OK
63 refactoring.newName = 'newName'; 63 refactoring.newName = 'newName';
64 assertRefactoringStatusOK(refactoring.checkNewName()); 64 assertRefactoringStatusOK(refactoring.checkNewName());
65 } 65 }
66 66
67 test_checkNewName_hasMember_constructor() async { 67 test_checkNewName_hasMember_constructor() async {
68 indexTestUnit(''' 68 await indexTestUnit('''
69 class A { 69 class A {
70 A.test() {} 70 A.test() {}
71 A.newName() {} // existing 71 A.newName() {} // existing
72 } 72 }
73 '''); 73 ''');
74 _createConstructorDeclarationRefactoring('test() {}'); 74 _createConstructorDeclarationRefactoring('test() {}');
75 // check status 75 // check status
76 refactoring.newName = 'newName'; 76 refactoring.newName = 'newName';
77 RefactoringStatus status = refactoring.checkNewName(); 77 RefactoringStatus status = refactoring.checkNewName();
78 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, 78 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
79 expectedMessage: 79 expectedMessage:
80 "Class 'A' already declares constructor with name 'newName'.", 80 "Class 'A' already declares constructor with name 'newName'.",
81 expectedContextSearch: 'newName() {} // existing'); 81 expectedContextSearch: 'newName() {} // existing');
82 } 82 }
83 83
84 test_checkNewName_hasMember_method() async { 84 test_checkNewName_hasMember_method() async {
85 indexTestUnit(''' 85 await indexTestUnit('''
86 class A { 86 class A {
87 A.test() {} 87 A.test() {}
88 newName() {} // existing 88 newName() {} // existing
89 } 89 }
90 '''); 90 ''');
91 _createConstructorDeclarationRefactoring('test() {}'); 91 _createConstructorDeclarationRefactoring('test() {}');
92 // check status 92 // check status
93 refactoring.newName = 'newName'; 93 refactoring.newName = 'newName';
94 RefactoringStatus status = refactoring.checkNewName(); 94 RefactoringStatus status = refactoring.checkNewName();
95 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, 95 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
96 expectedMessage: 96 expectedMessage:
97 "Class 'A' already declares method with name 'newName'.", 97 "Class 'A' already declares method with name 'newName'.",
98 expectedContextSearch: 'newName() {} // existing'); 98 expectedContextSearch: 'newName() {} // existing');
99 } 99 }
100 100
101 test_createChange_add() { 101 test_createChange_add() async {
102 indexTestUnit(''' 102 await indexTestUnit('''
103 class A { 103 class A {
104 A() {} // marker 104 A() {} // marker
105 } 105 }
106 class B extends A { 106 class B extends A {
107 B() : super() {} 107 B() : super() {}
108 factory B._() = A; 108 factory B._() = A;
109 } 109 }
110 main() { 110 main() {
111 new A(); 111 new A();
112 } 112 }
(...skipping 12 matching lines...) Expand all
125 class B extends A { 125 class B extends A {
126 B() : super.newName() {} 126 B() : super.newName() {}
127 factory B._() = A.newName; 127 factory B._() = A.newName;
128 } 128 }
129 main() { 129 main() {
130 new A.newName(); 130 new A.newName();
131 } 131 }
132 '''); 132 ''');
133 } 133 }
134 134
135 test_createChange_add_toSynthetic() { 135 test_createChange_add_toSynthetic() async {
136 indexTestUnit(''' 136 await indexTestUnit('''
137 class A { 137 class A {
138 } 138 }
139 class B extends A { 139 class B extends A {
140 B() : super() {} 140 B() : super() {}
141 factory B._() = A; 141 factory B._() = A;
142 } 142 }
143 main() { 143 main() {
144 new A(); 144 new A();
145 } 145 }
146 '''); 146 ''');
(...skipping 11 matching lines...) Expand all
158 class B extends A { 158 class B extends A {
159 B() : super.newName() {} 159 B() : super.newName() {}
160 factory B._() = A.newName; 160 factory B._() = A.newName;
161 } 161 }
162 main() { 162 main() {
163 new A.newName(); 163 new A.newName();
164 } 164 }
165 '''); 165 ''');
166 } 166 }
167 167
168 test_createChange_change() { 168 test_createChange_change() async {
169 indexTestUnit(''' 169 await indexTestUnit('''
170 class A { 170 class A {
171 A.test() {} // marker 171 A.test() {} // marker
172 } 172 }
173 class B extends A { 173 class B extends A {
174 B() : super.test() {} 174 B() : super.test() {}
175 factory B._() = A.test; 175 factory B._() = A.test;
176 } 176 }
177 main() { 177 main() {
178 new A.test(); 178 new A.test();
179 } 179 }
(...skipping 12 matching lines...) Expand all
192 class B extends A { 192 class B extends A {
193 B() : super.newName() {} 193 B() : super.newName() {}
194 factory B._() = A.newName; 194 factory B._() = A.newName;
195 } 195 }
196 main() { 196 main() {
197 new A.newName(); 197 new A.newName();
198 } 198 }
199 '''); 199 ''');
200 } 200 }
201 201
202 test_createChange_remove() { 202 test_createChange_remove() async {
203 indexTestUnit(''' 203 await indexTestUnit('''
204 class A { 204 class A {
205 A.test() {} // marker 205 A.test() {} // marker
206 } 206 }
207 class B extends A { 207 class B extends A {
208 B() : super.test() {} 208 B() : super.test() {}
209 factory B._() = A.test; 209 factory B._() = A.test;
210 } 210 }
211 main() { 211 main() {
212 new A.test(); 212 new A.test();
213 } 213 }
(...skipping 12 matching lines...) Expand all
226 class B extends A { 226 class B extends A {
227 B() : super() {} 227 B() : super() {}
228 factory B._() = A; 228 factory B._() = A;
229 } 229 }
230 main() { 230 main() {
231 new A(); 231 new A();
232 } 232 }
233 '''); 233 ''');
234 } 234 }
235 235
236 void test_newInstance_nullElement() { 236 test_newInstance_nullElement() async {
237 RenameRefactoring refactoring = new RenameRefactoring(searchEngine, null); 237 RenameRefactoring refactoring = new RenameRefactoring(searchEngine, null);
238 expect(refactoring, isNull); 238 expect(refactoring, isNull);
239 } 239 }
240 240
241 void _createConstructorDeclarationRefactoring(String search) { 241 void _createConstructorDeclarationRefactoring(String search) {
242 ConstructorElement element = findNodeElementAtString( 242 ConstructorElement element = findNodeElementAtString(
243 search, (node) => node is ConstructorDeclaration); 243 search, (node) => node is ConstructorDeclaration);
244 createRenameRefactoringForElement(element); 244 createRenameRefactoringForElement(element);
245 } 245 }
246 246
247 void _createConstructorInvocationRefactoring(String search) { 247 void _createConstructorInvocationRefactoring(String search) {
248 ConstructorElement element = findNodeElementAtString( 248 ConstructorElement element = findNodeElementAtString(
249 search, (node) => node is InstanceCreationExpression); 249 search, (node) => node is InstanceCreationExpression);
250 createRenameRefactoringForElement(element); 250 createRenameRefactoringForElement(element);
251 } 251 }
252 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698