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

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

Issue 695383002: Issue 21496. Fix for inlining negate/decrement into negate. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/refactoring/inline_local.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/services/refactoring/inline_local_test.dart
diff --git a/pkg/analysis_server/test/services/refactoring/inline_local_test.dart b/pkg/analysis_server/test/services/refactoring/inline_local_test.dart
index 17e0b73b2c7f1248934ed9ea0f73db346fb0a827..bbed0459d9fed41473f5dbaff6a28e4393f08ee4 100644
--- a/pkg/analysis_server/test/services/refactoring/inline_local_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/inline_local_test.dart
@@ -24,6 +24,102 @@ main() {
class InlineLocalTest extends RefactoringTest {
InlineLocalRefactoringImpl refactoring;
+ test_access() {
+ indexTestUnit('''
+main() {
+ int test = 1 + 2;
+ print(test);
+ print(test);
+}
+''');
+ _createRefactoring('test =');
+ expect(refactoring.refactoringName, 'Inline Local Variable');
+ // check initial conditions and access
+ return refactoring.checkInitialConditions().then((_) {
+ expect(refactoring.variableName, 'test');
+ expect(refactoring.referenceCount, 2);
+ });
+ }
+
+ test_bad_selectionMethod() {
+ indexTestUnit(r'''
+main() {
+}
+''');
+ _createRefactoring('main() {');
+ return refactoring.checkInitialConditions().then((status) {
+ _assert_fatalError_selection(status);
+ });
+ }
+
+ test_bad_selectionParameter() {
+ indexTestUnit(r'''
+main(int test) {
+}
+''');
+ _createRefactoring('test) {');
+ return refactoring.checkInitialConditions().then((status) {
+ _assert_fatalError_selection(status);
+ });
+ }
+
+ test_bad_selectionVariable_hasAssignments_1() {
+ indexTestUnit(r'''
+main() {
+ int test = 0;
+ test = 1;
+}
+''');
+ _createRefactoring('test = 0');
+ return refactoring.checkInitialConditions().then((status) {
+ assertRefactoringStatus(
+ status,
+ RefactoringProblemSeverity.FATAL,
+ expectedContextSearch: 'test = 1');
+ });
+ }
+
+ test_bad_selectionVariable_hasAssignments_2() {
+ indexTestUnit(r'''
+main() {
+ int test = 0;
+ test += 1;
+}
+''');
+ _createRefactoring('test = 0');
+ return refactoring.checkInitialConditions().then((status) {
+ assertRefactoringStatus(
+ status,
+ RefactoringProblemSeverity.FATAL,
+ expectedContextSearch: 'test += 1');
+ });
+ }
+
+ test_bad_selectionVariable_notInBlock() {
+ indexTestUnit(r'''
+main() {
+ if (true)
+ int test = 0;
+}
+''');
+ _createRefactoring('test = 0');
+ return refactoring.checkInitialConditions().then((status) {
+ assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL);
+ });
+ }
+
+ test_bad_selectionVariable_notInitialized() {
+ indexTestUnit(r'''
+main() {
+ int test;
+}
+''');
+ _createRefactoring('test;');
+ return refactoring.checkInitialConditions().then((status) {
+ assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL);
+ });
+ }
+
test_OK_cascade_intoCascade() {
indexTestUnit(r'''
class A {
@@ -118,24 +214,6 @@ process(x) {}
''');
}
- test_OK_intoStringInterpolation_stringInterpolation() {
- indexTestUnit(r'''
-main() {
- String a = 'aaa';
- String b = '$a bbb';
- String c = '$b ccc';
-}
-''');
- _createRefactoring('b =');
- // validate change
- return assertSuccessfulRefactoring(r'''
-main() {
- String a = 'aaa';
- String c = '$a bbb ccc';
-}
-''');
- }
-
test_OK_intoStringInterpolation_string_differentQuotes() {
indexTestUnit(r'''
main() {
@@ -298,6 +376,24 @@ main() {
''');
}
+ test_OK_intoStringInterpolation_stringInterpolation() {
+ indexTestUnit(r'''
+main() {
+ String a = 'aaa';
+ String b = '$a bbb';
+ String c = '$b ccc';
+}
+''');
+ _createRefactoring('b =');
+ // validate change
+ return assertSuccessfulRefactoring(r'''
+main() {
+ String a = 'aaa';
+ String c = '$a bbb ccc';
+}
+''');
+ }
+
/**
* <p>
* https://code.google.com/p/dart/issues/detail?id=18587
@@ -368,6 +464,24 @@ main() {
''');
}
+ test_OK_parenthesis_decrement_intoNegate() {
+ indexTestUnit('''
+main() {
+ var a = 1;
+ var test = --a;
+ var b = -test;
+}
+''');
+ _createRefactoring('test =');
+ // validate change
+ return assertSuccessfulRefactoring('''
+main() {
+ var a = 1;
+ var b = -(--a);
+}
+''');
+ }
+
test_OK_parenthesis_instanceCreation_intoList() {
indexTestUnit('''
class A {}
@@ -386,41 +500,41 @@ main() {
''');
}
- test_OK_parenthesis_plus_intoMultiply() {
+ test_OK_parenthesis_negate_intoNegate() {
indexTestUnit('''
main() {
- var test = 1 + 2;
- print(test * 3);
+ var a = 1;
+ var test = -a;
+ var b = -test;
}
''');
_createRefactoring('test =');
// validate change
return assertSuccessfulRefactoring('''
main() {
- print((1 + 2) * 3);
+ var a = 1;
+ var b = -(-a);
}
''');
}
- test_OK_twoUsages() {
+ test_OK_parenthesis_plus_intoMultiply() {
indexTestUnit('''
main() {
- int test = 1 + 2;
- print(test);
- print(test);
+ var test = 1 + 2;
+ print(test * 3);
}
''');
_createRefactoring('test =');
// validate change
return assertSuccessfulRefactoring('''
main() {
- print(1 + 2);
- print(1 + 2);
+ print((1 + 2) * 3);
}
''');
}
- test_access() {
+ test_OK_twoUsages() {
indexTestUnit('''
main() {
int test = 1 + 2;
@@ -429,91 +543,13 @@ main() {
}
''');
_createRefactoring('test =');
- expect(refactoring.refactoringName, 'Inline Local Variable');
- // check initial conditions and access
- return refactoring.checkInitialConditions().then((_) {
- expect(refactoring.variableName, 'test');
- expect(refactoring.referenceCount, 2);
- });
- }
-
- test_bad_selectionMethod() {
- indexTestUnit(r'''
-main() {
-}
-''');
- _createRefactoring('main() {');
- return refactoring.checkInitialConditions().then((status) {
- _assert_fatalError_selection(status);
- });
- }
-
- test_bad_selectionParameter() {
- indexTestUnit(r'''
-main(int test) {
-}
-''');
- _createRefactoring('test) {');
- return refactoring.checkInitialConditions().then((status) {
- _assert_fatalError_selection(status);
- });
- }
-
- test_bad_selectionVariable_hasAssignments_1() {
- indexTestUnit(r'''
-main() {
- int test = 0;
- test = 1;
-}
-''');
- _createRefactoring('test = 0');
- return refactoring.checkInitialConditions().then((status) {
- assertRefactoringStatus(
- status,
- RefactoringProblemSeverity.FATAL,
- expectedContextSearch: 'test = 1');
- });
- }
-
- test_bad_selectionVariable_hasAssignments_2() {
- indexTestUnit(r'''
-main() {
- int test = 0;
- test += 1;
-}
-''');
- _createRefactoring('test = 0');
- return refactoring.checkInitialConditions().then((status) {
- assertRefactoringStatus(
- status,
- RefactoringProblemSeverity.FATAL,
- expectedContextSearch: 'test += 1');
- });
- }
-
- test_bad_selectionVariable_notInBlock() {
- indexTestUnit(r'''
-main() {
- if (true)
- int test = 0;
-}
-''');
- _createRefactoring('test = 0');
- return refactoring.checkInitialConditions().then((status) {
- assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL);
- });
- }
-
- test_bad_selectionVariable_notInitialized() {
- indexTestUnit(r'''
+ // validate change
+ return assertSuccessfulRefactoring('''
main() {
- int test;
+ print(1 + 2);
+ print(1 + 2);
}
''');
- _createRefactoring('test;');
- return refactoring.checkInitialConditions().then((status) {
- assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL);
- });
}
void _assert_fatalError_selection(RefactoringStatus status) {
« no previous file with comments | « pkg/analysis_server/lib/src/services/refactoring/inline_local.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698