| 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.inline_local; | 5 library test.services.refactoring.inline_local; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart' hide Element; | 7 import 'package:analysis_server/src/protocol.dart' hide Element; |
| 8 import 'package:analysis_server/src/services/correction/status.dart'; | 8 import 'package:analysis_server/src/services/correction/status.dart'; |
| 9 import 'package:analysis_server/src/services/refactoring/inline_local.dart'; | 9 import 'package:analysis_server/src/services/refactoring/inline_local.dart'; |
| 10 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 10 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 | 12 |
| 13 import '../../reflective_tests.dart'; | 13 import '../../reflective_tests.dart'; |
| 14 import 'abstract_refactoring.dart'; | 14 import 'abstract_refactoring.dart'; |
| 15 | 15 |
| 16 | 16 |
| 17 main() { | 17 main() { |
| 18 groupSep = ' | '; | 18 groupSep = ' | '; |
| 19 runReflectiveTests(InlineLocalTest); | 19 runReflectiveTests(InlineLocalTest); |
| 20 } | 20 } |
| 21 | 21 |
| 22 | 22 |
| 23 @reflectiveTest | 23 @reflectiveTest |
| 24 class InlineLocalTest extends RefactoringTest { | 24 class InlineLocalTest extends RefactoringTest { |
| 25 InlineLocalRefactoringImpl refactoring; | 25 InlineLocalRefactoringImpl refactoring; |
| 26 | 26 |
| 27 test_access() { | 27 test_access() async { |
| 28 indexTestUnit(''' | 28 indexTestUnit(''' |
| 29 main() { | 29 main() { |
| 30 int test = 1 + 2; | 30 int test = 1 + 2; |
| 31 print(test); | 31 print(test); |
| 32 print(test); | 32 print(test); |
| 33 } | 33 } |
| 34 '''); | 34 '''); |
| 35 _createRefactoring('test ='); | 35 _createRefactoring('test ='); |
| 36 expect(refactoring.refactoringName, 'Inline Local Variable'); | 36 expect(refactoring.refactoringName, 'Inline Local Variable'); |
| 37 // check initial conditions and access | 37 // check initial conditions and access |
| 38 return refactoring.checkInitialConditions().then((_) { | 38 await refactoring.checkInitialConditions(); |
| 39 expect(refactoring.variableName, 'test'); | 39 expect(refactoring.variableName, 'test'); |
| 40 expect(refactoring.referenceCount, 2); | 40 expect(refactoring.referenceCount, 2); |
| 41 }); | |
| 42 } | 41 } |
| 43 | 42 |
| 44 test_bad_selectionMethod() { | 43 test_bad_selectionMethod() async { |
| 45 indexTestUnit(r''' | 44 indexTestUnit(r''' |
| 46 main() { | 45 main() { |
| 47 } | 46 } |
| 48 '''); | 47 '''); |
| 49 _createRefactoring('main() {'); | 48 _createRefactoring('main() {'); |
| 50 return refactoring.checkInitialConditions().then((status) { | 49 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 51 _assert_fatalError_selection(status); | 50 _assert_fatalError_selection(status); |
| 52 }); | |
| 53 } | 51 } |
| 54 | 52 |
| 55 test_bad_selectionParameter() { | 53 test_bad_selectionParameter() async { |
| 56 indexTestUnit(r''' | 54 indexTestUnit(r''' |
| 57 main(int test) { | 55 main(int test) { |
| 58 } | 56 } |
| 59 '''); | 57 '''); |
| 60 _createRefactoring('test) {'); | 58 _createRefactoring('test) {'); |
| 61 return refactoring.checkInitialConditions().then((status) { | 59 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 62 _assert_fatalError_selection(status); | 60 _assert_fatalError_selection(status); |
| 63 }); | |
| 64 } | 61 } |
| 65 | 62 |
| 66 test_bad_selectionVariable_hasAssignments_1() { | 63 test_bad_selectionVariable_hasAssignments_1() async { |
| 67 indexTestUnit(r''' | 64 indexTestUnit(r''' |
| 68 main() { | 65 main() { |
| 69 int test = 0; | 66 int test = 0; |
| 70 test = 1; | 67 test = 1; |
| 71 } | 68 } |
| 72 '''); | 69 '''); |
| 73 _createRefactoring('test = 0'); | 70 _createRefactoring('test = 0'); |
| 74 return refactoring.checkInitialConditions().then((status) { | 71 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 75 assertRefactoringStatus( | 72 assertRefactoringStatus( |
| 76 status, | 73 status, |
| 77 RefactoringProblemSeverity.FATAL, | 74 RefactoringProblemSeverity.FATAL, |
| 78 expectedContextSearch: 'test = 1'); | 75 expectedContextSearch: 'test = 1'); |
| 79 }); | |
| 80 } | 76 } |
| 81 | 77 |
| 82 test_bad_selectionVariable_hasAssignments_2() { | 78 test_bad_selectionVariable_hasAssignments_2() async { |
| 83 indexTestUnit(r''' | 79 indexTestUnit(r''' |
| 84 main() { | 80 main() { |
| 85 int test = 0; | 81 int test = 0; |
| 86 test += 1; | 82 test += 1; |
| 87 } | 83 } |
| 88 '''); | 84 '''); |
| 89 _createRefactoring('test = 0'); | 85 _createRefactoring('test = 0'); |
| 90 return refactoring.checkInitialConditions().then((status) { | 86 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 91 assertRefactoringStatus( | 87 assertRefactoringStatus( |
| 92 status, | 88 status, |
| 93 RefactoringProblemSeverity.FATAL, | 89 RefactoringProblemSeverity.FATAL, |
| 94 expectedContextSearch: 'test += 1'); | 90 expectedContextSearch: 'test += 1'); |
| 95 }); | |
| 96 } | 91 } |
| 97 | 92 |
| 98 test_bad_selectionVariable_notInBlock() { | 93 test_bad_selectionVariable_notInBlock() async { |
| 99 indexTestUnit(r''' | 94 indexTestUnit(r''' |
| 100 main() { | 95 main() { |
| 101 if (true) | 96 if (true) |
| 102 int test = 0; | 97 int test = 0; |
| 103 } | 98 } |
| 104 '''); | 99 '''); |
| 105 _createRefactoring('test = 0'); | 100 _createRefactoring('test = 0'); |
| 106 return refactoring.checkInitialConditions().then((status) { | 101 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 107 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); | 102 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); |
| 108 }); | |
| 109 } | 103 } |
| 110 | 104 |
| 111 test_bad_selectionVariable_notInitialized() { | 105 test_bad_selectionVariable_notInitialized() async { |
| 112 indexTestUnit(r''' | 106 indexTestUnit(r''' |
| 113 main() { | 107 main() { |
| 114 int test; | 108 int test; |
| 115 } | 109 } |
| 116 '''); | 110 '''); |
| 117 _createRefactoring('test;'); | 111 _createRefactoring('test;'); |
| 118 return refactoring.checkInitialConditions().then((status) { | 112 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 119 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); | 113 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); |
| 120 }); | |
| 121 } | 114 } |
| 122 | 115 |
| 123 test_OK_cascade_intoCascade() { | 116 test_OK_cascade_intoCascade() { |
| 124 indexTestUnit(r''' | 117 indexTestUnit(r''' |
| 125 class A { | 118 class A { |
| 126 foo() {} | 119 foo() {} |
| 127 bar() {} | 120 bar() {} |
| 128 } | 121 } |
| 129 main() { | 122 main() { |
| 130 A test = new A()..foo(); | 123 A test = new A()..foo(); |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 RefactoringProblemSeverity.FATAL, | 577 RefactoringProblemSeverity.FATAL, |
| 585 expectedMessage: 'Local variable declaration or reference must be ' | 578 expectedMessage: 'Local variable declaration or reference must be ' |
| 586 'selected to activate this refactoring.'); | 579 'selected to activate this refactoring.'); |
| 587 } | 580 } |
| 588 | 581 |
| 589 void _createRefactoring(String search) { | 582 void _createRefactoring(String search) { |
| 590 int offset = findOffset(search); | 583 int offset = findOffset(search); |
| 591 refactoring = new InlineLocalRefactoring(searchEngine, testUnit, offset); | 584 refactoring = new InlineLocalRefactoring(searchEngine, testUnit, offset); |
| 592 } | 585 } |
| 593 } | 586 } |
| OLD | NEW |