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

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

Issue 473563003: Sort separate Edits in FileEdit during adding. (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_services/constants.dart'; 7 import 'package:analysis_services/constants.dart';
8 import 'package:analysis_services/correction/change.dart'; 8 import 'package:analysis_services/correction/change.dart';
9 import 'package:analysis_testing/reflective_tests.dart'; 9 import 'package:analysis_testing/reflective_tests.dart';
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 12
13 13
14 main() { 14 main() {
15 groupSep = ' | '; 15 groupSep = ' | ';
16 runReflectiveTests(ChangeTest); 16 runReflectiveTests(ChangeTest);
17 runReflectiveTests(EditTest); 17 runReflectiveTests(EditTest);
18 runReflectiveTests(FileEditTest); 18 runReflectiveTests(FileEditTest);
19 runReflectiveTests(LinkedEditGroupTest); 19 runReflectiveTests(LinkedEditGroupTest);
20 runReflectiveTests(LinkedEditSuggestionTest); 20 runReflectiveTests(LinkedEditSuggestionTest);
21 runReflectiveTests(PositionTest); 21 runReflectiveTests(PositionTest);
22 } 22 }
23 23
24 24
25 @ReflectiveTestCase() 25 @ReflectiveTestCase()
26 class ChangeTest { 26 class ChangeTest {
27 void test_getFileEdit_empty() {
28 Change change = new Change('msg');
29 expect(change.getFileEdit('/some.dart'), isNull);
30 }
31
32 void test_addEdit() { 27 void test_addEdit() {
33 Change change = new Change('msg'); 28 Change change = new Change('msg');
34 Edit edit1 = new Edit(1, 2, 'a'); 29 Edit edit1 = new Edit(1, 2, 'a');
35 Edit edit2 = new Edit(1, 2, 'b'); 30 Edit edit2 = new Edit(1, 2, 'b');
36 expect(change.fileEdits, hasLength(0)); 31 expect(change.fileEdits, hasLength(0));
37 change.addEdit('/a.dart', edit1); 32 change.addEdit('/a.dart', edit1);
38 expect(change.fileEdits, hasLength(1)); 33 expect(change.fileEdits, hasLength(1));
39 change.addEdit('/a.dart', edit2); 34 change.addEdit('/a.dart', edit2);
40 expect(change.fileEdits, hasLength(1)); 35 expect(change.fileEdits, hasLength(1));
41 { 36 {
42 FileEdit fileEdit = change.getFileEdit('/a.dart'); 37 FileEdit fileEdit = change.getFileEdit('/a.dart');
43 expect(fileEdit, isNotNull); 38 expect(fileEdit, isNotNull);
44 expect(fileEdit.edits, unorderedEquals([edit1, edit2])); 39 expect(fileEdit.edits, unorderedEquals([edit1, edit2]));
45 } 40 }
46 } 41 }
47 42
48 void test_getFileEdit() { 43 void test_getFileEdit() {
49 Change change = new Change('msg'); 44 Change change = new Change('msg');
50 FileEdit fileEdit = new FileEdit('/a.dart'); 45 FileEdit fileEdit = new FileEdit('/a.dart');
51 change.addFileEdit(fileEdit); 46 change.addFileEdit(fileEdit);
52 expect(change.getFileEdit('/a.dart'), fileEdit); 47 expect(change.getFileEdit('/a.dart'), fileEdit);
53 } 48 }
54 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() { 55 void test_toJson() {
56 Change change = new Change('msg'); 56 Change change = new Change('msg');
57 change.addFileEdit(new FileEdit('/a.dart') 57 change.addFileEdit(new FileEdit('/a.dart')
58 ..add(new Edit(1, 2, 'aaa')) 58 ..add(new Edit(1, 2, 'aaa'))
59 ..add(new Edit(10, 20, 'bbb'))); 59 ..add(new Edit(10, 20, 'bbb')));
60 change.addFileEdit(new FileEdit('/b.dart') 60 change.addFileEdit(new FileEdit('/b.dart')
61 ..add(new Edit(21, 22, 'xxx')) 61 ..add(new Edit(21, 22, 'xxx'))
62 ..add(new Edit(210, 220, 'yyy'))); 62 ..add(new Edit(210, 220, 'yyy')));
63 { 63 {
64 var group = new LinkedEditGroup('id-a'); 64 var group = new LinkedEditGroup('id-a');
65 change.addLinkedEditGroup(group 65 change.addLinkedEditGroup(group
66 ..addPosition(new Position('/ga.dart', 1), 2) 66 ..addPosition(new Position('/ga.dart', 1), 2)
67 ..addPosition(new Position('/ga.dart', 10), 2)); 67 ..addPosition(new Position('/ga.dart', 10), 2));
68 group.addSuggestion( 68 group.addSuggestion(
69 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'AA')); 69 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'AA'));
70 group.addSuggestion( 70 group.addSuggestion(
71 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'BB')); 71 new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'BB'));
72 } 72 }
73 change.addLinkedEditGroup(new LinkedEditGroup('id-b') 73 change.addLinkedEditGroup(new LinkedEditGroup('id-b')
74 ..addPosition(new Position('/gb.dart', 10), 5) 74 ..addPosition(new Position('/gb.dart', 10), 5)
75 ..addPosition(new Position('/gb.dart', 100), 5)); 75 ..addPosition(new Position('/gb.dart', 100), 5));
76 change.selection = new Position('/selection.dart', 42); 76 change.selection = new Position('/selection.dart', 42);
77 var expectedJson = { 77 var expectedJson = {
78 'message': 'msg', 78 'message': 'msg',
79 'edits': [{ 79 'edits': [{
80 'file': '/a.dart', 80 'file': '/a.dart',
81 'edits': [{ 81 'edits': [{
82 'offset': 10,
83 'length': 20,
84 'replacement': 'bbb'
85 }, {
82 'offset': 1, 86 'offset': 1,
83 'length': 2, 87 'length': 2,
84 'replacement': 'aaa' 88 'replacement': 'aaa'
85 }, {
86 'offset': 10,
87 'length': 20,
88 'replacement': 'bbb'
89 }] 89 }]
90 }, { 90 }, {
91 'file': '/b.dart', 91 'file': '/b.dart',
92 'edits': [{ 92 'edits': [{
93 'offset': 210,
94 'length': 220,
95 'replacement': 'yyy'
96 }, {
93 'offset': 21, 97 'offset': 21,
94 'length': 22, 98 'length': 22,
95 'replacement': 'xxx' 99 'replacement': 'xxx'
96 }, {
97 'offset': 210,
98 'length': 220,
99 'replacement': 'yyy'
100 }] 100 }]
101 }], 101 }],
102 'linkedEditGroups': [{ 102 'linkedEditGroups': [{
103 'id': 'id-a', 103 'id': 'id-a',
104 'length': 2, 104 'length': 2,
105 'positions': [{ 105 'positions': [{
106 'file': '/ga.dart', 106 'file': '/ga.dart',
107 'offset': 1 107 'offset': 1
108 }, { 108 }, {
109 'file': '/ga.dart', 109 'file': '/ga.dart',
(...skipping 25 matching lines...) Expand all
135 }; 135 };
136 expect(change.toJson(), expectedJson); 136 expect(change.toJson(), expectedJson);
137 // some toString() 137 // some toString()
138 change.toString(); 138 change.toString();
139 } 139 }
140 } 140 }
141 141
142 142
143 @ReflectiveTestCase() 143 @ReflectiveTestCase()
144 class EditTest { 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
145 void test_end() { 151 void test_end() {
146 Edit edit = new Edit(1, 2, 'foo'); 152 Edit edit = new Edit(1, 2, 'foo');
147 expect(edit.end, 3); 153 expect(edit.end, 3);
148 } 154 }
149 155
150 void test_eqEq() { 156 void test_eqEq() {
151 Edit a = new Edit(1, 2, 'aaa'); 157 Edit a = new Edit(1, 2, 'aaa');
152 Edit a2 = new Edit(1, 2, 'aaa'); 158 Edit a2 = new Edit(1, 2, 'aaa');
153 Edit b = new Edit(1, 2, 'aaa'); 159 Edit b = new Edit(1, 2, 'aaa');
154 expect(a == a, isTrue); 160 expect(a == a, isTrue);
(...skipping 26 matching lines...) Expand all
181 REPLACEMENT: 'foo' 187 REPLACEMENT: 'foo'
182 }; 188 };
183 expect(edit.toJson(), expectedJson); 189 expect(edit.toJson(), expectedJson);
184 } 190 }
185 191
186 } 192 }
187 193
188 194
189 @ReflectiveTestCase() 195 @ReflectiveTestCase()
190 class FileEditTest { 196 class FileEditTest {
197 void test_addAll() {
198 Edit edit1a = new Edit(1, 0, 'a1');
199 Edit edit1b = new Edit(1, 0, 'a2');
200 Edit edit10 = new Edit(10, 1, 'b');
201 Edit edit100 = new Edit(100, 2, 'c');
202 FileEdit fileEdit = new FileEdit('/test.dart');
203 fileEdit.addAll([edit100, edit1a, edit10, edit1b]);
204 expect(fileEdit.edits, [edit100, edit10, edit1b, edit1a]);
205 }
206
207 void test_add_sorts() {
208 Edit edit1a = new Edit(1, 0, 'a1');
209 Edit edit1b = new Edit(1, 0, 'a2');
210 Edit edit10 = new Edit(10, 1, 'b');
211 Edit edit100 = new Edit(100, 2, 'c');
212 FileEdit fileEdit = new FileEdit('/test.dart');
213 fileEdit.add(edit100);
214 fileEdit.add(edit1a);
215 fileEdit.add(edit1b);
216 fileEdit.add(edit10);
217 expect(fileEdit.edits, [edit100, edit10, edit1b, edit1a]);
218 }
219
191 void test_new() { 220 void test_new() {
192 FileEdit fileEdit = new FileEdit('/test.dart'); 221 FileEdit fileEdit = new FileEdit('/test.dart');
193 fileEdit.add(new Edit(1, 2, 'aaa')); 222 fileEdit.add(new Edit(1, 2, 'aaa'));
194 fileEdit.add(new Edit(10, 20, 'bbb')); 223 fileEdit.add(new Edit(10, 20, 'bbb'));
195 expect( 224 expect(
196 fileEdit.toString(), 225 fileEdit.toString(),
197 'FileEdit(file=/test.dart, edits=[' 226 'FileEdit(file=/test.dart, edits=['
198 'Edit(offset=1, length=2, replacement=:>aaa<:), ' 227 'Edit(offset=10, length=20, replacement=:>bbb<:), '
199 'Edit(offset=10, length=20, replacement=:>bbb<:)])'); 228 'Edit(offset=1, length=2, replacement=:>aaa<:)])');
200 } 229 }
201 230
202 void test_toJson() { 231 void test_toJson() {
203 FileEdit fileEdit = new FileEdit('/test.dart'); 232 FileEdit fileEdit = new FileEdit('/test.dart');
204 fileEdit.add(new Edit(1, 2, 'aaa')); 233 fileEdit.add(new Edit(1, 2, 'aaa'));
205 fileEdit.add(new Edit(10, 20, 'bbb')); 234 fileEdit.add(new Edit(10, 20, 'bbb'));
206 var expectedJson = { 235 var expectedJson = {
207 FILE: '/test.dart', 236 FILE: '/test.dart',
208 EDITS: [{ 237 EDITS: [{
238 OFFSET: 10,
239 LENGTH: 20,
240 REPLACEMENT: 'bbb'
241 }, {
209 OFFSET: 1, 242 OFFSET: 1,
210 LENGTH: 2, 243 LENGTH: 2,
211 REPLACEMENT: 'aaa' 244 REPLACEMENT: 'aaa'
212 }, {
213 OFFSET: 10,
214 LENGTH: 20,
215 REPLACEMENT: 'bbb'
216 },] 245 },]
217 }; 246 };
218 expect(fileEdit.toJson(), expectedJson); 247 expect(fileEdit.toJson(), expectedJson);
219 } 248 }
220 } 249 }
221 250
222 251
223 @ReflectiveTestCase() 252 @ReflectiveTestCase()
224 class LinkedEditGroupTest { 253 class LinkedEditGroupTest {
225 void test_new() { 254 void test_new() {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 334
306 void test_toJson() { 335 void test_toJson() {
307 Position position = new Position('/test.dart', 1); 336 Position position = new Position('/test.dart', 1);
308 var expectedJson = { 337 var expectedJson = {
309 FILE: '/test.dart', 338 FILE: '/test.dart',
310 OFFSET: 1 339 OFFSET: 1
311 }; 340 };
312 expect(position.toJson(), expectedJson); 341 expect(position.toJson(), expectedJson);
313 } 342 }
314 } 343 }
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