Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: pkg/analysis_server/test/src/plugin/result_converter_test.dart

Issue 2689903002: Add conversion routines from the plugin API to the server API (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/plugin/protocol/protocol.dart' as server;
6 import 'package:analysis_server/src/plugin/result_converter.dart';
7 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server;
8 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
9 import 'package:test/test.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart';
11
12 main() {
13 defineReflectiveSuite(() {
14 defineReflectiveTests(ResultConverterTest);
15 });
16 }
17
18 @reflectiveTest
19 class ResultConverterTest {
20 static const List<String> strings = const <String>[
21 'a',
22 'b',
23 'c',
24 'd',
25 'e',
26 'f',
27 'g',
28 'h',
29 'i',
30 'j',
31 'k',
32 'l',
33 'm',
34 'n'
35 ];
36
37 ResultConverter converter = new ResultConverter();
38
39 void test_convertAnalysisError() {
40 plugin.AnalysisError initial = _pluginAnalysisError();
41 server.AnalysisError expected = _serverAnalysisError();
42 expect(converter.convertAnalysisError(initial), expected);
43 }
44
45 void test_convertAnalysisErrorFixes() {
46 plugin.AnalysisErrorFixes initial = new plugin.AnalysisErrorFixes(
47 _pluginAnalysisError(),
48 fixes: <plugin.PrioritizedSourceChange>[
49 new plugin.PrioritizedSourceChange(100, _pluginSourceChange())
50 ]);
51 server.AnalysisErrorFixes expected = new server.AnalysisErrorFixes(
52 _serverAnalysisError(),
53 fixes: <server.SourceChange>[_serverSourceChange()]);
54 expect(converter.convertAnalysisErrorFixes(initial), expected);
55 }
56
57 void test_convertAnalysisNavigationParams() {
58 plugin.AnalysisNavigationParams initial =
59 new plugin.AnalysisNavigationParams('a.dart', <plugin.NavigationRegion>[
60 new plugin.NavigationRegion(1, 2, <int>[3, 4])
61 ], <plugin.NavigationTarget>[
62 new plugin.NavigationTarget(plugin.ElementKind.FIELD, 5, 6, 7, 8, 9)
63 ], <String>[
64 'a',
65 'b'
66 ]);
67 server.AnalysisNavigationParams expected =
68 new server.AnalysisNavigationParams('a.dart', <server.NavigationRegion>[
69 new server.NavigationRegion(1, 2, <int>[3, 4])
70 ], <server.NavigationTarget>[
71 new server.NavigationTarget(server.ElementKind.FIELD, 5, 6, 7, 8, 9)
72 ], <String>[
73 'a',
74 'b'
75 ]);
76 expect(converter.convertAnalysisNavigationParams(initial), expected);
77 }
78
79 void test_convertCompletionSuggestion() {
80 plugin.CompletionSuggestion initial = new plugin.CompletionSuggestion(
81 plugin.CompletionSuggestionKind.IMPORT, 1, 'a', 2, 3, true, false,
82 docSummary: 'b',
83 docComplete: 'c',
84 declaringType: 'd',
85 element: _pluginElement(4, 4),
86 returnType: 'i',
87 parameterNames: <String>['j', 'k'],
88 parameterTypes: <String>[],
89 requiredParameterCount: 9,
90 hasNamedParameters: true,
91 parameterName: 'l',
92 parameterType: 'm',
93 importUri: 'n');
94 server.CompletionSuggestion expected = new server.CompletionSuggestion(
95 server.CompletionSuggestionKind.IMPORT, 1, 'a', 2, 3, true, false,
96 docSummary: 'b',
97 docComplete: 'c',
98 declaringType: 'd',
99 element: _serverElement(4, 4),
100 returnType: 'i',
101 parameterNames: <String>['j', 'k'],
102 parameterTypes: <String>[],
103 requiredParameterCount: 9,
104 hasNamedParameters: true,
105 parameterName: 'l',
106 parameterType: 'm',
107 importUri: 'n');
108 expect(converter.convertCompletionSuggestion(initial), expected);
109 }
110
111 void test_convertEditGetRefactoringResult_inlineMethod() {
112 plugin.EditGetRefactoringResult initial =
113 new plugin.EditGetRefactoringResult(
114 <plugin.RefactoringProblem>[_pluginRefactoringProblem('a', 1)],
115 <plugin.RefactoringProblem>[_pluginRefactoringProblem('b', 5)],
116 <plugin.RefactoringProblem>[_pluginRefactoringProblem('c', 9)],
117 feedback:
118 new plugin.InlineMethodFeedback('a', true, className: 'b'),
119 change: _pluginSourceChange(),
120 potentialEdits: <String>['f']);
121 server.EditGetRefactoringResult expected =
122 new server.EditGetRefactoringResult(
123 <server.RefactoringProblem>[_serverRefactoringProblem('a', 1)],
124 <server.RefactoringProblem>[_serverRefactoringProblem('b', 5)],
125 <server.RefactoringProblem>[_serverRefactoringProblem('c', 9)],
126 feedback:
127 new server.InlineMethodFeedback('a', true, className: 'b'),
128 change: _serverSourceChange(),
129 potentialEdits: <String>['f']);
130 expect(
131 converter.convertEditGetRefactoringResult(
132 plugin.RefactoringKind.INLINE_METHOD, initial),
133 expected);
134 }
135
136 void test_convertEditGetRefactoringResult_moveFile() {
137 plugin.EditGetRefactoringResult initial =
138 new plugin.EditGetRefactoringResult(
139 <plugin.RefactoringProblem>[_pluginRefactoringProblem('a', 1)],
140 <plugin.RefactoringProblem>[_pluginRefactoringProblem('b', 5)],
141 <plugin.RefactoringProblem>[_pluginRefactoringProblem('c', 9)],
142 feedback: new plugin.MoveFileFeedback(),
143 change: _pluginSourceChange(),
144 potentialEdits: <String>['f']);
145 server.EditGetRefactoringResult expected =
146 new server.EditGetRefactoringResult(
147 <server.RefactoringProblem>[_serverRefactoringProblem('a', 1)],
148 <server.RefactoringProblem>[_serverRefactoringProblem('b', 5)],
149 <server.RefactoringProblem>[_serverRefactoringProblem('c', 9)],
150 change: _serverSourceChange(),
151 potentialEdits: <String>['f']);
152 expect(
153 converter.convertEditGetRefactoringResult(
154 plugin.RefactoringKind.MOVE_FILE, initial),
155 expected);
156 }
157
158 void test_convertFoldingRegion() {
159 plugin.FoldingRegion initial =
160 new plugin.FoldingRegion(plugin.FoldingKind.COMMENT, 1, 2);
161 server.FoldingRegion expected =
162 new server.FoldingRegion(server.FoldingKind.COMMENT, 1, 2);
163 expect(converter.convertFoldingRegion(initial), expected);
164 }
165
166 void test_convertHighlightRegion() {
167 plugin.HighlightRegion initial =
168 new plugin.HighlightRegion(plugin.HighlightRegionType.FIELD, 1, 2);
169 server.HighlightRegion expected =
170 new server.HighlightRegion(server.HighlightRegionType.FIELD, 1, 2);
171 expect(converter.convertHighlightRegion(initial), expected);
172 }
173
174 void test_convertOccurrences() {
175 plugin.Occurrences initial =
176 new plugin.Occurrences(_pluginElement(1, 1), <int>[6, 7], 8);
177 server.Occurrences expected =
178 new server.Occurrences(_serverElement(1, 1), <int>[6, 7], 8);
179 expect(converter.convertOccurrences(initial), expected);
180 }
181
182 void test_convertOutline() {
183 plugin.Outline initial = new plugin.Outline(_pluginElement(1, 1), 6, 7,
184 children: <plugin.Outline>[
185 new plugin.Outline(_pluginElement(6, 8), 14, 15)
186 ]);
187 server.Outline expected = new server.Outline(_serverElement(1, 1), 6, 7,
188 children: <server.Outline>[
189 new server.Outline(_serverElement(6, 8), 14, 15)
190 ]);
191 expect(converter.convertOutline(initial), expected);
192 }
193
194 void test_convertPrioritizedSourceChange() {
195 plugin.PrioritizedSourceChange initial =
196 new plugin.PrioritizedSourceChange(100, _pluginSourceChange());
197 server.SourceChange expected = _serverSourceChange();
198 expect(converter.convertPrioritizedSourceChange(initial), expected);
199 }
200
201 void test_convertRefactoringFeedback_convertGetterToMethod() {
202 plugin.ConvertGetterToMethodFeedback initial =
203 new plugin.ConvertGetterToMethodFeedback();
204 expect(
205 converter.convertRefactoringFeedback(
206 plugin.RefactoringKind.CONVERT_GETTER_TO_METHOD, initial),
207 isNull);
208 }
209
210 void test_convertRefactoringFeedback_convertMethodToGetter() {
211 plugin.ConvertMethodToGetterFeedback initial =
212 new plugin.ConvertMethodToGetterFeedback();
213 expect(
214 converter.convertRefactoringFeedback(
215 plugin.RefactoringKind.CONVERT_METHOD_TO_GETTER, initial),
216 isNull);
217 }
218
219 void test_convertRefactoringFeedback_extractLocalVariable() {
220 plugin.ExtractLocalVariableFeedback initial =
221 new plugin.ExtractLocalVariableFeedback(
222 <String>['a', 'b'], <int>[1, 2], <int>[3],
223 coveringExpressionOffsets: <int>[4, 5],
224 coveringExpressionLengths: <int>[6]);
225 server.ExtractLocalVariableFeedback expected =
226 new server.ExtractLocalVariableFeedback(
227 <String>['a', 'b'], <int>[1, 2], <int>[3],
228 coveringExpressionOffsets: <int>[4, 5],
229 coveringExpressionLengths: <int>[6]);
230 expect(
231 converter.convertRefactoringFeedback(
232 plugin.RefactoringKind.EXTRACT_LOCAL_VARIABLE, initial),
233 expected);
234 }
235
236 void test_convertRefactoringFeedback_extractMethod() {
237 plugin.ExtractMethodFeedback initial = new plugin.ExtractMethodFeedback(
238 1,
239 2,
240 'a',
241 <String>['b', 'c'],
242 true,
243 <plugin.RefactoringMethodParameter>[
244 new plugin.RefactoringMethodParameter(
245 plugin.RefactoringMethodParameterKind.NAMED, 'd', 'e',
246 id: 'f', parameters: 'g')
247 ],
248 <int>[3, 4],
249 <int>[5, 6]);
250 server.ExtractMethodFeedback expected = new server.ExtractMethodFeedback(
251 1,
252 2,
253 'a',
254 <String>['b', 'c'],
255 true,
256 <server.RefactoringMethodParameter>[
257 new server.RefactoringMethodParameter(
258 server.RefactoringMethodParameterKind.NAMED, 'd', 'e',
259 id: 'f', parameters: 'g')
260 ],
261 <int>[3, 4],
262 <int>[5, 6]);
263 expect(
264 converter.convertRefactoringFeedback(
265 plugin.RefactoringKind.EXTRACT_METHOD, initial),
266 expected);
267 }
268
269 void test_convertRefactoringFeedback_inlineLocalVariable() {
270 plugin.InlineLocalVariableFeedback initial =
271 new plugin.InlineLocalVariableFeedback('a', 1);
272 server.InlineLocalVariableFeedback expected =
273 new server.InlineLocalVariableFeedback('a', 1);
274 expect(
275 converter.convertRefactoringFeedback(
276 plugin.RefactoringKind.INLINE_LOCAL_VARIABLE, initial),
277 expected);
278 }
279
280 void test_convertRefactoringFeedback_inlineMethod() {
281 plugin.InlineMethodFeedback initial =
282 new plugin.InlineMethodFeedback('a', true, className: 'b');
283 server.InlineMethodFeedback expected =
284 new server.InlineMethodFeedback('a', true, className: 'b');
285 expect(
286 converter.convertRefactoringFeedback(
287 plugin.RefactoringKind.INLINE_METHOD, initial),
288 expected);
289 }
290
291 void test_convertRefactoringFeedback_moveFile() {
292 plugin.MoveFileFeedback initial = new plugin.MoveFileFeedback();
293 expect(
294 converter.convertRefactoringFeedback(
295 plugin.RefactoringKind.MOVE_FILE, initial),
296 isNull);
297 }
298
299 void test_convertRefactoringFeedback_rename() {
300 plugin.RenameFeedback initial = new plugin.RenameFeedback(1, 2, 'a', 'b');
301 server.RenameFeedback expected = new server.RenameFeedback(1, 2, 'a', 'b');
302 expect(
303 converter.convertRefactoringFeedback(
304 plugin.RefactoringKind.RENAME, initial),
305 expected);
306 }
307
308 void test_convertRefactoringKind() {
309 Map<plugin.RefactoringKind, server.RefactoringKind> kindMap =
310 <plugin.RefactoringKind, server.RefactoringKind>{
311 plugin.RefactoringKind.CONVERT_GETTER_TO_METHOD:
312 server.RefactoringKind.CONVERT_GETTER_TO_METHOD,
313 plugin.RefactoringKind.CONVERT_METHOD_TO_GETTER:
314 server.RefactoringKind.CONVERT_METHOD_TO_GETTER,
315 plugin.RefactoringKind.EXTRACT_LOCAL_VARIABLE:
316 server.RefactoringKind.EXTRACT_LOCAL_VARIABLE,
317 plugin.RefactoringKind.EXTRACT_METHOD:
318 server.RefactoringKind.EXTRACT_METHOD,
319 plugin.RefactoringKind.INLINE_LOCAL_VARIABLE:
320 server.RefactoringKind.INLINE_LOCAL_VARIABLE,
321 plugin.RefactoringKind.INLINE_LOCAL_VARIABLE:
322 server.RefactoringKind.INLINE_LOCAL_VARIABLE,
323 plugin.RefactoringKind.MOVE_FILE: server.RefactoringKind.MOVE_FILE,
324 plugin.RefactoringKind.RENAME: server.RefactoringKind.RENAME,
325 plugin.RefactoringKind.SORT_MEMBERS: server.RefactoringKind.SORT_MEMBERS,
326 };
327 kindMap.forEach(
328 (plugin.RefactoringKind pluginKind, server.RefactoringKind serverKind) {
329 expect(converter.convertRefactoringKind(pluginKind), serverKind);
330 });
331 }
332
333 void test_convertSourceChange() {
334 plugin.SourceChange initial = _pluginSourceChange();
335 server.SourceChange expected = _serverSourceChange();
336 expect(converter.convertSourceChange(initial), expected);
337 }
338
339 String _fileName(int index) => '${strings[index]}.dart';
340
341 plugin.AnalysisError _pluginAnalysisError() => new plugin.AnalysisError(
342 plugin.AnalysisErrorSeverity.ERROR,
343 plugin.AnalysisErrorType.COMPILE_TIME_ERROR,
344 new plugin.Location('a.dart', 1, 2, 3, 4),
345 'm',
346 'c',
347 correction: 'n',
348 hasFix: true);
349
350 /**
351 * On return, increment [stringIndex] by 5 and [intIndex] by 5.
352 */
353 plugin.Element _pluginElement(int stringIndex, int intIndex) =>
354 new plugin.Element(
355 plugin.ElementKind.CLASS, strings[stringIndex++], intIndex++,
356 location: new plugin.Location(_fileName(stringIndex++), intIndex++,
357 intIndex++, intIndex++, intIndex++),
358 parameters: strings[stringIndex++],
359 returnType: strings[stringIndex++],
360 typeParameters: strings[stringIndex++]);
361
362 plugin.Location _pluginLocation(String baseName, int index) =>
363 new plugin.Location(
364 '$baseName.dart', index, index + 1, index + 2, index + 3);
365
366 plugin.RefactoringProblem _pluginRefactoringProblem(
367 String baseName, int index) =>
368 new plugin.RefactoringProblem(
369 plugin.RefactoringProblemSeverity.FATAL, baseName,
370 location: _pluginLocation(baseName, index));
371
372 plugin.SourceChange _pluginSourceChange() => new plugin.SourceChange('m',
373 edits: <plugin.SourceFileEdit>[
374 new plugin.SourceFileEdit('a.dart', 1,
375 edits: <plugin.SourceEdit>[new plugin.SourceEdit(2, 3, 'r')])
376 ],
377 linkedEditGroups: <plugin.LinkedEditGroup>[
378 new plugin.LinkedEditGroup(
379 <plugin.Position>[new plugin.Position('b.dart', 4)],
380 5,
381 <plugin.LinkedEditSuggestion>[
382 new plugin.LinkedEditSuggestion(
383 'v', plugin.LinkedEditSuggestionKind.METHOD)
384 ])
385 ],
386 selection: new plugin.Position('c.dart', 6));
387
388 server.AnalysisError _serverAnalysisError() {
389 return new server.AnalysisError(
390 server.AnalysisErrorSeverity.ERROR,
391 server.AnalysisErrorType.COMPILE_TIME_ERROR,
392 new server.Location('a.dart', 1, 2, 3, 4),
393 'm',
394 'c',
395 correction: 'n',
396 hasFix: true);
397 }
398
399 /**
400 * On return, increment [stringIndex] by 5 and [intIndex] by 5.
401 */
402 server.Element _serverElement(int stringIndex, int intIndex) =>
403 new server.Element(
404 server.ElementKind.CLASS, strings[stringIndex++], intIndex++,
405 location: new server.Location(_fileName(stringIndex++), intIndex++,
406 intIndex++, intIndex++, intIndex++),
407 parameters: strings[stringIndex++],
408 returnType: strings[stringIndex++],
409 typeParameters: strings[stringIndex++]);
410
411 server.Location _serverLocation(String baseName, int index) =>
412 new server.Location(
413 '$baseName.dart', index, index + 1, index + 2, index + 3);
414
415 server.RefactoringProblem _serverRefactoringProblem(
416 String baseName, int index) =>
417 new server.RefactoringProblem(
418 server.RefactoringProblemSeverity.FATAL, baseName,
419 location: _serverLocation(baseName, index));
420
421 server.SourceChange _serverSourceChange() => new server.SourceChange('m',
422 edits: <server.SourceFileEdit>[
423 new server.SourceFileEdit('a.dart', 1,
424 edits: <server.SourceEdit>[new server.SourceEdit(2, 3, 'r')])
425 ],
426 linkedEditGroups: <server.LinkedEditGroup>[
427 new server.LinkedEditGroup(
428 <server.Position>[new server.Position('b.dart', 4)],
429 5,
430 <server.LinkedEditSuggestion>[
431 new server.LinkedEditSuggestion(
432 'v', server.LinkedEditSuggestionKind.METHOD)
433 ])
434 ],
435 selection: new server.Position('c.dart', 6));
436 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/plugin/result_converter.dart ('k') | pkg/analysis_server/test/src/plugin/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698