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

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

Issue 495733002: Don't use LinkedEditGroup.id. (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.assist; 5 library test.services.correction.assist;
6 6
7 import 'package:analysis_server/src/services/correction/assist.dart'; 7 import 'package:analysis_server/src/services/correction/assist.dart';
8 import 'package:analysis_server/src/services/correction/change.dart'; 8 import 'package:analysis_server/src/services/correction/change.dart';
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 10 import 'package:analysis_server/src/services/index/local_memory_index.dart';
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 /** 51 /**
52 * Calls [assertHasAssist] at the offset of [offsetSearch] in [testCode]. 52 * Calls [assertHasAssist] at the offset of [offsetSearch] in [testCode].
53 */ 53 */
54 void assertHasAssistAt(String offsetSearch, AssistKind kind, 54 void assertHasAssistAt(String offsetSearch, AssistKind kind,
55 String expected) { 55 String expected) {
56 offset = findOffset(offsetSearch); 56 offset = findOffset(offsetSearch);
57 assertHasAssist(kind, expected); 57 assertHasAssist(kind, expected);
58 } 58 }
59 59
60 void assertHasPositionGroup(String id, int expectedLength,
61 List<Position> expectedPositions) {
62 List<LinkedEditGroup> linkedPositionGroups = change.linkedEditGroups;
63 for (LinkedEditGroup group in linkedPositionGroups) {
64 if (group.id == id) {
65 expect(group.length, expectedLength);
66 expect(group.positions, unorderedEquals(expectedPositions));
67 linkedPositionGroup = group;
68 return;
69 }
70 }
71 fail('No PositionGroup with id=$id found in $linkedPositionGroups');
72 }
73
74 /** 60 /**
75 * Asserts that there is no [Assist] of the given [kind] at [offset]. 61 * Asserts that there is no [Assist] of the given [kind] at [offset].
76 */ 62 */
77 void assertNoAssist(AssistKind kind) { 63 void assertNoAssist(AssistKind kind) {
78 List<Assist> assists = 64 List<Assist> assists =
79 computeAssists(searchEngine, testUnit, offset, length); 65 computeAssists(searchEngine, testUnit, offset, length);
80 for (Assist assist in assists) { 66 for (Assist assist in assists) {
81 if (assist.kind == kind) { 67 if (assist.kind == kind) {
82 throw fail('Unexpected assist $kind in\n${assists.join('\n')}'); 68 throw fail('Unexpected assist $kind in\n${assists.join('\n')}');
83 } 69 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 288 }
303 List<int> readBytes() => <int>[]; 289 List<int> readBytes() => <int>[];
304 '''); 290 ''');
305 assertHasAssistAt('readBytes();', AssistKind.ASSIGN_TO_LOCAL_VARIABLE, ''' 291 assertHasAssistAt('readBytes();', AssistKind.ASSIGN_TO_LOCAL_VARIABLE, '''
306 main() { 292 main() {
307 List<int> bytes; 293 List<int> bytes;
308 var readBytes = readBytes(); 294 var readBytes = readBytes();
309 } 295 }
310 List<int> readBytes() => <int>[]; 296 List<int> readBytes() => <int>[];
311 '''); 297 ''');
312 assertHasPositionGroup('NAME', 9, expectedPositions(['readBytes = '])); 298 _assertLinkedGroup(
313 expect( 299 change.linkedEditGroups[0],
314 linkedPositionGroup.suggestions, 300 ['readBytes = '],
315 unorderedEquals( 301 expectedSuggestions(
316 expectedSuggestions( 302 LinkedEditSuggestionKind.VARIABLE,
317 LinkedEditSuggestionKind.VARIABLE, 303 ['list', 'bytes2', 'readBytes']));
318 ['list', 'bytes2', 'readBytes'])));
319 } 304 }
320 305
321 void test_assignToLocalVariable_alreadyAssignment() { 306 void test_assignToLocalVariable_alreadyAssignment() {
322 _indexTestUnit(''' 307 _indexTestUnit('''
323 main() { 308 main() {
324 var vvv; 309 var vvv;
325 vvv = 42; 310 vvv = 42;
326 } 311 }
327 '''); 312 ''');
328 assertNoAssistAt('vvv =', AssistKind.ASSIGN_TO_LOCAL_VARIABLE); 313 assertNoAssistAt('vvv =', AssistKind.ASSIGN_TO_LOCAL_VARIABLE);
(...skipping 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 List<Assist> assists = 2180 List<Assist> assists =
2196 computeAssists(searchEngine, testUnit, offset, length); 2181 computeAssists(searchEngine, testUnit, offset, length);
2197 for (Assist assist in assists) { 2182 for (Assist assist in assists) {
2198 if (assist.kind == kind) { 2183 if (assist.kind == kind) {
2199 return assist; 2184 return assist;
2200 } 2185 }
2201 } 2186 }
2202 throw fail('Expected to find assist $kind in\n${assists.join('\n')}'); 2187 throw fail('Expected to find assist $kind in\n${assists.join('\n')}');
2203 } 2188 }
2204 2189
2205 void _assertHasLinkedPositions(String groupId, List<String> expectedStrings) { 2190 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings,
2191 [List<LinkedEditSuggestion> expectedSuggestions]) {
2206 List<Position> expectedPositions = _findResultPositions(expectedStrings); 2192 List<Position> expectedPositions = _findResultPositions(expectedStrings);
2207 List<LinkedEditGroup> groups = change.linkedEditGroups; 2193 expect(group.positions, unorderedEquals(expectedPositions));
2208 for (LinkedEditGroup group in groups) { 2194 if (expectedSuggestions != null) {
2209 if (group.id == groupId) { 2195 expect(group.suggestions, unorderedEquals(expectedSuggestions));
2210 List<Position> actualPositions = group.positions;
2211 expect(actualPositions, unorderedEquals(expectedPositions));
2212 return;
2213 }
2214 } 2196 }
2215 fail('No group with ID=$groupId foind in\n${groups.join('\n')}');
2216 }
2217
2218 void _assertHasLinkedProposals(String groupId, List<String> expected) {
2219 List<LinkedEditGroup> groups = change.linkedEditGroups;
2220 for (LinkedEditGroup group in groups) {
2221 if (group.id == groupId) {
2222 expect(group.suggestions, expected);
2223 return;
2224 }
2225 }
2226 fail('No group with ID=$groupId foind in\n${groups.join('\n')}');
2227 } 2197 }
2228 2198
2229 List<Position> _findResultPositions(List<String> searchStrings) { 2199 List<Position> _findResultPositions(List<String> searchStrings) {
2230 List<Position> positions = <Position>[]; 2200 List<Position> positions = <Position>[];
2231 for (String search in searchStrings) { 2201 for (String search in searchStrings) {
2232 int offset = resultCode.indexOf(search); 2202 int offset = resultCode.indexOf(search);
2233 positions.add(new Position(testFile, offset)); 2203 positions.add(new Position(testFile, offset));
2234 } 2204 }
2235 return positions; 2205 return positions;
2236 } 2206 }
2237 2207
2238 void _indexTestUnit(String code) { 2208 void _indexTestUnit(String code) {
2239 resolveTestUnit(code); 2209 resolveTestUnit(code);
2240 index.indexUnit(context, testUnit); 2210 index.indexUnit(context, testUnit);
2241 } 2211 }
2242 2212
2243 void _setStartEndSelection() { 2213 void _setStartEndSelection() {
2244 offset = findOffset('// start\n') + '// start\n'.length; 2214 offset = findOffset('// start\n') + '// start\n'.length;
2245 length = findOffset('// end') - offset; 2215 length = findOffset('// end') - offset;
2246 } 2216 }
2247 } 2217 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698