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

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

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