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

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

Issue 1026503002: Simplify rules for extracting getters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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_method.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_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 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 var X = 1; 853 var X = 1;
854 854
855 var Y = () { 855 var Y = () {
856 return res(); 856 return res();
857 }; 857 };
858 858
859 num res() => 1 + X; 859 num res() => 1 + X;
860 '''); 860 ''');
861 } 861 }
862 862
863 test_getExtractGetter_false_do() async { 863 test_getExtractGetter_expression_true_binaryExpression() async {
864 indexTestUnit('''
865 main() {
866 print(1 + 2);
867 }
868 ''');
869 _createRefactoringForString('1 + 2');
870 // apply refactoring
871 await assertRefactoringConditionsOK();
872 expect(refactoring.createGetter, true);
873 }
874
875 test_getExtractGetter_expression_true_literal() async {
876 indexTestUnit('''
877 main() {
878 print(42);
879 }
880 ''');
881 _createRefactoringForString('42');
882 // apply refactoring
883 await assertRefactoringConditionsOK();
884 expect(refactoring.createGetter, true);
885 }
886
887 test_getExtractGetter_expression_true_prefixedExpression() async {
888 indexTestUnit('''
889 main() {
890 print(!true);
891 }
892 ''');
893 _createRefactoringForString('!true');
894 // apply refactoring
895 await assertRefactoringConditionsOK();
896 expect(refactoring.createGetter, true);
897 }
898
899 test_getExtractGetter_expression_true_prefixedIdentifier() async {
900 indexTestUnit('''
901 main() {
902 print(myValue.isEven);
903 }
904 int get myValue => 42;
905 ''');
906 _createRefactoringForString('myValue.isEven');
907 // apply refactoring
908 await assertRefactoringConditionsOK();
909 expect(refactoring.createGetter, true);
910 }
911
912 test_getExtractGetter_expression_true_propertyAccess() async {
913 indexTestUnit('''
914 main() {
915 print(1.isEven);
916 }
917 ''');
918 _createRefactoringForString('1.isEven');
919 // apply refactoring
920 await assertRefactoringConditionsOK();
921 expect(refactoring.createGetter, true);
922 }
923
924 test_getExtractGetter_statements() async {
864 indexTestUnit(''' 925 indexTestUnit('''
865 main() { 926 main() {
866 // start 927 // start
867 int v = 0; 928 int v = 0;
868 do {
869 v++;
870 } while (v < 10);
871 // end 929 // end
872 print(v); 930 print(v);
873 } 931 }
874 ''');
875 _createRefactoringForStartEndComments();
876 // apply refactoring
877 await assertRefactoringConditionsOK();
878 expect(refactoring.createGetter, false);
879 }
880
881 test_getExtractGetter_false_for() async {
882 indexTestUnit('''
883 main() {
884 // start
885 int v = 0;
886 for (int i = 0; i < 10; i++) {
887 v += i;
888 }
889 // end
890 print(v);
891 }
892 ''');
893 _createRefactoringForStartEndComments();
894 // apply refactoring
895 await assertRefactoringConditionsOK();
896 expect(refactoring.createGetter, false);
897 }
898
899 test_getExtractGetter_false_forEach() async {
900 indexTestUnit('''
901 main() {
902 // start
903 int v = 0;
904 for (int i in [1, 2, 3]) {
905 v += i;
906 }
907 // end
908 print(v);
909 }
910 ''');
911 _createRefactoringForStartEndComments();
912 // apply refactoring
913 await assertRefactoringConditionsOK();
914 expect(refactoring.createGetter, false);
915 }
916
917 test_getExtractGetter_false_methodInvocation_expression() async {
918 indexTestUnit('''
919 main() {
920 int v = calculateSomething() + 5;
921 }
922 int calculateSomething() => 42;
923 ''');
924 _createRefactoringForString('calculateSomething() + 5');
925 // apply refactoring
926 await assertRefactoringConditionsOK();
927 expect(refactoring.createGetter, false);
928 }
929
930 test_getExtractGetter_false_methodInvocation_statements() async {
931 indexTestUnit('''
932 main() {
933 // start
934 int v = calculateSomething();
935 // end
936 print(v);
937 }
938 int calculateSomething() => 42;
939 ''');
940 _createRefactoringForStartEndComments();
941 // apply refactoring
942 await assertRefactoringConditionsOK();
943 expect(refactoring.createGetter, false);
944 }
945
946 test_getExtractGetter_false_while() async {
947 indexTestUnit('''
948 main() {
949 // start
950 int v = 0;
951 while (v < 10) {
952 v++;
953 }
954 // end
955 print(v);
956 }
957 '''); 932 ''');
958 _createRefactoringForStartEndComments(); 933 _createRefactoringForStartEndComments();
959 // apply refactoring 934 // apply refactoring
960 await assertRefactoringConditionsOK(); 935 await assertRefactoringConditionsOK();
961 expect(refactoring.createGetter, false); 936 expect(refactoring.createGetter, false);
962 } 937 }
963 938
964 test_getExtractGetter_true_simpleBlock() async {
965 indexTestUnit('''
966 main() {
967 // start
968 int v = 1 + 2;
969 // end
970 print(v);
971 }
972 ''');
973 _createRefactoringForStartEndComments();
974 // apply refactoring
975 await assertRefactoringConditionsOK();
976 expect(refactoring.createGetter, true);
977 }
978
979 test_getExtractGetter_true_singleExpression() async {
980 indexTestUnit('''
981 main() {
982 // start
983 int v = 1 + 2;
984 // end
985 print(v);
986 }
987 ''');
988 _createRefactoringForString('1 + 2');
989 // apply refactoring
990 await assertRefactoringConditionsOK();
991 expect(refactoring.createGetter, true);
992 }
993
994 test_getRefactoringName_function() { 939 test_getRefactoringName_function() {
995 indexTestUnit(''' 940 indexTestUnit('''
996 main() { 941 main() {
997 print(1 + 2); 942 print(1 + 2);
998 } 943 }
999 '''); 944 ''');
1000 _createRefactoringForString('1 + 2'); 945 _createRefactoringForString('1 + 2');
1001 expect(refactoring.refactoringName, 'Extract Function'); 946 expect(refactoring.refactoringName, 'Extract Function');
1002 } 947 }
1003 948
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 } 983 }
1039 '''); 984 ''');
1040 _createRefactoringForString('1 + 2'); 985 _createRefactoringForString('1 + 2');
1041 // apply refactoring 986 // apply refactoring
1042 await refactoring.checkInitialConditions(); 987 await refactoring.checkInitialConditions();
1043 expect(refactoring.offsets, 988 expect(refactoring.offsets,
1044 unorderedEquals([findOffset('1 + 2'), findOffset('1 + 2')])); 989 unorderedEquals([findOffset('1 + 2'), findOffset('1 + 2')]));
1045 expect(refactoring.lengths, unorderedEquals([5, 6])); 990 expect(refactoring.lengths, unorderedEquals([5, 6]));
1046 } 991 }
1047 992
993 test_returnType_closure() async {
994 indexTestUnit('''
995 process(f(x)) {}
996 main() {
997 process((x) => x * 2);
998 }
999 ''');
1000 _createRefactoringForString('(x) => x * 2');
1001 // do check
1002 await refactoring.checkInitialConditions();
1003 expect(refactoring.returnType, '');
1004 }
1005
1048 test_returnType_expression() async { 1006 test_returnType_expression() async {
1049 indexTestUnit(''' 1007 indexTestUnit('''
1050 main() { 1008 main() {
1051 int a = 1 + 2; 1009 int a = 1 + 2;
1052 } 1010 }
1053 '''); 1011 ''');
1054 _createRefactoringForString('1 + 2'); 1012 _createRefactoringForString('1 + 2');
1055 // do check 1013 // do check
1056 await refactoring.checkInitialConditions(); 1014 await refactoring.checkInitialConditions();
1057 expect(refactoring.returnType, 'int'); 1015 expect(refactoring.returnType, 'int');
1058 } 1016 }
1059 1017
1060 test_returnType_statements() async { 1018 test_returnType_statements() async {
1061 indexTestUnit(''' 1019 indexTestUnit('''
1062 main() { 1020 main() {
1063 // start 1021 // start
1064 double v = 5.0; 1022 double v = 5.0;
1065 // end 1023 // end
1066 print(v); 1024 print(v);
1067 } 1025 }
1068 '''); 1026 ''');
1069 _createRefactoringForStartEndComments(); 1027 _createRefactoringForStartEndComments();
1070 // do check 1028 // do check
1071 await refactoring.checkInitialConditions(); 1029 await refactoring.checkInitialConditions();
1072 expect(refactoring.returnType, 'double'); 1030 expect(refactoring.returnType, 'double');
1073 } 1031 }
1074 1032
1075 test_returnType_closure() async {
1076 indexTestUnit('''
1077 process(f(x)) {}
1078 main() {
1079 process((x) => x * 2);
1080 }
1081 ''');
1082 _createRefactoringForString('(x) => x * 2');
1083 // do check
1084 await refactoring.checkInitialConditions();
1085 expect(refactoring.returnType, '');
1086 }
1087
1088 test_returnType_statements_nullMix() async { 1033 test_returnType_statements_nullMix() async {
1089 indexTestUnit(''' 1034 indexTestUnit('''
1090 main(bool p) { 1035 main(bool p) {
1091 // start 1036 // start
1092 if (p) { 1037 if (p) {
1093 return 42; 1038 return 42;
1094 } 1039 }
1095 return null; 1040 return null;
1096 // end 1041 // end
1097 } 1042 }
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2552 * Returns a deep copy of [refactoring] parameters. 2497 * Returns a deep copy of [refactoring] parameters.
2553 * There was a bug masked by updating parameter instances shared between the 2498 * There was a bug masked by updating parameter instances shared between the
2554 * refactoring and the test. 2499 * refactoring and the test.
2555 */ 2500 */
2556 List<RefactoringMethodParameter> _getParametersCopy() { 2501 List<RefactoringMethodParameter> _getParametersCopy() {
2557 return refactoring.parameters.map((p) { 2502 return refactoring.parameters.map((p) {
2558 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); 2503 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id);
2559 }).toList(); 2504 }).toList();
2560 } 2505 }
2561 } 2506 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/refactoring/extract_method.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698