| 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.rename; | 5 library test.services.refactoring.rename; |
| 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/namespace.dart'; | 8 import 'package:analysis_server/src/services/correction/namespace.dart'; |
| 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | |
| 11 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| 12 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | |
| 14 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
| 15 | 13 |
| 16 import 'abstract_refactoring.dart'; | 14 import 'abstract_refactoring.dart'; |
| 17 | 15 |
| 18 | 16 |
| 19 /** | 17 /** |
| 20 * The base class for all [RenameRefactoring] tests. | 18 * The base class for all [RenameRefactoring] tests. |
| 21 */ | 19 */ |
| 22 class RenameRefactoringTest extends RefactoringTest { | 20 class RenameRefactoringTest extends RefactoringTest { |
| 23 RenameRefactoring refactoring; | 21 RenameRefactoring refactoring; |
| 24 | 22 |
| 25 /** | 23 /** |
| 26 * Asserts that [refactoringChange] contains a [FileEdit] for the file | |
| 27 * with the given [path], and it results the [expectedCode]. | |
| 28 */ | |
| 29 void assertFileChangeResult(String path, String expectedCode) { | |
| 30 // prepare FileEdit | |
| 31 SourceFileEdit fileEdit = refactoringChange.getFileEdit(path); | |
| 32 expect(fileEdit, isNotNull); | |
| 33 // validate resulting code | |
| 34 File file = provider.getResource(path); | |
| 35 Source source = file.createSource(); | |
| 36 String ini = context.getContents(source).data; | |
| 37 String actualCode = SourceEdit.applySequence(ini, fileEdit.edits); | |
| 38 expect(actualCode, expectedCode); | |
| 39 } | |
| 40 | |
| 41 /** | |
| 42 * Asserts that [refactoringChange] does not contain a [FileEdit] for the file | |
| 43 * with the given [path]. | |
| 44 */ | |
| 45 void assertNoFileChange(String path) { | |
| 46 SourceFileEdit fileEdit = refactoringChange.getFileEdit(path); | |
| 47 expect(fileEdit, isNull); | |
| 48 } | |
| 49 | |
| 50 /** | |
| 51 * Asserts that [refactoring] has potential edits in [testFile] at offset | 24 * Asserts that [refactoring] has potential edits in [testFile] at offset |
| 52 * of the given [searches]. | 25 * of the given [searches]. |
| 53 */ | 26 */ |
| 54 void assertPotentialEdits(List<String> searches) { | 27 void assertPotentialEdits(List<String> searches) { |
| 55 Set<int> expectedOffsets = new Set<int>(); | 28 Set<int> expectedOffsets = new Set<int>(); |
| 56 for (String search in searches) { | 29 for (String search in searches) { |
| 57 int offset = findOffset(search); | 30 int offset = findOffset(search); |
| 58 expectedOffsets.add(offset); | 31 expectedOffsets.add(offset); |
| 59 } | 32 } |
| 60 // remove offset marked as potential | 33 // remove offset marked as potential |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // void assertChangeResult(Change change, Source source, String expected) | 90 // void assertChangeResult(Change change, Source source, String expected) |
| 118 // { | 91 // { |
| 119 // SourceChange sourceChange = getSourceChange(compositeChange, source); | 92 // SourceChange sourceChange = getSourceChange(compositeChange, source); |
| 120 // assertNotNull("No change for: " + source.toString(), sourceChange); | 93 // assertNotNull("No change for: " + source.toString(), sourceChange); |
| 121 // String sourceResult = getChangeResult(context, source, sourceChange); | 94 // String sourceResult = getChangeResult(context, source, sourceChange); |
| 122 // assertEquals(expected, sourceResult); | 95 // assertEquals(expected, sourceResult); |
| 123 //// AnalysisContext context = getAnalysisContext(); | 96 //// AnalysisContext context = getAnalysisContext(); |
| 124 //// assertChangeResult(context, compositeChange, source, expected); | 97 //// assertChangeResult(context, compositeChange, source, expected); |
| 125 // } | 98 // } |
| 126 } | 99 } |
| OLD | NEW |