OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'package:analysis_server/protocol/protocol_generated.dart' as server; | 5 import 'package:analysis_server/protocol/protocol_generated.dart' as server; |
6 import 'package:analysis_server/src/plugin/result_converter.dart'; | 6 import 'package:analysis_server/src/plugin/result_converter.dart'; |
7 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server; | 7 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server; |
8 import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin; | 8 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
9 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; | 9 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
11 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
12 | 12 |
13 import 'protocol_test_utilities.dart'; | 13 import 'protocol_test_utilities.dart'; |
14 | 14 |
15 main() { | 15 main() { |
16 defineReflectiveSuite(() { | 16 defineReflectiveSuite(() { |
17 defineReflectiveTests(ResultConverterTest); | 17 defineReflectiveTests(ResultConverterTest); |
18 }); | 18 }); |
(...skipping 13 matching lines...) Expand all Loading... |
32 'i', | 32 'i', |
33 'j', | 33 'j', |
34 'k', | 34 'k', |
35 'l', | 35 'l', |
36 'm', | 36 'm', |
37 'n' | 37 'n' |
38 ]; | 38 ]; |
39 | 39 |
40 ResultConverter converter = new ResultConverter(); | 40 ResultConverter converter = new ResultConverter(); |
41 | 41 |
42 void test_convertAnalysisError() { | |
43 plugin.AnalysisError initial = pluginAnalysisError(0, 0); | |
44 server.AnalysisError expected = serverAnalysisError(0, 0); | |
45 expect(converter.convertAnalysisError(initial), expected); | |
46 } | |
47 | |
48 void test_convertAnalysisErrorFixes() { | 42 void test_convertAnalysisErrorFixes() { |
49 plugin.AnalysisErrorFixes initial = new plugin.AnalysisErrorFixes( | 43 plugin.AnalysisErrorFixes initial = new plugin.AnalysisErrorFixes( |
50 pluginAnalysisError(0, 0), | 44 pluginAnalysisError(0, 0), |
51 fixes: <plugin.PrioritizedSourceChange>[ | 45 fixes: <plugin.PrioritizedSourceChange>[ |
52 new plugin.PrioritizedSourceChange(100, pluginSourceChange(4, 4)) | 46 new plugin.PrioritizedSourceChange(100, pluginSourceChange(4, 4)) |
53 ]); | 47 ]); |
54 server.AnalysisErrorFixes expected = new server.AnalysisErrorFixes( | 48 server.AnalysisErrorFixes expected = new server.AnalysisErrorFixes( |
55 serverAnalysisError(0, 0), | 49 serverAnalysisError(0, 0), |
56 fixes: <server.SourceChange>[serverSourceChange(4, 4)]); | 50 fixes: <SourceChange>[serverSourceChange(4, 4)]); |
57 expect(converter.convertAnalysisErrorFixes(initial), expected); | 51 expect(converter.convertAnalysisErrorFixes(initial), expected); |
58 } | 52 } |
59 | 53 |
60 void test_convertAnalysisNavigationParams() { | 54 void test_convertAnalysisNavigationParams() { |
61 plugin.AnalysisNavigationParams initial = | 55 plugin.AnalysisNavigationParams initial = |
62 new plugin.AnalysisNavigationParams('a.dart', <plugin.NavigationRegion>[ | 56 new plugin.AnalysisNavigationParams('a.dart', <NavigationRegion>[ |
63 new plugin.NavigationRegion(1, 2, <int>[3, 4]) | 57 new NavigationRegion(1, 2, <int>[3, 4]) |
64 ], <plugin.NavigationTarget>[ | 58 ], <NavigationTarget>[ |
65 new plugin.NavigationTarget(plugin.ElementKind.FIELD, 5, 6, 7, 8, 9) | 59 new NavigationTarget(ElementKind.FIELD, 5, 6, 7, 8, 9) |
66 ], <String>[ | 60 ], <String>[ |
67 'a', | 61 'a', |
68 'b' | 62 'b' |
69 ]); | 63 ]); |
70 server.AnalysisNavigationParams expected = | 64 server.AnalysisNavigationParams expected = |
71 new server.AnalysisNavigationParams('a.dart', <server.NavigationRegion>[ | 65 new server.AnalysisNavigationParams('a.dart', <NavigationRegion>[ |
72 new server.NavigationRegion(1, 2, <int>[3, 4]) | 66 new NavigationRegion(1, 2, <int>[3, 4]) |
73 ], <server.NavigationTarget>[ | 67 ], <NavigationTarget>[ |
74 new server.NavigationTarget(server.ElementKind.FIELD, 5, 6, 7, 8, 9) | 68 new NavigationTarget(ElementKind.FIELD, 5, 6, 7, 8, 9) |
75 ], <String>[ | 69 ], <String>[ |
76 'a', | 70 'a', |
77 'b' | 71 'b' |
78 ]); | 72 ]); |
79 expect(converter.convertAnalysisNavigationParams(initial), expected); | 73 expect(converter.convertAnalysisNavigationParams(initial), expected); |
80 } | 74 } |
81 | 75 |
82 void test_convertCompletionSuggestion() { | |
83 plugin.CompletionSuggestion initial = new plugin.CompletionSuggestion( | |
84 plugin.CompletionSuggestionKind.IMPORT, 1, 'a', 2, 3, true, false, | |
85 docSummary: 'b', | |
86 docComplete: 'c', | |
87 declaringType: 'd', | |
88 element: pluginElement(4, 4), | |
89 returnType: 'i', | |
90 parameterNames: <String>['j', 'k'], | |
91 parameterTypes: <String>[], | |
92 requiredParameterCount: 9, | |
93 hasNamedParameters: true, | |
94 parameterName: 'l', | |
95 parameterType: 'm', | |
96 importUri: 'n'); | |
97 server.CompletionSuggestion expected = new server.CompletionSuggestion( | |
98 server.CompletionSuggestionKind.IMPORT, 1, 'a', 2, 3, true, false, | |
99 docSummary: 'b', | |
100 docComplete: 'c', | |
101 declaringType: 'd', | |
102 element: serverElement(4, 4), | |
103 returnType: 'i', | |
104 parameterNames: <String>['j', 'k'], | |
105 parameterTypes: <String>[], | |
106 requiredParameterCount: 9, | |
107 hasNamedParameters: true, | |
108 parameterName: 'l', | |
109 parameterType: 'm', | |
110 importUri: 'n'); | |
111 expect(converter.convertCompletionSuggestion(initial), expected); | |
112 } | |
113 | |
114 void test_convertEditGetRefactoringResult_inlineMethod() { | 76 void test_convertEditGetRefactoringResult_inlineMethod() { |
115 plugin.EditGetRefactoringResult initial = | 77 plugin.EditGetRefactoringResult initial = |
116 new plugin.EditGetRefactoringResult( | 78 new plugin.EditGetRefactoringResult( |
117 <plugin.RefactoringProblem>[pluginRefactoringProblem(0, 0)], | 79 <RefactoringProblem>[pluginRefactoringProblem(0, 0)], |
118 <plugin.RefactoringProblem>[pluginRefactoringProblem(2, 4)], | 80 <RefactoringProblem>[pluginRefactoringProblem(2, 4)], |
119 <plugin.RefactoringProblem>[pluginRefactoringProblem(4, 8)], | 81 <RefactoringProblem>[pluginRefactoringProblem(4, 8)], |
120 feedback: | 82 feedback: |
121 new plugin.InlineMethodFeedback('a', true, className: 'b'), | 83 new plugin.InlineMethodFeedback('a', true, className: 'b'), |
122 change: pluginSourceChange(6, 12), | 84 change: pluginSourceChange(6, 12), |
123 potentialEdits: <String>['f']); | 85 potentialEdits: <String>['f']); |
124 server.EditGetRefactoringResult expected = | 86 server.EditGetRefactoringResult expected = |
125 new server.EditGetRefactoringResult( | 87 new server.EditGetRefactoringResult( |
126 <server.RefactoringProblem>[serverRefactoringProblem(0, 0)], | 88 <RefactoringProblem>[serverRefactoringProblem(0, 0)], |
127 <server.RefactoringProblem>[serverRefactoringProblem(2, 4)], | 89 <RefactoringProblem>[serverRefactoringProblem(2, 4)], |
128 <server.RefactoringProblem>[serverRefactoringProblem(4, 8)], | 90 <RefactoringProblem>[serverRefactoringProblem(4, 8)], |
129 feedback: | 91 feedback: |
130 new server.InlineMethodFeedback('a', true, className: 'b'), | 92 new server.InlineMethodFeedback('a', true, className: 'b'), |
131 change: serverSourceChange(6, 12), | 93 change: serverSourceChange(6, 12), |
132 potentialEdits: <String>['f']); | 94 potentialEdits: <String>['f']); |
133 expect( | 95 expect( |
134 converter.convertEditGetRefactoringResult( | 96 converter.convertEditGetRefactoringResult( |
135 plugin.RefactoringKind.INLINE_METHOD, initial), | 97 RefactoringKind.INLINE_METHOD, initial), |
136 expected); | 98 expected); |
137 } | 99 } |
138 | 100 |
139 void test_convertEditGetRefactoringResult_moveFile() { | 101 void test_convertEditGetRefactoringResult_moveFile() { |
140 plugin.EditGetRefactoringResult initial = | 102 plugin.EditGetRefactoringResult initial = |
141 new plugin.EditGetRefactoringResult( | 103 new plugin.EditGetRefactoringResult( |
142 <plugin.RefactoringProblem>[pluginRefactoringProblem(0, 0)], | 104 <RefactoringProblem>[pluginRefactoringProblem(0, 0)], |
143 <plugin.RefactoringProblem>[pluginRefactoringProblem(2, 4)], | 105 <RefactoringProblem>[pluginRefactoringProblem(2, 4)], |
144 <plugin.RefactoringProblem>[pluginRefactoringProblem(4, 8)], | 106 <RefactoringProblem>[pluginRefactoringProblem(4, 8)], |
145 feedback: new plugin.MoveFileFeedback(), | 107 feedback: new plugin.MoveFileFeedback(), |
146 change: pluginSourceChange(6, 12), | 108 change: pluginSourceChange(6, 12), |
147 potentialEdits: <String>['f']); | 109 potentialEdits: <String>['f']); |
148 server.EditGetRefactoringResult expected = | 110 server.EditGetRefactoringResult expected = |
149 new server.EditGetRefactoringResult( | 111 new server.EditGetRefactoringResult( |
150 <server.RefactoringProblem>[serverRefactoringProblem(0, 0)], | 112 <RefactoringProblem>[serverRefactoringProblem(0, 0)], |
151 <server.RefactoringProblem>[serverRefactoringProblem(2, 4)], | 113 <RefactoringProblem>[serverRefactoringProblem(2, 4)], |
152 <server.RefactoringProblem>[serverRefactoringProblem(4, 8)], | 114 <RefactoringProblem>[serverRefactoringProblem(4, 8)], |
153 change: serverSourceChange(6, 12), | 115 change: serverSourceChange(6, 12), |
154 potentialEdits: <String>['f']); | 116 potentialEdits: <String>['f']); |
155 expect( | 117 expect( |
156 converter.convertEditGetRefactoringResult( | 118 converter.convertEditGetRefactoringResult( |
157 plugin.RefactoringKind.MOVE_FILE, initial), | 119 RefactoringKind.MOVE_FILE, initial), |
158 expected); | 120 expected); |
159 } | 121 } |
160 | 122 |
161 void test_convertFoldingRegion() { | |
162 plugin.FoldingRegion initial = pluginFoldingRegion(1, 2); | |
163 server.FoldingRegion expected = serverFoldingRegion(1, 2); | |
164 expect(converter.convertFoldingRegion(initial), expected); | |
165 } | |
166 | |
167 void test_convertHighlightRegion() { | |
168 plugin.HighlightRegion initial = pluginHighlightRegion(1, 2); | |
169 server.HighlightRegion expected = serverHighlightRegion(1, 2); | |
170 expect(converter.convertHighlightRegion(initial), expected); | |
171 } | |
172 | |
173 void test_convertOccurrences() { | |
174 plugin.Occurrences initial = pluginOccurrences(1, 1); | |
175 server.Occurrences expected = serverOccurrences(1, 1); | |
176 expect(converter.convertOccurrences(initial), expected); | |
177 } | |
178 | |
179 void test_convertOutline() { | |
180 plugin.Outline initial = new plugin.Outline(pluginElement(1, 1), 6, 7, | |
181 children: <plugin.Outline>[ | |
182 new plugin.Outline(pluginElement(6, 8), 14, 15) | |
183 ]); | |
184 server.Outline expected = new server.Outline(serverElement(1, 1), 6, 7, | |
185 children: <server.Outline>[ | |
186 new server.Outline(serverElement(6, 8), 14, 15) | |
187 ]); | |
188 expect(converter.convertOutline(initial), expected); | |
189 } | |
190 | |
191 void test_convertPrioritizedSourceChange() { | 123 void test_convertPrioritizedSourceChange() { |
192 plugin.PrioritizedSourceChange initial = | 124 plugin.PrioritizedSourceChange initial = |
193 new plugin.PrioritizedSourceChange(100, pluginSourceChange(0, 0)); | 125 new plugin.PrioritizedSourceChange(100, pluginSourceChange(0, 0)); |
194 server.SourceChange expected = serverSourceChange(0, 0); | 126 SourceChange expected = serverSourceChange(0, 0); |
195 expect(converter.convertPrioritizedSourceChange(initial), expected); | 127 expect(converter.convertPrioritizedSourceChange(initial), expected); |
196 } | 128 } |
197 | |
198 void test_convertRefactoringFeedback_convertGetterToMethod() { | |
199 plugin.ConvertGetterToMethodFeedback initial = | |
200 new plugin.ConvertGetterToMethodFeedback(); | |
201 expect( | |
202 converter.convertRefactoringFeedback( | |
203 plugin.RefactoringKind.CONVERT_GETTER_TO_METHOD, initial), | |
204 isNull); | |
205 } | |
206 | |
207 void test_convertRefactoringFeedback_convertMethodToGetter() { | |
208 plugin.ConvertMethodToGetterFeedback initial = | |
209 new plugin.ConvertMethodToGetterFeedback(); | |
210 expect( | |
211 converter.convertRefactoringFeedback( | |
212 plugin.RefactoringKind.CONVERT_METHOD_TO_GETTER, initial), | |
213 isNull); | |
214 } | |
215 | |
216 void test_convertRefactoringFeedback_extractLocalVariable() { | |
217 plugin.ExtractLocalVariableFeedback initial = | |
218 new plugin.ExtractLocalVariableFeedback( | |
219 <String>['a', 'b'], <int>[1, 2], <int>[3], | |
220 coveringExpressionOffsets: <int>[4, 5], | |
221 coveringExpressionLengths: <int>[6]); | |
222 server.ExtractLocalVariableFeedback expected = | |
223 new server.ExtractLocalVariableFeedback( | |
224 <String>['a', 'b'], <int>[1, 2], <int>[3], | |
225 coveringExpressionOffsets: <int>[4, 5], | |
226 coveringExpressionLengths: <int>[6]); | |
227 expect( | |
228 converter.convertRefactoringFeedback( | |
229 plugin.RefactoringKind.EXTRACT_LOCAL_VARIABLE, initial), | |
230 expected); | |
231 } | |
232 | |
233 void test_convertRefactoringFeedback_extractMethod() { | |
234 plugin.ExtractMethodFeedback initial = new plugin.ExtractMethodFeedback( | |
235 1, | |
236 2, | |
237 'a', | |
238 <String>['b', 'c'], | |
239 true, | |
240 <plugin.RefactoringMethodParameter>[ | |
241 new plugin.RefactoringMethodParameter( | |
242 plugin.RefactoringMethodParameterKind.NAMED, 'd', 'e', | |
243 id: 'f', parameters: 'g') | |
244 ], | |
245 <int>[3, 4], | |
246 <int>[5, 6]); | |
247 server.ExtractMethodFeedback expected = new server.ExtractMethodFeedback( | |
248 1, | |
249 2, | |
250 'a', | |
251 <String>['b', 'c'], | |
252 true, | |
253 <server.RefactoringMethodParameter>[ | |
254 new server.RefactoringMethodParameter( | |
255 server.RefactoringMethodParameterKind.NAMED, 'd', 'e', | |
256 id: 'f', parameters: 'g') | |
257 ], | |
258 <int>[3, 4], | |
259 <int>[5, 6]); | |
260 expect( | |
261 converter.convertRefactoringFeedback( | |
262 plugin.RefactoringKind.EXTRACT_METHOD, initial), | |
263 expected); | |
264 } | |
265 | |
266 void test_convertRefactoringFeedback_inlineLocalVariable() { | |
267 plugin.InlineLocalVariableFeedback initial = | |
268 new plugin.InlineLocalVariableFeedback('a', 1); | |
269 server.InlineLocalVariableFeedback expected = | |
270 new server.InlineLocalVariableFeedback('a', 1); | |
271 expect( | |
272 converter.convertRefactoringFeedback( | |
273 plugin.RefactoringKind.INLINE_LOCAL_VARIABLE, initial), | |
274 expected); | |
275 } | |
276 | |
277 void test_convertRefactoringFeedback_inlineMethod() { | |
278 plugin.InlineMethodFeedback initial = | |
279 new plugin.InlineMethodFeedback('a', true, className: 'b'); | |
280 server.InlineMethodFeedback expected = | |
281 new server.InlineMethodFeedback('a', true, className: 'b'); | |
282 expect( | |
283 converter.convertRefactoringFeedback( | |
284 plugin.RefactoringKind.INLINE_METHOD, initial), | |
285 expected); | |
286 } | |
287 | |
288 void test_convertRefactoringFeedback_moveFile() { | |
289 plugin.MoveFileFeedback initial = new plugin.MoveFileFeedback(); | |
290 expect( | |
291 converter.convertRefactoringFeedback( | |
292 plugin.RefactoringKind.MOVE_FILE, initial), | |
293 isNull); | |
294 } | |
295 | |
296 void test_convertRefactoringFeedback_rename() { | |
297 plugin.RenameFeedback initial = new plugin.RenameFeedback(1, 2, 'a', 'b'); | |
298 server.RenameFeedback expected = new server.RenameFeedback(1, 2, 'a', 'b'); | |
299 expect( | |
300 converter.convertRefactoringFeedback( | |
301 plugin.RefactoringKind.RENAME, initial), | |
302 expected); | |
303 } | |
304 | |
305 void test_convertRefactoringKind() { | |
306 Map<plugin.RefactoringKind, server.RefactoringKind> kindMap = | |
307 <plugin.RefactoringKind, server.RefactoringKind>{ | |
308 plugin.RefactoringKind.CONVERT_GETTER_TO_METHOD: | |
309 server.RefactoringKind.CONVERT_GETTER_TO_METHOD, | |
310 plugin.RefactoringKind.CONVERT_METHOD_TO_GETTER: | |
311 server.RefactoringKind.CONVERT_METHOD_TO_GETTER, | |
312 plugin.RefactoringKind.EXTRACT_LOCAL_VARIABLE: | |
313 server.RefactoringKind.EXTRACT_LOCAL_VARIABLE, | |
314 plugin.RefactoringKind.EXTRACT_METHOD: | |
315 server.RefactoringKind.EXTRACT_METHOD, | |
316 plugin.RefactoringKind.INLINE_LOCAL_VARIABLE: | |
317 server.RefactoringKind.INLINE_LOCAL_VARIABLE, | |
318 plugin.RefactoringKind.INLINE_METHOD: | |
319 server.RefactoringKind.INLINE_METHOD, | |
320 plugin.RefactoringKind.MOVE_FILE: server.RefactoringKind.MOVE_FILE, | |
321 plugin.RefactoringKind.RENAME: server.RefactoringKind.RENAME, | |
322 plugin.RefactoringKind.SORT_MEMBERS: server.RefactoringKind.SORT_MEMBERS, | |
323 }; | |
324 kindMap.forEach( | |
325 (plugin.RefactoringKind pluginKind, server.RefactoringKind serverKind) { | |
326 expect(converter.convertRefactoringKind(pluginKind), serverKind); | |
327 }); | |
328 } | |
329 | |
330 void test_convertSourceChange() { | |
331 plugin.SourceChange initial = pluginSourceChange(0, 0); | |
332 server.SourceChange expected = serverSourceChange(0, 0); | |
333 expect(converter.convertSourceChange(initial), expected); | |
334 } | |
335 } | 129 } |
OLD | NEW |