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

Unified Diff: pkg/analysis_server/test/services/refactoring/extract_local_test.dart

Issue 2267893002: Fix for 'Extract Local' in an expression function body. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/services/refactoring/extract_local_test.dart
diff --git a/pkg/analysis_server/test/services/refactoring/extract_local_test.dart b/pkg/analysis_server/test/services/refactoring/extract_local_test.dart
index 0ced2882853f2a39c6eea0dd81d2ae7fe38e5ac0..a40c510ae53cca035c63f9b87ac998107a765ba5 100644
--- a/pkg/analysis_server/test/services/refactoring/extract_local_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/extract_local_test.dart
@@ -113,7 +113,7 @@ int a = 1 + 2;
RefactoringStatus status = await refactoring.checkAllConditions();
assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL,
expectedMessage:
- 'Expression inside of function must be selected to activate this refactoring.');
+ 'Expression inside a function must be selected to activate this refactoring.');
}
test_checkInitialConditions_stringSelection_leadingQuote() async {
@@ -953,7 +953,7 @@ main(p) {
''');
}
- test_singleExpression_inExpressionBody() async {
+ test_singleExpression_inExpressionBody_ofClosure() async {
indexTestUnit('''
main() {
print((x) => x.y * x.y + 1);
@@ -973,6 +973,46 @@ main() {
length: 3, offsets: [31, 53, 59], names: ['y']);
}
+ test_singleExpression_inExpressionBody_ofFunction() async {
+ indexTestUnit('''
+foo(Point p) => p.x * p.x + p.y * p.y;
+class Point {int x; int y;}
+''');
+ _createRefactoringForString('p.x');
+ // apply refactoring
+ await _assertSuccessfulRefactoring('''
+foo(Point p) {
+ var res = p.x;
+ return res * res + p.y * p.y;
+}
+class Point {int x; int y;}
+''');
+ _assertSingleLinkedEditGroup(
+ length: 3, offsets: [21, 41, 47], names: ['x', 'i']);
+ }
+
+ test_singleExpression_inExpressionBody_ofMethod() async {
+ indexTestUnit('''
+class A {
+ foo(Point p) => p.x * p.x + p.y * p.y;
+}
+class Point {int x; int y;}
+''');
+ _createRefactoringForString('p.x');
+ // apply refactoring
+ await _assertSuccessfulRefactoring('''
+class A {
+ foo(Point p) {
+ var res = p.x;
+ return res * res + p.y * p.y;
+ }
+}
+class Point {int x; int y;}
+''');
+ _assertSingleLinkedEditGroup(
+ length: 3, offsets: [35, 57, 63], names: ['x', 'i']);
+ }
+
test_singleExpression_inIfElseIf() {
indexTestUnit('''
main(int p) {

Powered by Google App Engine
This is Rietveld 408576698