| OLD | NEW |
| 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 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 10 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 test_checkInitialConditions_notPartOfFunction() async { | 107 test_checkInitialConditions_notPartOfFunction() async { |
| 108 indexTestUnit(''' | 108 indexTestUnit(''' |
| 109 int a = 1 + 2; | 109 int a = 1 + 2; |
| 110 '''); | 110 '''); |
| 111 _createRefactoringForString('1 + 2'); | 111 _createRefactoringForString('1 + 2'); |
| 112 // check conditions | 112 // check conditions |
| 113 RefactoringStatus status = await refactoring.checkAllConditions(); | 113 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 114 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 114 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 115 expectedMessage: | 115 expectedMessage: |
| 116 'Expression inside of function must be selected to activate this ref
actoring.'); | 116 'Expression inside a function must be selected to activate this refa
ctoring.'); |
| 117 } | 117 } |
| 118 | 118 |
| 119 test_checkInitialConditions_stringSelection_leadingQuote() async { | 119 test_checkInitialConditions_stringSelection_leadingQuote() async { |
| 120 indexTestUnit(''' | 120 indexTestUnit(''' |
| 121 main() { | 121 main() { |
| 122 var vvv = 'abc'; | 122 var vvv = 'abc'; |
| 123 } | 123 } |
| 124 '''); | 124 '''); |
| 125 _createRefactoringForString("'a"); | 125 _createRefactoringForString("'a"); |
| 126 // apply refactoring | 126 // apply refactoring |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 // apply refactoring | 946 // apply refactoring |
| 947 return _assertSuccessfulRefactoring(''' | 947 return _assertSuccessfulRefactoring(''' |
| 948 main(p) { | 948 main(p) { |
| 949 foo | 949 foo |
| 950 var res = p.bar; | 950 var res = p.bar; |
| 951 res.baz; | 951 res.baz; |
| 952 } | 952 } |
| 953 '''); | 953 '''); |
| 954 } | 954 } |
| 955 | 955 |
| 956 test_singleExpression_inExpressionBody() async { | 956 test_singleExpression_inExpressionBody_ofClosure() async { |
| 957 indexTestUnit(''' | 957 indexTestUnit(''' |
| 958 main() { | 958 main() { |
| 959 print((x) => x.y * x.y + 1); | 959 print((x) => x.y * x.y + 1); |
| 960 } | 960 } |
| 961 '''); | 961 '''); |
| 962 _createRefactoringForString('x.y'); | 962 _createRefactoringForString('x.y'); |
| 963 // apply refactoring | 963 // apply refactoring |
| 964 await _assertSuccessfulRefactoring(''' | 964 await _assertSuccessfulRefactoring(''' |
| 965 main() { | 965 main() { |
| 966 print((x) { | 966 print((x) { |
| 967 var res = x.y; | 967 var res = x.y; |
| 968 return res * res + 1; | 968 return res * res + 1; |
| 969 }); | 969 }); |
| 970 } | 970 } |
| 971 '''); | 971 '''); |
| 972 _assertSingleLinkedEditGroup( | 972 _assertSingleLinkedEditGroup( |
| 973 length: 3, offsets: [31, 53, 59], names: ['y']); | 973 length: 3, offsets: [31, 53, 59], names: ['y']); |
| 974 } | 974 } |
| 975 | 975 |
| 976 test_singleExpression_inExpressionBody_ofFunction() async { |
| 977 indexTestUnit(''' |
| 978 foo(Point p) => p.x * p.x + p.y * p.y; |
| 979 class Point {int x; int y;} |
| 980 '''); |
| 981 _createRefactoringForString('p.x'); |
| 982 // apply refactoring |
| 983 await _assertSuccessfulRefactoring(''' |
| 984 foo(Point p) { |
| 985 var res = p.x; |
| 986 return res * res + p.y * p.y; |
| 987 } |
| 988 class Point {int x; int y;} |
| 989 '''); |
| 990 _assertSingleLinkedEditGroup( |
| 991 length: 3, offsets: [21, 41, 47], names: ['x', 'i']); |
| 992 } |
| 993 |
| 994 test_singleExpression_inExpressionBody_ofMethod() async { |
| 995 indexTestUnit(''' |
| 996 class A { |
| 997 foo(Point p) => p.x * p.x + p.y * p.y; |
| 998 } |
| 999 class Point {int x; int y;} |
| 1000 '''); |
| 1001 _createRefactoringForString('p.x'); |
| 1002 // apply refactoring |
| 1003 await _assertSuccessfulRefactoring(''' |
| 1004 class A { |
| 1005 foo(Point p) { |
| 1006 var res = p.x; |
| 1007 return res * res + p.y * p.y; |
| 1008 } |
| 1009 } |
| 1010 class Point {int x; int y;} |
| 1011 '''); |
| 1012 _assertSingleLinkedEditGroup( |
| 1013 length: 3, offsets: [35, 57, 63], names: ['x', 'i']); |
| 1014 } |
| 1015 |
| 976 test_singleExpression_inIfElseIf() { | 1016 test_singleExpression_inIfElseIf() { |
| 977 indexTestUnit(''' | 1017 indexTestUnit(''' |
| 978 main(int p) { | 1018 main(int p) { |
| 979 if (p == 1) { | 1019 if (p == 1) { |
| 980 print(1); | 1020 print(1); |
| 981 } else if (p == 2) { | 1021 } else if (p == 2) { |
| 982 print(2); | 1022 print(2); |
| 983 } | 1023 } |
| 984 } | 1024 } |
| 985 '''); | 1025 '''); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 List<String> _getCoveringExpressions() { | 1339 List<String> _getCoveringExpressions() { |
| 1300 List<String> subExpressions = <String>[]; | 1340 List<String> subExpressions = <String>[]; |
| 1301 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { | 1341 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { |
| 1302 int offset = refactoring.coveringExpressionOffsets[i]; | 1342 int offset = refactoring.coveringExpressionOffsets[i]; |
| 1303 int length = refactoring.coveringExpressionLengths[i]; | 1343 int length = refactoring.coveringExpressionLengths[i]; |
| 1304 subExpressions.add(testCode.substring(offset, offset + length)); | 1344 subExpressions.add(testCode.substring(offset, offset + length)); |
| 1305 } | 1345 } |
| 1306 return subExpressions; | 1346 return subExpressions; |
| 1307 } | 1347 } |
| 1308 } | 1348 } |
| OLD | NEW |