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

Side by Side Diff: pkg/analysis_server/test/services/correction/change_test.dart

Issue 497393002: Make more use of generated code in analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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.correction.change; 5 library test.services.correction.change;
6 6
7 import 'package:analysis_server/src/constants.dart'; 7 import 'package:analysis_server/src/constants.dart';
8 import 'package:analysis_server/src/protocol2.dart' show SourceEdit, 8 import 'package:analysis_server/src/protocol2.dart';
9 SourceFileEdit, Position;
10 import 'package:analysis_server/src/services/correction/change.dart';
11 import 'package:analysis_testing/reflective_tests.dart'; 9 import 'package:analysis_testing/reflective_tests.dart';
12 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
13 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
14 12
15 13
16 main() { 14 main() {
17 groupSep = ' | '; 15 groupSep = ' | ';
18 runReflectiveTests(ChangeTest); 16 runReflectiveTests(ChangeTest);
19 runReflectiveTests(EditTest); 17 runReflectiveTests(EditTest);
20 runReflectiveTests(FileEditTest); 18 runReflectiveTests(FileEditTest);
21 runReflectiveTests(LinkedEditGroupTest); 19 runReflectiveTests(LinkedEditGroupTest);
22 runReflectiveTests(LinkedEditSuggestionTest); 20 runReflectiveTests(LinkedEditSuggestionTest);
23 runReflectiveTests(PositionTest); 21 runReflectiveTests(PositionTest);
24 } 22 }
25 23
26 24
27 @ReflectiveTestCase() 25 @ReflectiveTestCase()
28 class ChangeTest { 26 class ChangeTest {
29 void test_addEdit() { 27 void test_addEdit() {
30 Change change = new Change('msg'); 28 SourceChange change = new SourceChange('msg');
31 SourceEdit edit1 = new SourceEdit(1, 2, 'a'); 29 SourceEdit edit1 = new SourceEdit(1, 2, 'a');
32 SourceEdit edit2 = new SourceEdit(1, 2, 'b'); 30 SourceEdit edit2 = new SourceEdit(1, 2, 'b');
33 expect(change.fileEdits, hasLength(0)); 31 expect(change.edits, hasLength(0));
34 change.addEdit('/a.dart', edit1); 32 change.addEdit('/a.dart', edit1);
35 expect(change.fileEdits, hasLength(1)); 33 expect(change.edits, hasLength(1));
36 change.addEdit('/a.dart', edit2); 34 change.addEdit('/a.dart', edit2);
37 expect(change.fileEdits, hasLength(1)); 35 expect(change.edits, hasLength(1));
38 { 36 {
39 SourceFileEdit fileEdit = change.getFileEdit('/a.dart'); 37 SourceFileEdit fileEdit = change.getFileEdit('/a.dart');
40 expect(fileEdit, isNotNull); 38 expect(fileEdit, isNotNull);
41 expect(fileEdit.edits, unorderedEquals([edit1, edit2])); 39 expect(fileEdit.edits, unorderedEquals([edit1, edit2]));
42 } 40 }
43 } 41 }
44 42
45 void test_getFileEdit() { 43 void test_getFileEdit() {
46 Change change = new Change('msg'); 44 SourceChange change = new SourceChange('msg');
47 SourceFileEdit fileEdit = new SourceFileEdit('/a.dart'); 45 SourceFileEdit fileEdit = new SourceFileEdit('/a.dart');
48 change.addFileEdit(fileEdit); 46 change.addFileEdit(fileEdit);
49 expect(change.getFileEdit('/a.dart'), fileEdit); 47 expect(change.getFileEdit('/a.dart'), fileEdit);
50 } 48 }
51 49
52 void test_getFileEdit_empty() { 50 void test_getFileEdit_empty() {
53 Change change = new Change('msg'); 51 SourceChange change = new SourceChange('msg');
54 expect(change.getFileEdit('/some.dart'), isNull); 52 expect(change.getFileEdit('/some.dart'), isNull);
55 } 53 }
56 54
57 void test_toJson() { 55 void test_toJson() {
58 Change change = new Change('msg'); 56 SourceChange change = new SourceChange('msg');
59 change.addFileEdit(new SourceFileEdit('/a.dart') 57 change.addFileEdit(new SourceFileEdit('/a.dart')
60 ..add(new SourceEdit(1, 2, 'aaa')) 58 ..add(new SourceEdit(1, 2, 'aaa'))
61 ..add(new SourceEdit(10, 20, 'bbb'))); 59 ..add(new SourceEdit(10, 20, 'bbb')));
62 change.addFileEdit(new SourceFileEdit('/b.dart') 60 change.addFileEdit(new SourceFileEdit('/b.dart')
63 ..add(new SourceEdit(21, 22, 'xxx')) 61 ..add(new SourceEdit(21, 22, 'xxx'))
64 ..add(new SourceEdit(210, 220, 'yyy'))); 62 ..add(new SourceEdit(210, 220, 'yyy')));
65 { 63 {
66 var group = new LinkedEditGroup(); 64 var group = new LinkedEditGroup.empty();
67 change.addLinkedEditGroup(group 65 change.addLinkedEditGroup(group
68 ..addPosition(new Position('/ga.dart', 1), 2) 66 ..addPosition(new Position('/ga.dart', 1), 2)
69 ..addPosition(new Position('/ga.dart', 10), 2)); 67 ..addPosition(new Position('/ga.dart', 10), 2));
70 group.addSuggestion( 68 group.addSuggestion(
71 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'AA')); 69 new LinkedEditSuggestion('AA', LinkedEditSuggestionKind.TYPE));
72 group.addSuggestion( 70 group.addSuggestion(
73 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'BB')); 71 new LinkedEditSuggestion('BB', LinkedEditSuggestionKind.TYPE));
74 } 72 }
75 change.addLinkedEditGroup(new LinkedEditGroup() 73 change.addLinkedEditGroup(new LinkedEditGroup.empty()
76 ..addPosition(new Position('/gb.dart', 10), 5) 74 ..addPosition(new Position('/gb.dart', 10), 5)
77 ..addPosition(new Position('/gb.dart', 100), 5)); 75 ..addPosition(new Position('/gb.dart', 100), 5));
78 change.selection = new Position('/selection.dart', 42); 76 change.selection = new Position('/selection.dart', 42);
79 var expectedJson = { 77 var expectedJson = {
80 'message': 'msg', 78 'message': 'msg',
81 'edits': [{ 79 'edits': [{
82 'file': '/a.dart', 80 'file': '/a.dart',
83 'edits': [{ 81 'edits': [{
84 'offset': 10, 82 'offset': 10,
85 'length': 20, 83 'length': 20,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 },] 240 },]
243 }; 241 };
244 expect(fileEdit.toJson(), expectedJson); 242 expect(fileEdit.toJson(), expectedJson);
245 } 243 }
246 } 244 }
247 245
248 246
249 @ReflectiveTestCase() 247 @ReflectiveTestCase()
250 class LinkedEditGroupTest { 248 class LinkedEditGroupTest {
251 void test_new() { 249 void test_new() {
252 LinkedEditGroup group = new LinkedEditGroup(); 250 LinkedEditGroup group = new LinkedEditGroup.empty();
253 group.addPosition(new Position('/a.dart', 1), 2); 251 group.addPosition(new Position('/a.dart', 1), 2);
254 group.addPosition(new Position('/b.dart', 10), 2); 252 group.addPosition(new Position('/b.dart', 10), 2);
255 expect( 253 expect(
256 group.toString(), 254 group.toString(),
257 'LinkedEditGroup(length=2, positions=[' 255 '{"positions":['
258 '{"file":"/a.dart","offset":1}, ' 256 '{"file":"/a.dart","offset":1},'
259 '{"file":"/b.dart","offset":10}], suggestions=[])'); 257 '{"file":"/b.dart","offset":10}],"length":2,"suggestions":[]}');
260 } 258 }
261 259
262 void test_toJson() { 260 void test_toJson() {
263 LinkedEditGroup group = new LinkedEditGroup(); 261 LinkedEditGroup group = new LinkedEditGroup.empty();
264 group.addPosition(new Position('/a.dart', 1), 2); 262 group.addPosition(new Position('/a.dart', 1), 2);
265 group.addPosition(new Position('/b.dart', 10), 2); 263 group.addPosition(new Position('/b.dart', 10), 2);
266 group.addSuggestion( 264 group.addSuggestion(
267 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'AA')); 265 new LinkedEditSuggestion('AA', LinkedEditSuggestionKind.TYPE));
268 group.addSuggestion( 266 group.addSuggestion(
269 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'BB')); 267 new LinkedEditSuggestion('BB', LinkedEditSuggestionKind.TYPE));
270 expect(group.toJson(), { 268 expect(group.toJson(), {
271 'length': 2, 269 'length': 2,
272 'positions': [{ 270 'positions': [{
273 'file': '/a.dart', 271 'file': '/a.dart',
274 'offset': 1 272 'offset': 1
275 }, { 273 }, {
276 'file': '/b.dart', 274 'file': '/b.dart',
277 'offset': 10 275 'offset': 10
278 }], 276 }],
279 'suggestions': [{ 277 'suggestions': [{
280 'kind': 'TYPE', 278 'kind': 'TYPE',
281 'value': 'AA' 279 'value': 'AA'
282 }, { 280 }, {
283 'kind': 'TYPE', 281 'kind': 'TYPE',
284 'value': 'BB' 282 'value': 'BB'
285 }] 283 }]
286 }); 284 });
287 } 285 }
288 } 286 }
289 287
290 288
291 @ReflectiveTestCase() 289 @ReflectiveTestCase()
292 class LinkedEditSuggestionTest { 290 class LinkedEditSuggestionTest {
293 void test_eqEq() { 291 void test_eqEq() {
294 var a = new LinkedEditSuggestion(LinkedEditSuggestionKind.METHOD, 'a'); 292 var a = new LinkedEditSuggestion('a', LinkedEditSuggestionKind.METHOD);
295 var a2 = new LinkedEditSuggestion(LinkedEditSuggestionKind.METHOD, 'a'); 293 var a2 = new LinkedEditSuggestion('a', LinkedEditSuggestionKind.METHOD);
296 var b = new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'a'); 294 var b = new LinkedEditSuggestion('a', LinkedEditSuggestionKind.TYPE);
297 var c = new LinkedEditSuggestion(LinkedEditSuggestionKind.METHOD, 'c'); 295 var c = new LinkedEditSuggestion('c', LinkedEditSuggestionKind.METHOD);
298 expect(a == a, isTrue); 296 expect(a == a, isTrue);
299 expect(a == a2, isTrue); 297 expect(a == a2, isTrue);
300 expect(a == this, isFalse); 298 expect(a == this, isFalse);
301 expect(a == b, isFalse); 299 expect(a == b, isFalse);
302 expect(a == c, isFalse); 300 expect(a == c, isFalse);
303 } 301 }
304 } 302 }
305 303
306 304
307 @ReflectiveTestCase() 305 @ReflectiveTestCase()
(...skipping 22 matching lines...) Expand all
330 328
331 void test_toJson() { 329 void test_toJson() {
332 Position position = new Position('/test.dart', 1); 330 Position position = new Position('/test.dart', 1);
333 var expectedJson = { 331 var expectedJson = {
334 FILE: '/test.dart', 332 FILE: '/test.dart',
335 OFFSET: 1 333 OFFSET: 1
336 }; 334 };
337 expect(position.toJson(), expectedJson); 335 expect(position.toJson(), expectedJson);
338 } 336 }
339 } 337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698