| 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) {
|
|
|