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

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

Issue 472613002: Update analysis server and integration tests to match new ChangeContentOverlay. (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_services/correction/assist.dart'; 7 import 'package:analysis_services/correction/assist.dart';
8 import 'package:analysis_services/correction/change.dart'; 8 import 'package:analysis_services/correction/change.dart';
9 import 'package:analysis_services/index/index.dart'; 9 import 'package:analysis_services/index/index.dart';
10 import 'package:analysis_services/index/local_memory_index.dart'; 10 import 'package:analysis_services/index/local_memory_index.dart';
11 import 'package:analysis_services/src/search/search_engine.dart'; 11 import 'package:analysis_services/src/search/search_engine.dart';
12 import 'package:analysis_testing/abstract_single_unit.dart'; 12 import 'package:analysis_testing/abstract_single_unit.dart';
13 import 'package:analysis_testing/reflective_tests.dart'; 13 import 'package:analysis_testing/reflective_tests.dart';
14 import 'package:collection/collection.dart';
15 import 'package:unittest/unittest.dart'; 14 import 'package:unittest/unittest.dart';
16 15
17 16
18 main() { 17 main() {
19 groupSep = ' | '; 18 groupSep = ' | ';
20 runReflectiveTests(AssistProcessorTest); 19 runReflectiveTests(AssistProcessorTest);
21 } 20 }
22 21
23 22
24 @ReflectiveTestCase() 23 @ReflectiveTestCase()
(...skipping 12 matching lines...) Expand all
37 /** 36 /**
38 * Asserts that there is an [Assist] of the given [kind] at [offset] which 37 * Asserts that there is an [Assist] of the given [kind] at [offset] which
39 * produces the [expected] code when applied to [testCode]. 38 * produces the [expected] code when applied to [testCode].
40 */ 39 */
41 void assertHasAssist(AssistKind kind, String expected) { 40 void assertHasAssist(AssistKind kind, String expected) {
42 assist = _assertHasAssist(kind); 41 assist = _assertHasAssist(kind);
43 change = assist.change; 42 change = assist.change;
44 // apply to "file" 43 // apply to "file"
45 List<FileEdit> fileEdits = change.fileEdits; 44 List<FileEdit> fileEdits = change.fileEdits;
46 expect(fileEdits, hasLength(1)); 45 expect(fileEdits, hasLength(1));
47 resultCode = _applyEdits(testCode, change.fileEdits[0].edits); 46 // TODO(paulberry): should the code under test be responsible for sorting
47 // the edits?
48 resultCode = Edit.applySorted(testCode, change.fileEdits[0].edits);
48 // verify 49 // verify
49 expect(resultCode, expected); 50 expect(resultCode, expected);
50 } 51 }
51 52
52 /** 53 /**
53 * Calls [assertHasAssist] at the offset of [offsetSearch] in [testCode]. 54 * Calls [assertHasAssist] at the offset of [offsetSearch] in [testCode].
54 */ 55 */
55 void assertHasAssistAt(String offsetSearch, AssistKind kind, 56 void assertHasAssistAt(String offsetSearch, AssistKind kind,
56 String expected) { 57 String expected) {
57 offset = findOffset(offsetSearch); 58 offset = findOffset(offsetSearch);
(...skipping 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2182 // start 2183 // start
2183 while (condition) { 2184 while (condition) {
2184 print(0); 2185 print(0);
2185 print(1); 2186 print(1);
2186 } 2187 }
2187 // end 2188 // end
2188 } 2189 }
2189 '''); 2190 ''');
2190 } 2191 }
2191 2192
2192 String _applyEdits(String code, List<Edit> edits) {
2193 mergeSort(edits, compare: (a, b) => a.offset - b.offset);
2194 edits.reversed.forEach((Edit edit) {
2195 code = code.substring(0, edit.offset) +
2196 edit.replacement +
2197 code.substring(edit.end);
2198 });
2199 return code;
2200 }
2201
2202 /** 2193 /**
2203 * Computes assists and verifies that there is an assist of the given kind. 2194 * Computes assists and verifies that there is an assist of the given kind.
2204 */ 2195 */
2205 Assist _assertHasAssist(AssistKind kind) { 2196 Assist _assertHasAssist(AssistKind kind) {
2206 List<Assist> assists = 2197 List<Assist> assists =
2207 computeAssists(searchEngine, testUnit, offset, length); 2198 computeAssists(searchEngine, testUnit, offset, length);
2208 for (Assist assist in assists) { 2199 for (Assist assist in assists) {
2209 if (assist.kind == kind) { 2200 if (assist.kind == kind) {
2210 return assist; 2201 return assist;
2211 } 2202 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2249 void _indexTestUnit(String code) { 2240 void _indexTestUnit(String code) {
2250 resolveTestUnit(code); 2241 resolveTestUnit(code);
2251 index.indexUnit(context, testUnit); 2242 index.indexUnit(context, testUnit);
2252 } 2243 }
2253 2244
2254 void _setStartEndSelection() { 2245 void _setStartEndSelection() {
2255 offset = findOffset('// start\n') + '// start\n'.length; 2246 offset = findOffset('// start\n') + '// start\n'.length;
2256 length = findOffset('// end') - offset; 2247 length = findOffset('// end') - offset;
2257 } 2248 }
2258 } 2249 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/lib/correction/change.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