| 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/refactoring/inline_local.dart'; | 9 import 'package:analysis_server/src/services/refactoring/inline_local.dart'; |
| 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 10 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 10 import '../../reflective_tests.dart'; | |
| 11 import 'package:analyzer/src/generated/ast.dart'; | |
| 12 import 'package:analyzer/src/generated/element.dart'; | |
| 13 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 14 | 12 |
| 13 import '../../reflective_tests.dart'; |
| 15 import 'abstract_refactoring.dart'; | 14 import 'abstract_refactoring.dart'; |
| 16 | 15 |
| 17 | 16 |
| 18 main() { | 17 main() { |
| 19 groupSep = ' | '; | 18 groupSep = ' | '; |
| 20 runReflectiveTests(InlineLocalTest); | 19 runReflectiveTests(InlineLocalTest); |
| 21 } | 20 } |
| 22 | 21 |
| 23 | 22 |
| 24 @ReflectiveTestCase() | 23 @ReflectiveTestCase() |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 191 } |
| 193 '''); | 192 '''); |
| 194 _createRefactoring('test ='); | 193 _createRefactoring('test ='); |
| 195 expect(refactoring.refactoringName, 'Inline Local Variable'); | 194 expect(refactoring.refactoringName, 'Inline Local Variable'); |
| 196 // check initial conditions and access | 195 // check initial conditions and access |
| 197 return refactoring.checkInitialConditions().then((_) { | 196 return refactoring.checkInitialConditions().then((_) { |
| 198 expect(refactoring.referenceCount, 2); | 197 expect(refactoring.referenceCount, 2); |
| 199 }); | 198 }); |
| 200 } | 199 } |
| 201 | 200 |
| 201 test_bad_selectionMethod() { |
| 202 indexTestUnit(r''' |
| 203 main() { |
| 204 } |
| 205 '''); |
| 206 _createRefactoring('main() {'); |
| 207 return refactoring.checkInitialConditions().then((status) { |
| 208 _assert_fatalError_selection(status); |
| 209 }); |
| 210 } |
| 211 |
| 212 test_bad_selectionParameter() { |
| 213 indexTestUnit(r''' |
| 214 main(int test) { |
| 215 } |
| 216 '''); |
| 217 _createRefactoring('test) {'); |
| 218 return refactoring.checkInitialConditions().then((status) { |
| 219 _assert_fatalError_selection(status); |
| 220 }); |
| 221 } |
| 222 |
| 202 test_bad_selectionVariable_hasAssignments_1() { | 223 test_bad_selectionVariable_hasAssignments_1() { |
| 203 indexTestUnit(r''' | 224 indexTestUnit(r''' |
| 204 main() { | 225 main() { |
| 205 int test = 0; | 226 int test = 0; |
| 206 test = 1; | 227 test = 1; |
| 207 } | 228 } |
| 208 '''); | 229 '''); |
| 209 _createRefactoring('test = 0'); | 230 _createRefactoring('test = 0'); |
| 210 return refactoring.checkInitialConditions().then((status) { | 231 return refactoring.checkInitialConditions().then((status) { |
| 211 assertRefactoringStatus( | 232 assertRefactoringStatus( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 main() { | 270 main() { |
| 250 int test; | 271 int test; |
| 251 } | 272 } |
| 252 '''); | 273 '''); |
| 253 _createRefactoring('test;'); | 274 _createRefactoring('test;'); |
| 254 return refactoring.checkInitialConditions().then((status) { | 275 return refactoring.checkInitialConditions().then((status) { |
| 255 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); | 276 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); |
| 256 }); | 277 }); |
| 257 } | 278 } |
| 258 | 279 |
| 280 void _assert_fatalError_selection(RefactoringStatus status) { |
| 281 assertRefactoringStatus( |
| 282 status, |
| 283 RefactoringProblemSeverity.FATAL, |
| 284 expectedMessage: 'Local variable declaration or reference must be ' |
| 285 'selected to activate this refactoring.'); |
| 286 } |
| 287 |
| 259 void _createRefactoring(String search) { | 288 void _createRefactoring(String search) { |
| 260 SimpleIdentifier identifier = findIdentifier(search); | 289 int offset = findOffset(search); |
| 261 LocalVariableElement element = identifier.bestElement; | 290 refactoring = new InlineLocalRefactoring(searchEngine, testUnit, offset); |
| 262 refactoring = new InlineLocalRefactoring(searchEngine, testUnit, element); | |
| 263 } | 291 } |
| 264 } | 292 } |
| OLD | NEW |