| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017, 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 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 6 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 7 import 'package:test/test.dart'; |
| 8 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 9 |
| 10 import '../support/integration_tests.dart'; |
| 11 |
| 12 main() { |
| 13 defineReflectiveSuite(() { |
| 14 defineReflectiveTests(GetRefactoringTest); |
| 15 }); |
| 16 } |
| 17 |
| 18 @reflectiveTest |
| 19 class GetRefactoringTest extends AbstractAnalysisServerIntegrationTest { |
| 20 test_rename() async { |
| 21 String pathname = sourcePath('test.dart'); |
| 22 String text = r''' |
| 23 void foo() { } |
| 24 |
| 25 void bar() { |
| 26 foo(); |
| 27 foo(); |
| 28 } |
| 29 '''; |
| 30 writeFile(pathname, text); |
| 31 standardAnalysisSetup(); |
| 32 |
| 33 await analysisFinished; |
| 34 expect(currentAnalysisErrors[pathname], isEmpty); |
| 35 |
| 36 // expect no edits if no rename options specified |
| 37 EditGetRefactoringResult result = await sendEditGetRefactoring( |
| 38 RefactoringKind.RENAME, pathname, text.indexOf('foo('), 0, false); |
| 39 expect(result.initialProblems, isEmpty); |
| 40 expect(result.optionsProblems, isEmpty); |
| 41 expect(result.finalProblems, isEmpty); |
| 42 expect(result.potentialEdits, isNull); |
| 43 expect(result.change, isNull); |
| 44 |
| 45 // expect a valid rename refactoring |
| 46 result = await sendEditGetRefactoring( |
| 47 RefactoringKind.RENAME, pathname, text.indexOf('foo('), 0, false, |
| 48 options: new RenameOptions('baz')); |
| 49 expect(result.initialProblems, isEmpty); |
| 50 expect(result.optionsProblems, isEmpty); |
| 51 expect(result.finalProblems, isEmpty); |
| 52 expect(result.potentialEdits, isNull); |
| 53 expect(result.change.edits, isNotEmpty); |
| 54 |
| 55 // apply the refactoring, expect that the new code has no errors |
| 56 SourceChange change = result.change; |
| 57 expect(change.edits.first.edits, isNotEmpty); |
| 58 for (SourceEdit edit in change.edits.first.edits) { |
| 59 text = text.replaceRange(edit.offset, edit.end, edit.replacement); |
| 60 } |
| 61 await sendAnalysisUpdateContent({pathname: new AddContentOverlay(text)}); |
| 62 |
| 63 await analysisFinished; |
| 64 expect(currentAnalysisErrors[pathname], isEmpty); |
| 65 } |
| 66 } |
| OLD | NEW |