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

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

Issue 489413003: Finish 'Extract Local' refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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/services/refactoring/extract_local.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.services.refactoring.extract_local; 5 library test.services.refactoring.extract_local;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/services/correction/change.dart'; 9 import 'package:analysis_server/src/services/correction/change.dart';
10 import 'package:analysis_server/src/services/correction/status.dart'; 10 import 'package:analysis_server/src/services/correction/status.dart';
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 _createRefactoringForString('2 + 3 '); 462 _createRefactoringForString('2 + 3 ');
463 // apply refactoring 463 // apply refactoring
464 return _assertSuccessfulRefactoring(''' 464 return _assertSuccessfulRefactoring('''
465 main() { 465 main() {
466 var res = 2 + 3 ; 466 var res = 2 + 3 ;
467 int a = 1 + res+ 4; 467 int a = 1 + res+ 4;
468 } 468 }
469 '''); 469 ''');
470 } 470 }
471 471
472 test_guessNames_fragmentExpression() {
473 indexTestUnit('''
474 main() {
475 var a = 111 + 222 + 333 + 444;
476 }
477 ''');
478 _createRefactoringForString('222 + 333');
479 // check guesses
480 return refactoring.checkInitialConditions().then((_) {
481 expect(refactoring.names, isEmpty);
482 });
483 }
484
485 test_guessNames_singleExpression() {
486 indexTestUnit('''
487 class TreeItem {}
488 TreeItem getSelectedItem() => null;
489 process(my) {}
490 main() {
491 process(getSelectedItem()); // marker
492 }
493 ''');
494 _createRefactoringWithSuffix('getSelectedItem()', '); // marker');
495 // check guesses
496 return refactoring.checkInitialConditions().then((_) {
497 expect(
498 refactoring.names,
499 unorderedEquals(['selectedItem', 'item', 'my', 'treeItem']));
500 });
501 }
502
503 test_guessNames_stringPart() {
504 indexTestUnit('''
505 main() {
506 var s = 'Hello Bob... welcome to Dart!';
507 }
508 ''');
509 _createRefactoringForString('Hello Bob');
510 // check guesses
511 return refactoring.checkInitialConditions().then((_) {
512 expect(refactoring.names, unorderedEquals(['helloBob', 'bob']));
513 });
514 }
515
472 test_occurences_disableOccurences() { 516 test_occurences_disableOccurences() {
473 indexTestUnit(''' 517 indexTestUnit('''
474 int foo() => 42; 518 int foo() => 42;
475 main() { 519 main() {
476 int a = 1 + foo(); 520 int a = 1 + foo();
477 int b = 2 + foo(); // marker 521 int b = 2 + foo(); // marker
478 } 522 }
479 '''); 523 ''');
480 _createRefactoringWithSuffix('foo()', '; // marker'); 524 _createRefactoringWithSuffix('foo()', '; // marker');
481 refactoring.extractAll = false; 525 refactoring.extractAll = false;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 int foo(String s) => 42; 654 int foo(String s) => 42;
611 main() { 655 main() {
612 var res = foo('has space'); 656 var res = foo('has space');
613 int a = 1 + res; 657 int a = 1 + res;
614 int b = 2 + res; // marker 658 int b = 2 + res; // marker
615 } 659 }
616 '''); 660 ''');
617 } 661 }
618 662
619 test_offsets_lengths() { 663 test_offsets_lengths() {
620 // TODO(scheglov) implement and test 664 indexTestUnit('''
665 int foo() => 42;
666 main() {
667 int a = 1 + foo(); // marker
668 int b = 2 + foo( );
669 }
670 ''');
671 _createRefactoringWithSuffix('foo()', '; // marker');
672 // apply refactoring
673 return refactoring.checkInitialConditions().then((_) {
674 expect(
675 refactoring.offsets,
676 unorderedEquals([findOffset('foo();'), findOffset('foo( );')]));
677 expect(refactoring.lengths, unorderedEquals([5, 6]));
678 });
621 } 679 }
622 680
623 test_singleExpression() { 681 test_singleExpression() {
624 indexTestUnit(''' 682 indexTestUnit('''
625 main() { 683 main() {
626 int a = 1 + 2; 684 int a = 1 + 2;
627 } 685 }
628 '''); 686 ''');
629 _createRefactoringForString('1 + 2'); 687 _createRefactoringForString('1 + 2');
630 // apply refactoring 688 // apply refactoring
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 int length = search.length; 897 int length = search.length;
840 _createRefactoring(offset, length); 898 _createRefactoring(offset, length);
841 } 899 }
842 900
843 void _createRefactoringWithSuffix(String selectionSearch, String suffix) { 901 void _createRefactoringWithSuffix(String selectionSearch, String suffix) {
844 int offset = findOffset(selectionSearch + suffix); 902 int offset = findOffset(selectionSearch + suffix);
845 int length = selectionSearch.length; 903 int length = selectionSearch.length;
846 _createRefactoring(offset, length); 904 _createRefactoring(offset, length);
847 } 905 }
848 } 906 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/refactoring/extract_local.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698