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

Side by Side Diff: pkg/analysis_services/test/correction/change_test.dart

Issue 447613002: Make Change implementation consistent with the server spec. (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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library test.services.correction.change; 8 library test.services.correction.change;
9 9
10 import 'package:analysis_services/constants.dart'; 10 import 'package:analysis_services/constants.dart';
11 import 'package:analysis_services/correction/change.dart'; 11 import 'package:analysis_services/correction/change.dart';
12 import 'package:analysis_testing/reflective_tests.dart'; 12 import 'package:analysis_testing/reflective_tests.dart';
13 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
14 14
15 15
16 main() { 16 main() {
17 groupSep = ' | '; 17 groupSep = ' | ';
18 runReflectiveTests(ChangeTest); 18 runReflectiveTests(ChangeTest);
19 runReflectiveTests(EditTest); 19 runReflectiveTests(EditTest);
20 runReflectiveTests(FileEditTest); 20 runReflectiveTests(FileEditTest);
21 runReflectiveTests(LinkedPositionGroupTest); 21 runReflectiveTests(LinkedEditGroupTest);
22 runReflectiveTests(LinkedEditSuggestionTest);
22 runReflectiveTests(PositionTest); 23 runReflectiveTests(PositionTest);
23 } 24 }
24 25
25 26
26 @ReflectiveTestCase() 27 @ReflectiveTestCase()
27 class ChangeTest { 28 class ChangeTest {
28 void test_fromJson() {
29 var json = {
30 MESSAGE: 'msg',
31 EDITS: [{
32 FILE: '/a.dart',
33 EDITS: [{
34 OFFSET: 1,
35 LENGTH: 2,
36 REPLACEMENT: 'aaa'
37 }, {
38 OFFSET: 10,
39 LENGTH: 20,
40 REPLACEMENT: 'bbb'
41 }]
42 }, {
43 FILE: '/b.dart',
44 EDITS: [{
45 OFFSET: 21,
46 LENGTH: 22,
47 REPLACEMENT: 'xxx'
48 }, {
49 OFFSET: 210,
50 LENGTH: 220,
51 REPLACEMENT: 'yyy'
52 }]
53 }],
54 LINKED_POSITION_GROUPS: [{
55 ID: 'id-a',
56 POSITIONS: [{
57 FILE: '/ga.dart',
58 OFFSET: 1,
59 LENGTH: 2
60 }, {
61 FILE: '/ga.dart',
62 OFFSET: 10,
63 LENGTH: 2
64 }]
65 }, {
66 ID: 'id-b',
67 POSITIONS: [{
68 FILE: '/gb.dart',
69 OFFSET: 10,
70 LENGTH: 5
71 }, {
72 FILE: '/gb.dart',
73 OFFSET: 100,
74 LENGTH: 5
75 }]
76 }]
77 };
78 Change change = Change.fromJson(json);
79 expect(change.message, 'msg');
80 // edits
81 expect(change.edits, hasLength(2));
82 {
83 FileEdit fileEdit = change.edits[0];
84 expect(fileEdit.file, '/a.dart');
85 expect(fileEdit.edits, hasLength(2));
86 expect(fileEdit.edits[0], new Edit(1, 2, 'aaa'));
87 expect(fileEdit.edits[1], new Edit(10, 20, 'bbb'));
88 }
89 {
90 FileEdit fileEdit = change.edits[1];
91 expect(fileEdit.file, '/b.dart');
92 expect(fileEdit.edits, hasLength(2));
93 expect(fileEdit.edits[0], new Edit(21, 22, 'xxx'));
94 expect(fileEdit.edits[1], new Edit(210, 220, 'yyy'));
95 }
96 // linked position groups
97 expect(change.linkedPositionGroups, hasLength(2));
98 {
99 LinkedPositionGroup group = change.linkedPositionGroups[0];
100 expect(group.id, 'id-a');
101 expect(group.positions, hasLength(2));
102 expect(group.positions[0], new Position('/ga.dart', 1, 2));
103 expect(group.positions[1], new Position('/ga.dart', 10, 2));
104 }
105 {
106 LinkedPositionGroup group = change.linkedPositionGroups[1];
107 expect(group.id, 'id-b');
108 expect(group.positions, hasLength(2));
109 expect(group.positions[0], new Position('/gb.dart', 10, 5));
110 expect(group.positions[1], new Position('/gb.dart', 100, 5));
111 }
112 }
113
114 void test_new() {
115 Change change = new Change('msg');
116 change.add(new FileEdit('/a.dart')
117 ..add(new Edit(1, 2, 'aaa'))
118 ..add(new Edit(10, 20, 'bbb')));
119 change.add(new FileEdit('/b.dart')
120 ..add(new Edit(21, 22, 'xxx'))
121 ..add(new Edit(210, 220, 'yyy')));
122 change.addLinkedPositionGroup(new LinkedPositionGroup('id-a')
123 ..addPosition(new Position('/ga.dart', 1, 2))
124 ..addPosition(new Position('/ga.dart', 10, 2)));
125 change.addLinkedPositionGroup(new LinkedPositionGroup('id-b')
126 ..addPosition(new Position('/gb.dart', 10, 5))
127 ..addPosition(new Position('/gb.dart', 100, 5)));
128 expect(
129 change.toString(),
130 'Change(message=msg, edits=[FileEdit(file=/a.dart, edits=['
131 'Edit(offset=1, length=2, replacement=:>aaa<:), '
132 'Edit(offset=10, length=20, replacement=:>bbb<:)]), '
133 'FileEdit(file=/b.dart, edits=['
134 'Edit(offset=21, length=22, replacement=:>xxx<:), '
135 'Edit(offset=210, length=220, replacement=:>yyy<:)])], '
136 'linkedPositionGroups=[' 'LinkedPositionGroup(id=id-a, positions=['
137 'Position(file=/ga.dart, offset=1, length=2), '
138 'Position(file=/ga.dart, offset=10, length=2)]), '
139 'LinkedPositionGroup(id=id-b, positions=['
140 'Position(file=/gb.dart, offset=10, length=5), '
141 'Position(file=/gb.dart, offset=100, length=5)])])');
142 }
143
144 void test_toJson() { 29 void test_toJson() {
145 Change change = new Change('msg'); 30 Change change = new Change('msg');
146 change.add(new FileEdit('/a.dart') 31 change.add(new FileEdit('/a.dart')
147 ..add(new Edit(1, 2, 'aaa')) 32 ..add(new Edit(1, 2, 'aaa'))
148 ..add(new Edit(10, 20, 'bbb'))); 33 ..add(new Edit(10, 20, 'bbb')));
149 change.add(new FileEdit('/b.dart') 34 change.add(new FileEdit('/b.dart')
150 ..add(new Edit(21, 22, 'xxx')) 35 ..add(new Edit(21, 22, 'xxx'))
151 ..add(new Edit(210, 220, 'yyy'))); 36 ..add(new Edit(210, 220, 'yyy')));
152 change.addLinkedPositionGroup(new LinkedPositionGroup('id-a') 37 {
153 ..addPosition(new Position('/ga.dart', 1, 2)) 38 var group = new LinkedEditGroup('id-a');
154 ..addPosition(new Position('/ga.dart', 10, 2))); 39 change.addLinkedEditGroup(group
155 change.addLinkedPositionGroup(new LinkedPositionGroup('id-b') 40 ..addPosition(new Position('/ga.dart', 1), 2)
156 ..addPosition(new Position('/gb.dart', 10, 5)) 41 ..addPosition(new Position('/ga.dart', 10), 2));
157 ..addPosition(new Position('/gb.dart', 100, 5))); 42 group.addSuggestion(
43 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'AA'));
44 group.addSuggestion(
45 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'BB'));
46 }
47 change.addLinkedEditGroup(new LinkedEditGroup('id-b')
48 ..addPosition(new Position('/gb.dart', 10), 5)
49 ..addPosition(new Position('/gb.dart', 100), 5));
158 var expectedJson = { 50 var expectedJson = {
159 MESSAGE: 'msg', 51 'message': 'msg',
160 EDITS: [{ 52 'edits': [{
161 FILE: '/a.dart', 53 'file': '/a.dart',
162 EDITS: [{ 54 'edits': [{
163 OFFSET: 1, 55 'offset': 1,
164 LENGTH: 2, 56 'length': 2,
165 REPLACEMENT: 'aaa' 57 'relacement': 'aaa'
166 }, { 58 }, {
167 OFFSET: 10, 59 'offset': 10,
168 LENGTH: 20, 60 'length': 20,
169 REPLACEMENT: 'bbb' 61 'relacement': 'bbb'
170 }] 62 }]
171 }, { 63 }, {
172 FILE: '/b.dart', 64 'file': '/b.dart',
173 EDITS: [{ 65 'edits': [{
174 OFFSET: 21, 66 'offset': 21,
175 LENGTH: 22, 67 'length': 22,
176 REPLACEMENT: 'xxx' 68 'relacement': 'xxx'
177 }, { 69 }, {
178 OFFSET: 210, 70 'offset': 210,
179 LENGTH: 220, 71 'length': 220,
180 REPLACEMENT: 'yyy' 72 'relacement': 'yyy'
181 }] 73 }]
182 }], 74 }],
183 LINKED_POSITION_GROUPS: [{ 75 'linkedEditGroups': [{
184 ID: 'id-a', 76 'id': 'id-a',
185 POSITIONS: [{ 77 'length': 2,
186 FILE: '/ga.dart', 78 'positions': [{
187 OFFSET: 1, 79 'file': '/ga.dart',
188 LENGTH: 2 80 'offset': 1
189 }, { 81 }, {
190 FILE: '/ga.dart', 82 'file': '/ga.dart',
191 OFFSET: 10, 83 'offset': 10
192 LENGTH: 2 84 }],
85 'suggestions': [{
86 'kind': 'TYPE',
87 'value': 'AA'
88 }, {
89 'kind': 'TYPE',
90 'value': 'BB'
193 }] 91 }]
194 }, { 92 }, {
195 ID: 'id-b', 93 'id': 'id-b',
196 POSITIONS: [{ 94 'length': 5,
197 FILE: '/gb.dart', 95 'positions': [{
198 OFFSET: 10, 96 'file': '/gb.dart',
199 LENGTH: 5 97 'offset': 10
200 }, { 98 }, {
201 FILE: '/gb.dart', 99 'file': '/gb.dart',
202 OFFSET: 100, 100 'offset': 100
203 LENGTH: 5 101 }],
204 }] 102 'suggestions': []
205 }] 103 }]
206 }; 104 };
207 expect(change.toJson(), expectedJson); 105 expect(change.toJson(), expectedJson);
106 // some toString()
107 change.toString();
208 } 108 }
209 } 109 }
210 110
211 111
212 @ReflectiveTestCase() 112 @ReflectiveTestCase()
213 class EditTest { 113 class EditTest {
214 void test_end() { 114 void test_end() {
215 Edit edit = new Edit(1, 2, 'foo'); 115 Edit edit = new Edit(1, 2, 'foo');
216 expect(edit.end, 3); 116 expect(edit.end, 3);
217 } 117 }
218 118
219 void test_fromJson() {
220 var json = {
221 OFFSET: 1,
222 LENGTH: 2,
223 REPLACEMENT: 'foo'
224 };
225 Edit edit = Edit.fromJson(json);
226 expect(edit.offset, 1);
227 expect(edit.length, 2);
228 expect(edit.replacement, 'foo');
229 }
230
231 void test_new() { 119 void test_new() {
232 Edit edit = new Edit(1, 2, 'foo'); 120 Edit edit = new Edit(1, 2, 'foo');
233 expect(edit.offset, 1); 121 expect(edit.offset, 1);
234 expect(edit.length, 2); 122 expect(edit.length, 2);
235 expect(edit.replacement, 'foo'); 123 expect(edit.replacement, 'foo');
236 expect(edit.toString(), 'Edit(offset=1, length=2, replacement=:>foo<:)'); 124 expect(edit.toString(), 'Edit(offset=1, length=2, replacement=:>foo<:)');
237 } 125 }
238 126
239 void test_toJson() { 127 void test_toJson() {
240 Edit edit = new Edit(1, 2, 'foo'); 128 Edit edit = new Edit(1, 2, 'foo');
(...skipping 13 matching lines...) Expand all
254 expect(a == this, isFalse); 142 expect(a == this, isFalse);
255 expect(a == new Edit(1, 2, 'bbb'), isFalse); 143 expect(a == new Edit(1, 2, 'bbb'), isFalse);
256 expect(a == new Edit(10, 2, 'aaa'), isFalse); 144 expect(a == new Edit(10, 2, 'aaa'), isFalse);
257 } 145 }
258 146
259 } 147 }
260 148
261 149
262 @ReflectiveTestCase() 150 @ReflectiveTestCase()
263 class FileEditTest { 151 class FileEditTest {
264 void test_fromJson() {
265 var json = {
266 FILE: '/test.dart',
267 EDITS: [{
268 OFFSET: 1,
269 LENGTH: 2,
270 REPLACEMENT: 'aaa'
271 }, {
272 OFFSET: 10,
273 LENGTH: 20,
274 REPLACEMENT: 'bbb'
275 },]
276 };
277 var fileEdit = FileEdit.fromJson(json);
278 expect(fileEdit.file, '/test.dart');
279 expect(fileEdit.edits, hasLength(2));
280 expect(fileEdit.edits[0], new Edit(1, 2, 'aaa'));
281 expect(fileEdit.edits[1], new Edit(10, 20, 'bbb'));
282 }
283
284 void test_new() { 152 void test_new() {
285 FileEdit fileEdit = new FileEdit('/test.dart'); 153 FileEdit fileEdit = new FileEdit('/test.dart');
286 fileEdit.add(new Edit(1, 2, 'aaa')); 154 fileEdit.add(new Edit(1, 2, 'aaa'));
287 fileEdit.add(new Edit(10, 20, 'bbb')); 155 fileEdit.add(new Edit(10, 20, 'bbb'));
288 expect( 156 expect(
289 fileEdit.toString(), 157 fileEdit.toString(),
290 'FileEdit(file=/test.dart, edits=[' 158 'FileEdit(file=/test.dart, edits=['
291 'Edit(offset=1, length=2, replacement=:>aaa<:), ' 159 'Edit(offset=1, length=2, replacement=:>aaa<:), '
292 'Edit(offset=10, length=20, replacement=:>bbb<:)])'); 160 'Edit(offset=10, length=20, replacement=:>bbb<:)])');
293 } 161 }
294 162
295 void test_toJson() { 163 void test_toJson() {
296 FileEdit fileEdit = new FileEdit('/test.dart'); 164 FileEdit fileEdit = new FileEdit('/test.dart');
297 fileEdit.add(new Edit(1, 2, 'aaa')); 165 fileEdit.add(new Edit(1, 2, 'aaa'));
298 fileEdit.add(new Edit(10, 20, 'bbb')); 166 fileEdit.add(new Edit(10, 20, 'bbb'));
299 expect(fileEdit.toJson(), { 167 var expectedJson = {
300 FILE: '/test.dart', 168 FILE: '/test.dart',
301 EDITS: [{ 169 EDITS: [{
302 OFFSET: 1, 170 OFFSET: 1,
303 LENGTH: 2, 171 LENGTH: 2,
304 REPLACEMENT: 'aaa' 172 REPLACEMENT: 'aaa'
305 }, { 173 }, {
306 OFFSET: 10, 174 OFFSET: 10,
307 LENGTH: 20, 175 LENGTH: 20,
308 REPLACEMENT: 'bbb' 176 REPLACEMENT: 'bbb'
309 },] 177 },]
310 }); 178 };
179 expect(fileEdit.toJson(), expectedJson);
311 } 180 }
312 } 181 }
313 182
314 183
315 @ReflectiveTestCase() 184 @ReflectiveTestCase()
316 class LinkedPositionGroupTest { 185 class LinkedEditSuggestionTest {
317 void test_addWrongLength() { 186 void test_eqEq() {
318 LinkedPositionGroup group = new LinkedPositionGroup('my-id'); 187 var a = new LinkedEditSuggestion(LinkedEditSuggestionKind.METHOD, 'a');
319 group.addPosition(new Position('/a.dart', 1, 2)); 188 var a2 = new LinkedEditSuggestion(LinkedEditSuggestionKind.METHOD, 'a');
320 expect(() { 189 var b = new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'a');
321 group.addPosition(new Position('/b.dart', 10, 20)); 190 var c = new LinkedEditSuggestion(LinkedEditSuggestionKind.METHOD, 'c');
322 }, throws); 191 expect(a == a, isTrue);
192 expect(a == a2, isTrue);
193 expect(a == this, isFalse);
194 expect(a == b, isFalse);
195 expect(a == c, isFalse);
323 } 196 }
197 }
324 198
325 void test_fromJson() {
326 var json = {
327 ID: 'my-id',
328 POSITIONS: [{
329 FILE: '/a.dart',
330 OFFSET: 1,
331 LENGTH: 2
332 }, {
333 FILE: '/b.dart',
334 OFFSET: 10,
335 LENGTH: 2
336 }]
337 };
338 LinkedPositionGroup group = LinkedPositionGroup.fromJson(json);
339 expect(group.id, 'my-id');
340 expect(group.positions, hasLength(2));
341 expect(group.positions[0], new Position('/a.dart', 1, 2));
342 expect(group.positions[1], new Position('/b.dart', 10, 2));
343 }
344 199
200 @ReflectiveTestCase()
201 class LinkedEditGroupTest {
345 void test_new() { 202 void test_new() {
346 LinkedPositionGroup group = new LinkedPositionGroup('my-id'); 203 LinkedEditGroup group = new LinkedEditGroup('my-id');
347 group.addPosition(new Position('/a.dart', 1, 2)); 204 group.addPosition(new Position('/a.dart', 1), 2);
348 group.addPosition(new Position('/b.dart', 10, 2)); 205 group.addPosition(new Position('/b.dart', 10), 2);
349 expect( 206 expect(
350 group.toString(), 207 group.toString(),
351 'LinkedPositionGroup(id=my-id, positions=[' 208 'LinkedEditGroup(id=my-id, length=2, positions=['
352 'Position(file=/a.dart, offset=1, length=2), ' 209 'Position(file=/a.dart, offset=1), '
353 'Position(file=/b.dart, offset=10, length=2)])'); 210 'Position(file=/b.dart, offset=10)], suggestions=[])');
354 } 211 }
355 212
356 void test_toJson() { 213 void test_toJson() {
357 LinkedPositionGroup group = new LinkedPositionGroup('my-id'); 214 LinkedEditGroup group = new LinkedEditGroup('my-id');
358 group.addPosition(new Position('/a.dart', 1, 2)); 215 group.addPosition(new Position('/a.dart', 1), 2);
359 group.addPosition(new Position('/b.dart', 10, 2)); 216 group.addPosition(new Position('/b.dart', 10), 2);
360 var expectedJson = { 217 group.addSuggestion(
361 ID: 'my-id', 218 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'AA'));
362 POSITIONS: [{ 219 group.addSuggestion(
363 FILE: '/a.dart', 220 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'BB'));
364 OFFSET: 1, 221 expect(group.toJson(), {
365 LENGTH: 2 222 'id': 'my-id',
223 'length': 2,
224 'positions': [{
225 'file': '/a.dart',
226 'offset': 1
366 }, { 227 }, {
367 FILE: '/b.dart', 228 'file': '/b.dart',
368 OFFSET: 10, 229 'offset': 10
369 LENGTH: 2 230 }],
231 'suggestions': [{
232 'kind': 'TYPE',
233 'value': 'AA'
234 }, {
235 'kind': 'TYPE',
236 'value': 'BB'
370 }] 237 }]
371 }; 238 });
372 expect(group.toJson(), expectedJson);
373 } 239 }
374 } 240 }
375 241
376 242
377 @ReflectiveTestCase() 243 @ReflectiveTestCase()
378 class PositionTest { 244 class PositionTest {
379 void test_eqEq() { 245 void test_eqEq() {
380 Position a = new Position('/a.dart', 1, 2); 246 Position a = new Position('/a.dart', 1);
381 Position a2 = new Position('/a.dart', 1, 2); 247 Position a2 = new Position('/a.dart', 1);
382 Position b = new Position('/b.dart', 1, 2); 248 Position b = new Position('/b.dart', 1);
383 expect(a == a, isTrue); 249 expect(a == a, isTrue);
384 expect(a == a2, isTrue); 250 expect(a == a2, isTrue);
385 expect(a == b, isFalse); 251 expect(a == b, isFalse);
386 expect(a == this, isFalse); 252 expect(a == this, isFalse);
387 } 253 }
388 254
389 void test_fromJson() {
390 var json = {
391 FILE: '/test.dart',
392 OFFSET: 1,
393 LENGTH: 2
394 };
395 Position position = Position.fromJson(json);
396 expect(position.file, '/test.dart');
397 expect(position.offset, 1);
398 expect(position.length, 2);
399 }
400
401 void test_hashCode() { 255 void test_hashCode() {
402 Position position = new Position('/test.dart', 1, 2); 256 Position position = new Position('/test.dart', 1);
403 position.hashCode; 257 position.hashCode;
404 } 258 }
405 259
406 void test_new() { 260 void test_new() {
407 Position position = new Position('/test.dart', 1, 2); 261 Position position = new Position('/test.dart', 1);
408 expect(position.file, '/test.dart'); 262 expect(position.file, '/test.dart');
409 expect(position.offset, 1); 263 expect(position.offset, 1);
410 expect(position.length, 2); 264 expect(position.toString(), 'Position(file=/test.dart, offset=1)');
411 expect(
412 position.toString(),
413 'Position(file=/test.dart, offset=1, length=2)');
414 } 265 }
415 266
416 void test_toJson() { 267 void test_toJson() {
417 Position position = new Position('/test.dart', 1, 2); 268 Position position = new Position('/test.dart', 1);
418 var expectedJson = { 269 var expectedJson = {
419 FILE: '/test.dart', 270 FILE: '/test.dart',
420 OFFSET: 1, 271 OFFSET: 1
421 LENGTH: 2
422 }; 272 };
423 expect(position.toJson(), expectedJson); 273 expect(position.toJson(), expectedJson);
424 } 274 }
425 } 275 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/test/correction/assist_test.dart ('k') | pkg/analysis_services/test/correction/fix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698