| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. |
| 7 |
| 8 library test.services.refactoring.rename_local; |
| 9 |
| 10 import 'package:analysis_services/correction/change.dart'; |
| 11 import 'package:analysis_services/correction/status.dart'; |
| 12 import 'package:analysis_services/index/index.dart'; |
| 13 import 'package:analysis_services/index/local_memory_index.dart'; |
| 14 import 'package:analysis_services/refactoring/refactoring.dart'; |
| 15 import 'package:analysis_services/search/search_engine.dart'; |
| 16 import 'package:analysis_services/src/correction/source_range.dart'; |
| 17 import 'package:analysis_services/src/search/search_engine.dart'; |
| 18 import 'package:analysis_testing/abstract_single_unit.dart'; |
| 19 import 'package:analysis_testing/reflective_tests.dart'; |
| 20 import 'package:analyzer/src/generated/ast.dart'; |
| 21 import 'package:analyzer/src/generated/element.dart'; |
| 22 import 'package:analyzer/src/generated/source.dart'; |
| 23 import 'package:typed_mock/typed_mock.dart'; |
| 24 import 'package:unittest/unittest.dart'; |
| 25 |
| 26 |
| 27 |
| 28 main() { |
| 29 groupSep = ' | '; |
| 30 runReflectiveTests(RenameLocalTest); |
| 31 } |
| 32 |
| 33 |
| 34 @ReflectiveTestCase() |
| 35 class RenameLocalTest extends RenameRefactoringTest { |
| 36 void test_createChange_localVariable() { |
| 37 indexTestUnit(''' |
| 38 main() { |
| 39 int test = 0; |
| 40 test = 1; |
| 41 test += 2; |
| 42 print(test); |
| 43 } |
| 44 '''); |
| 45 // configure refactoring |
| 46 createRenameRefactoringAtString('test = 0'); |
| 47 print(refactoring.refactoringName); |
| 48 expect(refactoring.refactoringName, 'Rename Local Variable'); |
| 49 refactoring.newName = 'newName'; |
| 50 // validate change |
| 51 // TODO(scheglov) |
| 52 // assertSuccessfulRename( |
| 53 // "// filler filler filler filler filler filler filler filler filler fil
ler", |
| 54 // "main() {", |
| 55 // " int newName = 0;", |
| 56 // " newName = 1;", |
| 57 // " newName += 2;", |
| 58 // " print(newName);", |
| 59 // "}"); |
| 60 } |
| 61 } |
| 62 |
| 63 |
| 64 /** |
| 65 * The base class for all [RenameRefactoring] tests. |
| 66 * |
| 67 * TODO(scheglov) extract |
| 68 */ |
| 69 class RenameRefactoringTest extends AbstractSingleUnitTest { |
| 70 Index index; |
| 71 SearchEngineImpl searchEngine; |
| 72 |
| 73 RenameRefactoring refactoring; |
| 74 Change refactoringChange; |
| 75 |
| 76 /** |
| 77 * Creates a new [RenameRefactoring] in [refactoringC] for the [Element] of |
| 78 * the [SimpleIdentifier] at the given [search] pattern. |
| 79 */ |
| 80 void createRenameRefactoringAtString(String search) { |
| 81 SimpleIdentifier identifier = findIdentifier(search); |
| 82 Element element = identifier.bestElement; |
| 83 // TODO(scheglov) uncomment later |
| 84 // if (element instanceof PrefixElement) { |
| 85 // element = IndexContributor.getImportElement(identifier); |
| 86 // } |
| 87 refactoring = new RenameRefactoring(searchEngine, element); |
| 88 expect(refactoring, isNotNull); |
| 89 } |
| 90 |
| 91 void indexTestUnit(String code) { |
| 92 resolveTestUnit(code); |
| 93 index.indexUnit(context, testUnit); |
| 94 } |
| 95 |
| 96 void setUp() { |
| 97 super.setUp(); |
| 98 index = createLocalMemoryIndex(); |
| 99 searchEngine = new SearchEngineImpl(index); |
| 100 } |
| 101 } |
| OLD | NEW |