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 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/protocol2.dart' show SourceEdit; | 9 import 'package:analysis_server/src/protocol2.dart' show SourceEdit, |
| 10 SourceFileEdit; |
10 import 'package:analysis_server/src/services/correction/change.dart'; | 11 import 'package:analysis_server/src/services/correction/change.dart'; |
11 import 'package:analysis_server/src/services/correction/namespace.dart'; | 12 import 'package:analysis_server/src/services/correction/namespace.dart'; |
12 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
13 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
14 import 'package:analyzer/src/generated/ast.dart'; | 15 import 'package:analyzer/src/generated/ast.dart'; |
15 import 'package:analyzer/src/generated/element.dart'; | 16 import 'package:analyzer/src/generated/element.dart'; |
16 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
17 import 'package:unittest/unittest.dart'; | 18 import 'package:unittest/unittest.dart'; |
18 | 19 |
19 import 'abstract_refactoring.dart'; | 20 import 'abstract_refactoring.dart'; |
20 | 21 |
21 | 22 |
22 /** | 23 /** |
23 * The base class for all [RenameRefactoring] tests. | 24 * The base class for all [RenameRefactoring] tests. |
24 */ | 25 */ |
25 class RenameRefactoringTest extends RefactoringTest { | 26 class RenameRefactoringTest extends RefactoringTest { |
26 RenameRefactoring refactoring; | 27 RenameRefactoring refactoring; |
27 | 28 |
28 /** | 29 /** |
29 * Asserts that [refactoringChange] contains a [FileEdit] for the file | 30 * Asserts that [refactoringChange] contains a [FileEdit] for the file |
30 * with the given [path], and it results the [expectedCode]. | 31 * with the given [path], and it results the [expectedCode]. |
31 */ | 32 */ |
32 void assertFileChangeResult(String path, String expectedCode) { | 33 void assertFileChangeResult(String path, String expectedCode) { |
33 // prepare FileEdit | 34 // prepare FileEdit |
34 FileEdit fileEdit = refactoringChange.getFileEdit(path); | 35 SourceFileEdit fileEdit = refactoringChange.getFileEdit(path); |
35 expect(fileEdit, isNotNull); | 36 expect(fileEdit, isNotNull); |
36 // validate resulting code | 37 // validate resulting code |
37 File file = provider.getResource(path); | 38 File file = provider.getResource(path); |
38 Source source = file.createSource(); | 39 Source source = file.createSource(); |
39 String ini = context.getContents(source).data; | 40 String ini = context.getContents(source).data; |
40 String actualCode = SourceEdit.applySequence(ini, fileEdit.edits); | 41 String actualCode = SourceEdit.applySequence(ini, fileEdit.edits); |
41 expect(actualCode, expectedCode); | 42 expect(actualCode, expectedCode); |
42 } | 43 } |
43 | 44 |
44 /** | 45 /** |
45 * Asserts that [refactoringChange] does not contain a [FileEdit] for the file | 46 * Asserts that [refactoringChange] does not contain a [FileEdit] for the file |
46 * with the given [path]. | 47 * with the given [path]. |
47 */ | 48 */ |
48 void assertNoFileChange(String path) { | 49 void assertNoFileChange(String path) { |
49 FileEdit fileEdit = refactoringChange.getFileEdit(path); | 50 SourceFileEdit fileEdit = refactoringChange.getFileEdit(path); |
50 expect(fileEdit, isNull); | 51 expect(fileEdit, isNull); |
51 } | 52 } |
52 | 53 |
53 /** | 54 /** |
54 * Asserts that [refactoring] has potential edits in [testFile] at offset | 55 * Asserts that [refactoring] has potential edits in [testFile] at offset |
55 * of the given [searches]. | 56 * of the given [searches]. |
56 */ | 57 */ |
57 void assertPotentialEdits(List<String> searches) { | 58 void assertPotentialEdits(List<String> searches) { |
58 Set<int> expectedOffsets = new Set<int>(); | 59 Set<int> expectedOffsets = new Set<int>(); |
59 for (String search in searches) { | 60 for (String search in searches) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 */ | 103 */ |
103 void createRenameRefactoringForElement(Element element) { | 104 void createRenameRefactoringForElement(Element element) { |
104 refactoring = new RenameRefactoring(searchEngine, element); | 105 refactoring = new RenameRefactoring(searchEngine, element); |
105 expect(refactoring, isNotNull, reason: "No refactoring for '$element'."); | 106 expect(refactoring, isNotNull, reason: "No refactoring for '$element'."); |
106 } | 107 } |
107 | 108 |
108 /** | 109 /** |
109 * Returns the [Edit] with the given [id], maybe `null`. | 110 * Returns the [Edit] with the given [id], maybe `null`. |
110 */ | 111 */ |
111 SourceEdit findEditById(String id) { | 112 SourceEdit findEditById(String id) { |
112 for (FileEdit fileEdit in refactoringChange.fileEdits) { | 113 for (SourceFileEdit fileEdit in refactoringChange.fileEdits) { |
113 for (SourceEdit edit in fileEdit.edits) { | 114 for (SourceEdit edit in fileEdit.edits) { |
114 if (edit.id == id) { | 115 if (edit.id == id) { |
115 return edit; | 116 return edit; |
116 } | 117 } |
117 } | 118 } |
118 } | 119 } |
119 return null; | 120 return null; |
120 } | 121 } |
121 | 122 |
122 // /** | 123 // /** |
(...skipping 10 matching lines...) Expand all Loading... |
133 // void assertChangeResult(Change change, Source source, String expected) | 134 // void assertChangeResult(Change change, Source source, String expected) |
134 // { | 135 // { |
135 // SourceChange sourceChange = getSourceChange(compositeChange, source); | 136 // SourceChange sourceChange = getSourceChange(compositeChange, source); |
136 // assertNotNull("No change for: " + source.toString(), sourceChange); | 137 // assertNotNull("No change for: " + source.toString(), sourceChange); |
137 // String sourceResult = getChangeResult(context, source, sourceChange); | 138 // String sourceResult = getChangeResult(context, source, sourceChange); |
138 // assertEquals(expected, sourceResult); | 139 // assertEquals(expected, sourceResult); |
139 //// AnalysisContext context = getAnalysisContext(); | 140 //// AnalysisContext context = getAnalysisContext(); |
140 //// assertChangeResult(context, compositeChange, source, expected); | 141 //// assertChangeResult(context, compositeChange, source, expected); |
141 // } | 142 // } |
142 } | 143 } |
OLD | NEW |