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

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

Issue 908463004: Convert refactoring tests to use 'await'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
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_local; 5 library test.services.refactoring.rename_local;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import '../../reflective_tests.dart'; 10 import '../../reflective_tests.dart';
11 import 'abstract_rename.dart'; 11 import 'abstract_rename.dart';
12 import 'package:analysis_server/src/services/correction/status.dart';
12 13
13 14
14 main() { 15 main() {
15 groupSep = ' | '; 16 groupSep = ' | ';
16 runReflectiveTests(RenameLocalTest); 17 runReflectiveTests(RenameLocalTest);
17 } 18 }
18 19
19 20
20 @reflectiveTest 21 @reflectiveTest
21 class RenameLocalTest extends RenameRefactoringTest { 22 class RenameLocalTest extends RenameRefactoringTest {
22 test_checkFinalConditions_hasLocalFunction_after() { 23 test_checkFinalConditions_hasLocalFunction_after() async {
23 indexTestUnit(''' 24 indexTestUnit('''
24 main() { 25 main() {
25 int test = 0; 26 int test = 0;
26 newName() => 1; 27 newName() => 1;
27 } 28 }
28 '''); 29 ''');
29 createRenameRefactoringAtString('test = 0'); 30 createRenameRefactoringAtString('test = 0');
30 // check status 31 // check status
31 refactoring.newName = 'newName'; 32 refactoring.newName = 'newName';
32 return refactoring.checkFinalConditions().then((status) { 33 RefactoringStatus status = await refactoring.checkFinalConditions();
33 assertRefactoringStatus( 34 assertRefactoringStatus(
34 status, 35 status,
35 RefactoringProblemSeverity.ERROR, 36 RefactoringProblemSeverity.ERROR,
36 expectedMessage: "Duplicate function 'newName'.", 37 expectedMessage: "Duplicate function 'newName'.",
37 expectedContextSearch: 'newName() => 1'); 38 expectedContextSearch: 'newName() => 1');
38 });
39 } 39 }
40 40
41 test_checkFinalConditions_hasLocalFunction_before() { 41 test_checkFinalConditions_hasLocalFunction_before() async {
42 indexTestUnit(''' 42 indexTestUnit('''
43 main() { 43 main() {
44 newName() => 1; 44 newName() => 1;
45 int test = 0; 45 int test = 0;
46 } 46 }
47 '''); 47 ''');
48 createRenameRefactoringAtString('test = 0'); 48 createRenameRefactoringAtString('test = 0');
49 // check status 49 // check status
50 refactoring.newName = 'newName'; 50 refactoring.newName = 'newName';
51 return refactoring.checkFinalConditions().then((status) { 51 RefactoringStatus status = await refactoring.checkFinalConditions();
52 assertRefactoringStatus( 52 assertRefactoringStatus(
53 status, 53 status,
54 RefactoringProblemSeverity.ERROR, 54 RefactoringProblemSeverity.ERROR,
55 expectedMessage: "Duplicate function 'newName'."); 55 expectedMessage: "Duplicate function 'newName'.");
56 });
57 } 56 }
58 57
59 test_checkFinalConditions_hasLocalVariable_after() { 58 test_checkFinalConditions_hasLocalVariable_after() async {
60 indexTestUnit(''' 59 indexTestUnit('''
61 main() { 60 main() {
62 int test = 0; 61 int test = 0;
63 var newName = 1; 62 var newName = 1;
64 print(newName); 63 print(newName);
65 } 64 }
66 '''); 65 ''');
67 createRenameRefactoringAtString('test = 0'); 66 createRenameRefactoringAtString('test = 0');
68 // check status 67 // check status
69 refactoring.newName = 'newName'; 68 refactoring.newName = 'newName';
70 return refactoring.checkFinalConditions().then((status) { 69 RefactoringStatus status = await refactoring.checkFinalConditions();
71 expect(status.problems, hasLength(1)); 70 expect(status.problems, hasLength(1));
72 assertRefactoringStatus( 71 assertRefactoringStatus(
73 status, 72 status,
74 RefactoringProblemSeverity.ERROR, 73 RefactoringProblemSeverity.ERROR,
75 expectedMessage: "Duplicate local variable 'newName'.", 74 expectedMessage: "Duplicate local variable 'newName'.",
76 expectedContextSearch: 'newName = 1;'); 75 expectedContextSearch: 'newName = 1;');
77 });
78 } 76 }
79 77
80 test_checkFinalConditions_hasLocalVariable_before() { 78 test_checkFinalConditions_hasLocalVariable_before() async {
81 indexTestUnit(''' 79 indexTestUnit('''
82 main() { 80 main() {
83 var newName = 1; 81 var newName = 1;
84 int test = 0; 82 int test = 0;
85 } 83 }
86 '''); 84 ''');
87 createRenameRefactoringAtString('test = 0'); 85 createRenameRefactoringAtString('test = 0');
88 // check status 86 // check status
89 refactoring.newName = 'newName'; 87 refactoring.newName = 'newName';
90 return refactoring.checkFinalConditions().then((status) { 88 RefactoringStatus status = await refactoring.checkFinalConditions();
91 assertRefactoringStatus( 89 assertRefactoringStatus(
92 status, 90 status,
93 RefactoringProblemSeverity.ERROR, 91 RefactoringProblemSeverity.ERROR,
94 expectedMessage: "Duplicate local variable 'newName'.", 92 expectedMessage: "Duplicate local variable 'newName'.",
95 expectedContextSearch: 'newName = 1;'); 93 expectedContextSearch: 'newName = 1;');
96 });
97 } 94 }
98 95
99 test_checkFinalConditions_hasLocalVariable_otherBlock() { 96 test_checkFinalConditions_hasLocalVariable_otherBlock() {
100 indexTestUnit(''' 97 indexTestUnit('''
101 main() { 98 main() {
102 { 99 {
103 var newName = 1; 100 var newName = 1;
104 } 101 }
105 { 102 {
106 int test = 0; 103 int test = 0;
(...skipping 14 matching lines...) Expand all
121 main2() { 118 main2() {
122 var newName = 1; 119 var newName = 1;
123 } 120 }
124 '''); 121 ''');
125 createRenameRefactoringAtString('test = 0'); 122 createRenameRefactoringAtString('test = 0');
126 // check status 123 // check status
127 refactoring.newName = 'newName'; 124 refactoring.newName = 'newName';
128 return assertRefactoringConditionsOK(); 125 return assertRefactoringConditionsOK();
129 } 126 }
130 127
131 test_checkFinalConditions_shadows_classMember() { 128 test_checkFinalConditions_shadows_classMember() async {
132 indexTestUnit(''' 129 indexTestUnit('''
133 class A { 130 class A {
134 var newName = 1; 131 var newName = 1;
135 main() { 132 main() {
136 var test = 0; 133 var test = 0;
137 print(newName); 134 print(newName);
138 } 135 }
139 } 136 }
140 '''); 137 ''');
141 createRenameRefactoringAtString('test = 0'); 138 createRenameRefactoringAtString('test = 0');
142 // check status 139 // check status
143 refactoring.newName = 'newName'; 140 refactoring.newName = 'newName';
144 return refactoring.checkFinalConditions().then((status) { 141 RefactoringStatus status = await refactoring.checkFinalConditions();
145 assertRefactoringStatus( 142 assertRefactoringStatus(
146 status, 143 status,
147 RefactoringProblemSeverity.ERROR, 144 RefactoringProblemSeverity.ERROR,
148 expectedMessage: 'Usage of field "A.newName" declared in "test.dart" ' 145 expectedMessage: 'Usage of field "A.newName" declared in "test.dart" '
149 'will be shadowed by renamed local variable.', 146 'will be shadowed by renamed local variable.',
150 expectedContextSearch: 'newName);'); 147 expectedContextSearch: 'newName);');
151 });
152 } 148 }
153 149
154 test_checkFinalConditions_shadows_classMemberOK_qualifiedReference() { 150 test_checkFinalConditions_shadows_classMemberOK_qualifiedReference() {
155 indexTestUnit(''' 151 indexTestUnit('''
156 class A { 152 class A {
157 var newName = 1; 153 var newName = 1;
158 main() { 154 main() {
159 var test = 0; 155 var test = 0;
160 print(this.newName); 156 print(this.newName);
161 } 157 }
(...skipping 12 matching lines...) Expand all
174 var test = 0; 170 var test = 0;
175 f(newName: test); 171 f(newName: test);
176 } 172 }
177 '''); 173 ''');
178 createRenameRefactoringAtString('test = 0'); 174 createRenameRefactoringAtString('test = 0');
179 // check status 175 // check status
180 refactoring.newName = 'newName'; 176 refactoring.newName = 'newName';
181 return assertRefactoringFinalConditionsOK(); 177 return assertRefactoringFinalConditionsOK();
182 } 178 }
183 179
184 test_checkFinalConditions_shadows_topLevelFunction() { 180 test_checkFinalConditions_shadows_topLevelFunction() async {
185 indexTestUnit(''' 181 indexTestUnit('''
186 newName() {} 182 newName() {}
187 main() { 183 main() {
188 var test = 0; 184 var test = 0;
189 newName(); // ref 185 newName(); // ref
190 } 186 }
191 '''); 187 ''');
192 createRenameRefactoringAtString('test = 0'); 188 createRenameRefactoringAtString('test = 0');
193 // check status 189 // check status
194 refactoring.newName = 'newName'; 190 refactoring.newName = 'newName';
195 return refactoring.checkFinalConditions().then((status) { 191 RefactoringStatus status = await refactoring.checkFinalConditions();
196 assertRefactoringStatus( 192 assertRefactoringStatus(
197 status, 193 status,
198 RefactoringProblemSeverity.ERROR, 194 RefactoringProblemSeverity.ERROR,
199 expectedContextSearch: 'newName(); // ref'); 195 expectedContextSearch: 'newName(); // ref');
200 });
201 } 196 }
202 197
203 test_checkNewName_FunctionElement() { 198 test_checkNewName_FunctionElement() {
204 indexTestUnit(''' 199 indexTestUnit('''
205 main() { 200 main() {
206 int test() {} 201 int test() {}
207 } 202 }
208 '''); 203 ''');
209 createRenameRefactoringAtString('test() {}'); 204 createRenameRefactoringAtString('test() {}');
210 // null 205 // null
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 newName = 1; 404 newName = 1;
410 newName += 2; 405 newName += 2;
411 print(newName); 406 print(newName);
412 } 407 }
413 main() { 408 main() {
414 myFunction(newName: 2); 409 myFunction(newName: 2);
415 } 410 }
416 '''); 411 ''');
417 } 412 }
418 413
419 test_createChange_parameter_namedInOtherFile() { 414 test_createChange_parameter_namedInOtherFile() async {
420 indexTestUnit(''' 415 indexTestUnit('''
421 class A { 416 class A {
422 A({test}); 417 A({test});
423 } 418 }
424 '''); 419 ''');
425 indexUnit('/test2.dart', ''' 420 indexUnit('/test2.dart', '''
426 import 'test.dart'; 421 import 'test.dart';
427 main() { 422 main() {
428 new A(test: 2); 423 new A(test: 2);
429 } 424 }
430 '''); 425 ''');
431 // configure refactoring 426 // configure refactoring
432 createRenameRefactoringAtString('test});'); 427 createRenameRefactoringAtString('test});');
433 expect(refactoring.refactoringName, 'Rename Parameter'); 428 expect(refactoring.refactoringName, 'Rename Parameter');
434 refactoring.newName = 'newName'; 429 refactoring.newName = 'newName';
435 // validate change 430 // validate change
436 return assertSuccessfulRefactoring(''' 431 await assertSuccessfulRefactoring('''
437 class A { 432 class A {
438 A({newName}); 433 A({newName});
439 } 434 }
440 ''').then((_) { 435 ''');
441 assertFileChangeResult('/test2.dart', ''' 436 assertFileChangeResult('/test2.dart', '''
442 import 'test.dart'; 437 import 'test.dart';
443 main() { 438 main() {
444 new A(newName: 2); 439 new A(newName: 2);
445 } 440 }
446 '''); 441 ''');
447 });
448 } 442 }
449 443
450 test_oldName() { 444 test_oldName() {
451 indexTestUnit(''' 445 indexTestUnit('''
452 main() { 446 main() {
453 int test = 0; 447 int test = 0;
454 } 448 }
455 '''); 449 ''');
456 // configure refactoring 450 // configure refactoring
457 createRenameRefactoringAtString('test = 0'); 451 createRenameRefactoringAtString('test = 0');
458 // old name 452 // old name
459 expect(refactoring.oldName, 'test'); 453 expect(refactoring.oldName, 'test');
460 } 454 }
461 } 455 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698