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

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

Issue 1053323002: Issue 22988. Improve checking for conflicts between parameters and local elements during extracting… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up. Created 5 years, 8 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/test/mock_sdk.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | 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.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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 { 377 {
378 List<RefactoringMethodParameter> parameters = _getParametersCopy(); 378 List<RefactoringMethodParameter> parameters = _getParametersCopy();
379 expect(parameters, hasLength(2)); 379 expect(parameters, hasLength(2));
380 parameters[0].name = 'dup'; 380 parameters[0].name = 'dup';
381 parameters[1].name = 'dup'; 381 parameters[1].name = 'dup';
382 refactoring.parameters = parameters; 382 refactoring.parameters = parameters;
383 } 383 }
384 return _assertFinalConditionsError("Parameter 'dup' already exists"); 384 return _assertFinalConditionsError("Parameter 'dup' already exists");
385 } 385 }
386 386
387 test_bad_parameterName_inUse() async { 387 test_bad_parameterName_inUse_function() async {
388 indexTestUnit(''' 388 indexTestUnit('''
389 main() { 389 main() {
390 int v1 = 1; 390 int v1 = 1;
391 int v2 = 2;
392 // start
393 f(v1, v2);
394 // end
395 }
396 f(a, b) {}
397 ''');
398 _createRefactoringForStartEndComments();
399 // update parameters
400 await refactoring.checkInitialConditions();
401 {
402 List<RefactoringMethodParameter> parameters = _getParametersCopy();
403 expect(parameters, hasLength(2));
404 parameters[0].name = 'f';
405 refactoring.parameters = parameters;
406 }
407 return _assertFinalConditionsError(
408 "'f' is already used as a name in the selected code");
409 }
410
411 test_bad_parameterName_inUse_localVariable() async {
412 indexTestUnit('''
413 main() {
414 int v1 = 1;
391 int v2 = 2; 415 int v2 = 2;
392 // start 416 // start
393 int a = v1 + v2; // marker 417 int a = v1 + v2; // marker
394 // end 418 // end
395 } 419 }
396 '''); 420 ''');
397 _createRefactoringForStartEndComments(); 421 _createRefactoringForStartEndComments();
398 // update parameters 422 // update parameters
399 await refactoring.checkInitialConditions(); 423 await refactoring.checkInitialConditions();
400 { 424 {
401 List<RefactoringMethodParameter> parameters = _getParametersCopy(); 425 List<RefactoringMethodParameter> parameters = _getParametersCopy();
402 expect(parameters, hasLength(2)); 426 expect(parameters, hasLength(2));
403 parameters[0].name = 'a'; 427 parameters[0].name = 'a';
404 refactoring.parameters = parameters; 428 refactoring.parameters = parameters;
405 } 429 }
406 return _assertFinalConditionsError( 430 return _assertFinalConditionsError(
407 "'a' is already used as a name in the selected code"); 431 "'a' is already used as a name in the selected code");
408 } 432 }
409 433
434 test_bad_parameterName_inUse_method() async {
435 indexTestUnit('''
436 class A {
437 main() {
438 int v1 = 1;
439 int v2 = 2;
440 // start
441 m(v1, v2);
442 // end
443 }
444 m(a, b) {}
445 }
446 ''');
447 _createRefactoringForStartEndComments();
448 // update parameters
449 await refactoring.checkInitialConditions();
450 {
451 List<RefactoringMethodParameter> parameters = _getParametersCopy();
452 expect(parameters, hasLength(2));
453 parameters[0].name = 'm';
454 refactoring.parameters = parameters;
455 }
456 return _assertFinalConditionsError(
457 "'m' is already used as a name in the selected code");
458 }
459
410 test_bad_selectionEndsInSomeNode() { 460 test_bad_selectionEndsInSomeNode() {
411 indexTestUnit(''' 461 indexTestUnit('''
412 main() { 462 main() {
413 // start 463 // start
414 print(0); 464 print(0);
415 print(1); 465 print(1);
416 // end 466 // end
417 } 467 }
418 '''); 468 ''');
419 _createRefactoringForStartEndString('print(0', 'rint(1)'); 469 _createRefactoringForStartEndString('print(0', 'rint(1)');
(...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2206 res(v); 2256 res(v);
2207 // end 2257 // end
2208 } 2258 }
2209 2259
2210 void res(Future<int> v) { 2260 void res(Future<int> v) {
2211 print(v); 2261 print(v);
2212 } 2262 }
2213 '''); 2263 ''');
2214 } 2264 }
2215 2265
2266 test_statements_parameters_noLocalVariableConflict() async {
2267 indexTestUnit('''
2268 int f(int x) {
2269 int y = x + 1;
2270 // start
2271 if (y % 2 == 0) {
2272 int y = x + 2;
2273 return y;
2274 } else {
2275 return y;
2276 }
2277 // end
2278 }
2279 ''');
2280 _createRefactoringForStartEndComments();
2281 await assertRefactoringConditionsOK();
2282 }
2283
2216 test_statements_return_last() { 2284 test_statements_return_last() {
2217 indexTestUnit(''' 2285 indexTestUnit('''
2218 main() { 2286 main() {
2219 // start 2287 // start
2220 int v = 5; 2288 int v = 5;
2221 return v + 1; 2289 return v + 1;
2222 // end 2290 // end
2223 } 2291 }
2224 '''); 2292 ''');
2225 _createRefactoringForStartEndComments(); 2293 _createRefactoringForStartEndComments();
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
2497 * Returns a deep copy of [refactoring] parameters. 2565 * Returns a deep copy of [refactoring] parameters.
2498 * There was a bug masked by updating parameter instances shared between the 2566 * There was a bug masked by updating parameter instances shared between the
2499 * refactoring and the test. 2567 * refactoring and the test.
2500 */ 2568 */
2501 List<RefactoringMethodParameter> _getParametersCopy() { 2569 List<RefactoringMethodParameter> _getParametersCopy() {
2502 return refactoring.parameters.map((p) { 2570 return refactoring.parameters.map((p) {
2503 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); 2571 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id);
2504 }).toList(); 2572 }).toList();
2505 } 2573 }
2506 } 2574 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/mock_sdk.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698