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

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

Issue 871013012: Issue 22188. Verify that none or all execution flows return. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments. 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.extract_method; 5 library test.services.refactoring.extract_method;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/correction/status.dart'; 10 import 'package:analysis_server/src/services/correction/status.dart';
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 print(1); 417 print(1);
418 // end 418 // end
419 } 419 }
420 '''); 420 ''');
421 _createRefactoringForStartEndString('print(0', 'rint(1)'); 421 _createRefactoringForStartEndString('print(0', 'rint(1)');
422 return _assertConditionsFatal( 422 return _assertConditionsFatal(
423 "The selection does not cover a set of statements or an expression. " 423 "The selection does not cover a set of statements or an expression. "
424 "Extend selection to a valid range."); 424 "Extend selection to a valid range.");
425 } 425 }
426 426
427 test_bad_statements_exit_notAllExecutionFlows() {
428 indexTestUnit('''
429 main(int p) {
430 // start
431 if (p == 0) {
432 return;
433 }
434 // end
435 print(p);
436 }
437 ''');
438 _createRefactoringForStartEndComments();
439 return _assertConditionsError(ExtractMethodRefactoringImpl.ERROR_EXITS);
440 }
441
427 test_bad_statements_return_andAssignsVariable() { 442 test_bad_statements_return_andAssignsVariable() {
428 indexTestUnit(''' 443 indexTestUnit('''
429 main() { 444 main() {
430 // start 445 // start
431 var v = 0; 446 var v = 0;
432 return 42; 447 return 42;
433 // end 448 // end
434 print(v); 449 print(v);
435 } 450 }
436 '''); 451 ''');
(...skipping 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 } 2088 }
2074 2089
2075 void res() { 2090 void res() {
2076 if (true) { 2091 if (true) {
2077 print(0); 2092 print(0);
2078 } 2093 }
2079 } 2094 }
2080 '''); 2095 ''');
2081 } 2096 }
2082 2097
2098 test_statements_exit_throws() async {
2099 indexTestUnit('''
2100 main(int p) {
2101 // start
2102 if (p == 0) {
2103 return;
2104 }
2105 throw 'boo!';
2106 // end
2107 }
2108 ''');
2109 _createRefactoringForStartEndComments();
2110 await assertRefactoringConditionsOK();
2111 }
2112
2083 test_statements_inSwitchMember() { 2113 test_statements_inSwitchMember() {
2084 indexTestUnit(''' 2114 indexTestUnit('''
2085 class A { 2115 class A {
2086 foo(int p) { 2116 foo(int p) {
2087 switch (p) { 2117 switch (p) {
2088 case 0: 2118 case 0:
2089 // start 2119 // start
2090 print(0); 2120 print(0);
2091 // end 2121 // end
2092 break; 2122 break;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 return 42; 2315 return 42;
2286 } 2316 }
2287 '''); 2317 ''');
2288 } 2318 }
2289 2319
2290 test_statements_return_multiple_sameElementDifferentTypeArgs() { 2320 test_statements_return_multiple_sameElementDifferentTypeArgs() {
2291 indexTestUnit(''' 2321 indexTestUnit('''
2292 main(bool b) { 2322 main(bool b) {
2293 // start 2323 // start
2294 if (b) { 2324 if (b) {
2325 print(true);
2295 return <int>[]; 2326 return <int>[];
2296 } else { 2327 } else {
2328 print(false);
2297 return <String>[]; 2329 return <String>[];
2298 } 2330 }
2299 // end 2331 // end
2300 } 2332 }
2301 '''); 2333 ''');
2302 _createRefactoringForStartEndComments(); 2334 _createRefactoringForStartEndComments();
2303 // apply refactoring 2335 // apply refactoring
2304 return _assertSuccessfulRefactoring(''' 2336 return _assertSuccessfulRefactoring('''
2305 main(bool b) { 2337 main(bool b) {
2306 // start 2338 // start
2307 return res(b); 2339 return res(b);
2308 // end 2340 // end
2309 } 2341 }
2310 2342
2311 List res(bool b) { 2343 List res(bool b) {
2312 if (b) { 2344 if (b) {
2345 print(true);
2313 return <int>[]; 2346 return <int>[];
2314 } else { 2347 } else {
2348 print(false);
2315 return <String>[]; 2349 return <String>[];
2316 } 2350 }
2317 } 2351 }
2318 '''); 2352 ''');
2319 } 2353 }
2320 2354
2321 test_statements_return_single() { 2355 test_statements_return_single() {
2322 indexTestUnit(''' 2356 indexTestUnit('''
2323 main() { 2357 main() {
2324 // start 2358 // start
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 * Returns a deep copy of [refactoring] parameters. 2485 * Returns a deep copy of [refactoring] parameters.
2452 * There was a bug masked by updating parameter instances shared between the 2486 * There was a bug masked by updating parameter instances shared between the
2453 * refactoring and the test. 2487 * refactoring and the test.
2454 */ 2488 */
2455 List<RefactoringMethodParameter> _getParametersCopy() { 2489 List<RefactoringMethodParameter> _getParametersCopy() {
2456 return refactoring.parameters.map((p) { 2490 return refactoring.parameters.map((p) {
2457 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); 2491 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id);
2458 }).toList(); 2492 }).toList();
2459 } 2493 }
2460 } 2494 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/refactoring/extract_method.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698