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

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

Issue 969113002: Reformat (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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/protocol_server.dart'; 8 import 'package:analysis_server/src/protocol_server.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
11 11
12 import '../../reflective_tests.dart'; 12 import '../../reflective_tests.dart';
13 13
14
15 main() { 14 main() {
16 groupSep = ' | '; 15 groupSep = ' | ';
17 runReflectiveTests(ChangeTest); 16 runReflectiveTests(ChangeTest);
18 runReflectiveTests(EditTest); 17 runReflectiveTests(EditTest);
19 runReflectiveTests(FileEditTest); 18 runReflectiveTests(FileEditTest);
20 runReflectiveTests(LinkedEditGroupTest); 19 runReflectiveTests(LinkedEditGroupTest);
21 runReflectiveTests(LinkedEditSuggestionTest); 20 runReflectiveTests(LinkedEditSuggestionTest);
22 runReflectiveTests(PositionTest); 21 runReflectiveTests(PositionTest);
23 } 22 }
24 23
25
26 @reflectiveTest 24 @reflectiveTest
27 class ChangeTest { 25 class ChangeTest {
28 void test_addEdit() { 26 void test_addEdit() {
29 SourceChange change = new SourceChange('msg'); 27 SourceChange change = new SourceChange('msg');
30 SourceEdit edit1 = new SourceEdit(1, 2, 'a'); 28 SourceEdit edit1 = new SourceEdit(1, 2, 'a');
31 SourceEdit edit2 = new SourceEdit(1, 2, 'b'); 29 SourceEdit edit2 = new SourceEdit(1, 2, 'b');
32 expect(change.edits, hasLength(0)); 30 expect(change.edits, hasLength(0));
33 change.addEdit('/a.dart', 0, edit1); 31 change.addEdit('/a.dart', 0, edit1);
34 expect(change.edits, hasLength(1)); 32 expect(change.edits, hasLength(1));
35 change.addEdit('/a.dart', 0, edit2); 33 change.addEdit('/a.dart', 0, edit2);
(...skipping 13 matching lines...) Expand all
49 } 47 }
50 48
51 void test_getFileEdit_empty() { 49 void test_getFileEdit_empty() {
52 SourceChange change = new SourceChange('msg'); 50 SourceChange change = new SourceChange('msg');
53 expect(change.getFileEdit('/some.dart'), isNull); 51 expect(change.getFileEdit('/some.dart'), isNull);
54 } 52 }
55 53
56 void test_toJson() { 54 void test_toJson() {
57 SourceChange change = new SourceChange('msg'); 55 SourceChange change = new SourceChange('msg');
58 change.addFileEdit(new SourceFileEdit('/a.dart', 1) 56 change.addFileEdit(new SourceFileEdit('/a.dart', 1)
59 ..add(new SourceEdit(1, 2, 'aaa')) 57 ..add(new SourceEdit(1, 2, 'aaa'))
60 ..add(new SourceEdit(10, 20, 'bbb'))); 58 ..add(new SourceEdit(10, 20, 'bbb')));
61 change.addFileEdit(new SourceFileEdit('/b.dart', 2) 59 change.addFileEdit(new SourceFileEdit('/b.dart', 2)
62 ..add(new SourceEdit(21, 22, 'xxx')) 60 ..add(new SourceEdit(21, 22, 'xxx'))
63 ..add(new SourceEdit(210, 220, 'yyy'))); 61 ..add(new SourceEdit(210, 220, 'yyy')));
64 { 62 {
65 var group = new LinkedEditGroup.empty(); 63 var group = new LinkedEditGroup.empty();
66 change.addLinkedEditGroup(group 64 change.addLinkedEditGroup(group
67 ..addPosition(new Position('/ga.dart', 1), 2) 65 ..addPosition(new Position('/ga.dart', 1), 2)
68 ..addPosition(new Position('/ga.dart', 10), 2)); 66 ..addPosition(new Position('/ga.dart', 10), 2));
69 group.addSuggestion( 67 group.addSuggestion(
70 new LinkedEditSuggestion('AA', LinkedEditSuggestionKind.TYPE)); 68 new LinkedEditSuggestion('AA', LinkedEditSuggestionKind.TYPE));
71 group.addSuggestion( 69 group.addSuggestion(
72 new LinkedEditSuggestion('BB', LinkedEditSuggestionKind.TYPE)); 70 new LinkedEditSuggestion('BB', LinkedEditSuggestionKind.TYPE));
73 } 71 }
74 change.addLinkedEditGroup(new LinkedEditGroup.empty() 72 change.addLinkedEditGroup(new LinkedEditGroup.empty()
75 ..addPosition(new Position('/gb.dart', 10), 5) 73 ..addPosition(new Position('/gb.dart', 10), 5)
76 ..addPosition(new Position('/gb.dart', 100), 5)); 74 ..addPosition(new Position('/gb.dart', 100), 5));
77 change.selection = new Position('/selection.dart', 42); 75 change.selection = new Position('/selection.dart', 42);
78 var expectedJson = { 76 var expectedJson = {
79 'message': 'msg', 77 'message': 'msg',
80 'edits': [{ 78 'edits': [
79 {
81 'file': '/a.dart', 80 'file': '/a.dart',
82 'fileStamp': 1, 81 'fileStamp': 1,
83 'edits': [{ 82 'edits': [
84 'offset': 10, 83 {'offset': 10, 'length': 20, 'replacement': 'bbb'},
85 'length': 20, 84 {'offset': 1, 'length': 2, 'replacement': 'aaa'}
86 'replacement': 'bbb' 85 ]
87 }, { 86 },
88 'offset': 1, 87 {
89 'length': 2,
90 'replacement': 'aaa'
91 }]
92 }, {
93 'file': '/b.dart', 88 'file': '/b.dart',
94 'fileStamp': 2, 89 'fileStamp': 2,
95 'edits': [{ 90 'edits': [
96 'offset': 210, 91 {'offset': 210, 'length': 220, 'replacement': 'yyy'},
97 'length': 220, 92 {'offset': 21, 'length': 22, 'replacement': 'xxx'}
98 'replacement': 'yyy' 93 ]
99 }, { 94 }
100 'offset': 21, 95 ],
101 'length': 22, 96 'linkedEditGroups': [
102 'replacement': 'xxx' 97 {
103 }]
104 }],
105 'linkedEditGroups': [{
106 'length': 2, 98 'length': 2,
107 'positions': [{ 99 'positions': [
108 'file': '/ga.dart', 100 {'file': '/ga.dart', 'offset': 1},
109 'offset': 1 101 {'file': '/ga.dart', 'offset': 10}
110 }, { 102 ],
111 'file': '/ga.dart', 103 'suggestions': [
112 'offset': 10 104 {'kind': 'TYPE', 'value': 'AA'},
113 }], 105 {'kind': 'TYPE', 'value': 'BB'}
114 'suggestions': [{ 106 ]
115 'kind': 'TYPE', 107 },
116 'value': 'AA' 108 {
117 }, {
118 'kind': 'TYPE',
119 'value': 'BB'
120 }]
121 }, {
122 'length': 5, 109 'length': 5,
123 'positions': [{ 110 'positions': [
124 'file': '/gb.dart', 111 {'file': '/gb.dart', 'offset': 10},
125 'offset': 10 112 {'file': '/gb.dart', 'offset': 100}
126 }, { 113 ],
127 'file': '/gb.dart',
128 'offset': 100
129 }],
130 'suggestions': [] 114 'suggestions': []
131 }], 115 }
132 'selection': { 116 ],
133 'file': '/selection.dart', 117 'selection': {'file': '/selection.dart', 'offset': 42}
134 'offset': 42
135 }
136 }; 118 };
137 expect(change.toJson(), expectedJson); 119 expect(change.toJson(), expectedJson);
138 // some toString() 120 // some toString()
139 change.toString(); 121 change.toString();
140 } 122 }
141 } 123 }
142 124
143
144 @reflectiveTest 125 @reflectiveTest
145 class EditTest { 126 class EditTest {
146 void test_applySequence() { 127 void test_applySequence() {
147 SourceEdit edit1 = new SourceEdit(5, 2, 'abc'); 128 SourceEdit edit1 = new SourceEdit(5, 2, 'abc');
148 SourceEdit edit2 = new SourceEdit(1, 0, '!'); 129 SourceEdit edit2 = new SourceEdit(1, 0, '!');
149 expect( 130 expect(
150 SourceEdit.applySequence('0123456789', [edit1, edit2]), 131 SourceEdit.applySequence('0123456789', [edit1, edit2]), '0!1234abc789');
151 '0!1234abc789');
152 } 132 }
153 133
154 void test_editFromRange() { 134 void test_editFromRange() {
155 SourceRange range = new SourceRange(1, 2); 135 SourceRange range = new SourceRange(1, 2);
156 SourceEdit edit = newSourceEdit_range(range, 'foo'); 136 SourceEdit edit = newSourceEdit_range(range, 'foo');
157 expect(edit.offset, 1); 137 expect(edit.offset, 1);
158 expect(edit.length, 2); 138 expect(edit.length, 2);
159 expect(edit.replacement, 'foo'); 139 expect(edit.replacement, 'foo');
160 } 140 }
161 141
(...skipping 13 matching lines...) Expand all
175 expect(edit.replacement, 'foo'); 155 expect(edit.replacement, 'foo');
176 expect(edit.toJson(), { 156 expect(edit.toJson(), {
177 'offset': 1, 157 'offset': 1,
178 'length': 2, 158 'length': 2,
179 'replacement': 'foo', 159 'replacement': 'foo',
180 'id': 'my-id' 160 'id': 'my-id'
181 }); 161 });
182 } 162 }
183 void test_toJson() { 163 void test_toJson() {
184 SourceEdit edit = new SourceEdit(1, 2, 'foo'); 164 SourceEdit edit = new SourceEdit(1, 2, 'foo');
185 var expectedJson = { 165 var expectedJson = {OFFSET: 1, LENGTH: 2, REPLACEMENT: 'foo'};
186 OFFSET: 1,
187 LENGTH: 2,
188 REPLACEMENT: 'foo'
189 };
190 expect(edit.toJson(), expectedJson); 166 expect(edit.toJson(), expectedJson);
191 } 167 }
192
193 } 168 }
194 169
195
196 @reflectiveTest 170 @reflectiveTest
197 class FileEditTest { 171 class FileEditTest {
198 void test_add_sorts() { 172 void test_add_sorts() {
199 SourceEdit edit1a = new SourceEdit(1, 0, 'a1'); 173 SourceEdit edit1a = new SourceEdit(1, 0, 'a1');
200 SourceEdit edit1b = new SourceEdit(1, 0, 'a2'); 174 SourceEdit edit1b = new SourceEdit(1, 0, 'a2');
201 SourceEdit edit10 = new SourceEdit(10, 1, 'b'); 175 SourceEdit edit10 = new SourceEdit(10, 1, 'b');
202 SourceEdit edit100 = new SourceEdit(100, 2, 'c'); 176 SourceEdit edit100 = new SourceEdit(100, 2, 'c');
203 SourceFileEdit fileEdit = new SourceFileEdit('/test.dart', 0); 177 SourceFileEdit fileEdit = new SourceFileEdit('/test.dart', 0);
204 fileEdit.add(edit100); 178 fileEdit.add(edit100);
205 fileEdit.add(edit1a); 179 fileEdit.add(edit1a);
206 fileEdit.add(edit1b); 180 fileEdit.add(edit1b);
207 fileEdit.add(edit10); 181 fileEdit.add(edit10);
208 expect(fileEdit.edits, [edit100, edit10, edit1b, edit1a]); 182 expect(fileEdit.edits, [edit100, edit10, edit1b, edit1a]);
209 } 183 }
210 184
211 void test_addAll() { 185 void test_addAll() {
212 SourceEdit edit1a = new SourceEdit(1, 0, 'a1'); 186 SourceEdit edit1a = new SourceEdit(1, 0, 'a1');
213 SourceEdit edit1b = new SourceEdit(1, 0, 'a2'); 187 SourceEdit edit1b = new SourceEdit(1, 0, 'a2');
214 SourceEdit edit10 = new SourceEdit(10, 1, 'b'); 188 SourceEdit edit10 = new SourceEdit(10, 1, 'b');
215 SourceEdit edit100 = new SourceEdit(100, 2, 'c'); 189 SourceEdit edit100 = new SourceEdit(100, 2, 'c');
216 SourceFileEdit fileEdit = new SourceFileEdit('/test.dart', 0); 190 SourceFileEdit fileEdit = new SourceFileEdit('/test.dart', 0);
217 fileEdit.addAll([edit100, edit1a, edit10, edit1b]); 191 fileEdit.addAll([edit100, edit1a, edit10, edit1b]);
218 expect(fileEdit.edits, [edit100, edit10, edit1b, edit1a]); 192 expect(fileEdit.edits, [edit100, edit10, edit1b, edit1a]);
219 } 193 }
220 194
221 void test_new() { 195 void test_new() {
222 SourceFileEdit fileEdit = new SourceFileEdit('/test.dart', 100); 196 SourceFileEdit fileEdit = new SourceFileEdit('/test.dart', 100);
223 fileEdit.add(new SourceEdit(1, 2, 'aaa')); 197 fileEdit.add(new SourceEdit(1, 2, 'aaa'));
224 fileEdit.add(new SourceEdit(10, 20, 'bbb')); 198 fileEdit.add(new SourceEdit(10, 20, 'bbb'));
225 expect( 199 expect(fileEdit.toString(), '{"file":"/test.dart","fileStamp":100,"edits":['
226 fileEdit.toString(), 200 '{"offset":10,"length":20,"replacement":"bbb"},'
227 '{"file":"/test.dart","fileStamp":100,"edits":[' 201 '{"offset":1,"length":2,"replacement":"aaa"}]}');
228 '{"offset":10,"length":20,"replacement":"bbb"},'
229 '{"offset":1,"length":2,"replacement":"aaa"}]}');
230 } 202 }
231 203
232 void test_toJson() { 204 void test_toJson() {
233 SourceFileEdit fileEdit = new SourceFileEdit('/test.dart', 100); 205 SourceFileEdit fileEdit = new SourceFileEdit('/test.dart', 100);
234 fileEdit.add(new SourceEdit(1, 2, 'aaa')); 206 fileEdit.add(new SourceEdit(1, 2, 'aaa'));
235 fileEdit.add(new SourceEdit(10, 20, 'bbb')); 207 fileEdit.add(new SourceEdit(10, 20, 'bbb'));
236 var expectedJson = { 208 var expectedJson = {
237 FILE: '/test.dart', 209 FILE: '/test.dart',
238 FILE_STAMP: 100, 210 FILE_STAMP: 100,
239 EDITS: [{ 211 EDITS: [
240 OFFSET: 10, 212 {OFFSET: 10, LENGTH: 20, REPLACEMENT: 'bbb'},
241 LENGTH: 20, 213 {OFFSET: 1, LENGTH: 2, REPLACEMENT: 'aaa'},
242 REPLACEMENT: 'bbb' 214 ]
243 }, {
244 OFFSET: 1,
245 LENGTH: 2,
246 REPLACEMENT: 'aaa'
247 },]
248 }; 215 };
249 expect(fileEdit.toJson(), expectedJson); 216 expect(fileEdit.toJson(), expectedJson);
250 } 217 }
251 } 218 }
252 219
253
254 @reflectiveTest 220 @reflectiveTest
255 class LinkedEditGroupTest { 221 class LinkedEditGroupTest {
256 void test_new() { 222 void test_new() {
257 LinkedEditGroup group = new LinkedEditGroup.empty(); 223 LinkedEditGroup group = new LinkedEditGroup.empty();
258 group.addPosition(new Position('/a.dart', 1), 2); 224 group.addPosition(new Position('/a.dart', 1), 2);
259 group.addPosition(new Position('/b.dart', 10), 2); 225 group.addPosition(new Position('/b.dart', 10), 2);
260 expect( 226 expect(group.toString(), '{"positions":[' '{"file":"/a.dart","offset":1},'
261 group.toString(), 227 '{"file":"/b.dart","offset":10}],"length":2,"suggestions":[]}');
262 '{"positions":[' '{"file":"/a.dart","offset":1},'
263 '{"file":"/b.dart","offset":10}],"length":2,"suggestions":[]}');
264 } 228 }
265 229
266 void test_toJson() { 230 void test_toJson() {
267 LinkedEditGroup group = new LinkedEditGroup.empty(); 231 LinkedEditGroup group = new LinkedEditGroup.empty();
268 group.addPosition(new Position('/a.dart', 1), 2); 232 group.addPosition(new Position('/a.dart', 1), 2);
269 group.addPosition(new Position('/b.dart', 10), 2); 233 group.addPosition(new Position('/b.dart', 10), 2);
270 group.addSuggestion( 234 group.addSuggestion(
271 new LinkedEditSuggestion('AA', LinkedEditSuggestionKind.TYPE)); 235 new LinkedEditSuggestion('AA', LinkedEditSuggestionKind.TYPE));
272 group.addSuggestion( 236 group.addSuggestion(
273 new LinkedEditSuggestion('BB', LinkedEditSuggestionKind.TYPE)); 237 new LinkedEditSuggestion('BB', LinkedEditSuggestionKind.TYPE));
274 expect(group.toJson(), { 238 expect(group.toJson(), {
275 'length': 2, 239 'length': 2,
276 'positions': [{ 240 'positions': [
277 'file': '/a.dart', 241 {'file': '/a.dart', 'offset': 1},
278 'offset': 1 242 {'file': '/b.dart', 'offset': 10}
279 }, { 243 ],
280 'file': '/b.dart', 244 'suggestions': [
281 'offset': 10 245 {'kind': 'TYPE', 'value': 'AA'},
282 }], 246 {'kind': 'TYPE', 'value': 'BB'}
283 'suggestions': [{ 247 ]
284 'kind': 'TYPE',
285 'value': 'AA'
286 }, {
287 'kind': 'TYPE',
288 'value': 'BB'
289 }]
290 }); 248 });
291 } 249 }
292 } 250 }
293 251
294
295 @reflectiveTest 252 @reflectiveTest
296 class LinkedEditSuggestionTest { 253 class LinkedEditSuggestionTest {
297 void test_eqEq() { 254 void test_eqEq() {
298 var a = new LinkedEditSuggestion('a', LinkedEditSuggestionKind.METHOD); 255 var a = new LinkedEditSuggestion('a', LinkedEditSuggestionKind.METHOD);
299 var a2 = new LinkedEditSuggestion('a', LinkedEditSuggestionKind.METHOD); 256 var a2 = new LinkedEditSuggestion('a', LinkedEditSuggestionKind.METHOD);
300 var b = new LinkedEditSuggestion('a', LinkedEditSuggestionKind.TYPE); 257 var b = new LinkedEditSuggestion('a', LinkedEditSuggestionKind.TYPE);
301 var c = new LinkedEditSuggestion('c', LinkedEditSuggestionKind.METHOD); 258 var c = new LinkedEditSuggestion('c', LinkedEditSuggestionKind.METHOD);
302 expect(a == a, isTrue); 259 expect(a == a, isTrue);
303 expect(a == a2, isTrue); 260 expect(a == a2, isTrue);
304 expect(a == this, isFalse); 261 expect(a == this, isFalse);
305 expect(a == b, isFalse); 262 expect(a == b, isFalse);
306 expect(a == c, isFalse); 263 expect(a == c, isFalse);
307 } 264 }
308 } 265 }
309 266
310
311 @reflectiveTest 267 @reflectiveTest
312 class PositionTest { 268 class PositionTest {
313 void test_eqEq() { 269 void test_eqEq() {
314 Position a = new Position('/a.dart', 1); 270 Position a = new Position('/a.dart', 1);
315 Position a2 = new Position('/a.dart', 1); 271 Position a2 = new Position('/a.dart', 1);
316 Position b = new Position('/b.dart', 1); 272 Position b = new Position('/b.dart', 1);
317 expect(a == a, isTrue); 273 expect(a == a, isTrue);
318 expect(a == a2, isTrue); 274 expect(a == a2, isTrue);
319 expect(a == b, isFalse); 275 expect(a == b, isFalse);
320 expect(a == this, isFalse); 276 expect(a == this, isFalse);
321 } 277 }
322 278
323 void test_hashCode() { 279 void test_hashCode() {
324 Position position = new Position('/test.dart', 1); 280 Position position = new Position('/test.dart', 1);
325 position.hashCode; 281 position.hashCode;
326 } 282 }
327 283
328 void test_new() { 284 void test_new() {
329 Position position = new Position('/test.dart', 1); 285 Position position = new Position('/test.dart', 1);
330 expect(position.file, '/test.dart'); 286 expect(position.file, '/test.dart');
331 expect(position.offset, 1); 287 expect(position.offset, 1);
332 expect(position.toString(), '{"file":"/test.dart","offset":1}'); 288 expect(position.toString(), '{"file":"/test.dart","offset":1}');
333 } 289 }
334 290
335 void test_toJson() { 291 void test_toJson() {
336 Position position = new Position('/test.dart', 1); 292 Position position = new Position('/test.dart', 1);
337 var expectedJson = { 293 var expectedJson = {FILE: '/test.dart', OFFSET: 1};
338 FILE: '/test.dart',
339 OFFSET: 1
340 };
341 expect(position.toJson(), expectedJson); 294 expect(position.toJson(), expectedJson);
342 } 295 }
343 } 296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698