| OLD | NEW |
| 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/protocol2.dart' show SourceEdit, | 7 import 'package:analysis_server/src/protocol2.dart'; |
| 8 SourceFileEdit, Position; | |
| 9 import 'package:analysis_server/src/services/correction/assist.dart'; | 8 import 'package:analysis_server/src/services/correction/assist.dart'; |
| 10 import 'package:analysis_server/src/services/correction/change.dart'; | |
| 11 import 'package:analysis_server/src/services/index/index.dart'; | 9 import 'package:analysis_server/src/services/index/index.dart'; |
| 12 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
| 13 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 11 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 14 import 'package:analysis_testing/abstract_single_unit.dart'; | 12 import 'package:analysis_testing/abstract_single_unit.dart'; |
| 15 import 'package:analysis_testing/reflective_tests.dart'; | 13 import 'package:analysis_testing/reflective_tests.dart'; |
| 16 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
| 17 | 15 |
| 18 | 16 |
| 19 main() { | 17 main() { |
| 20 groupSep = ' | '; | 18 groupSep = ' | '; |
| 21 runReflectiveTests(AssistProcessorTest); | 19 runReflectiveTests(AssistProcessorTest); |
| 22 } | 20 } |
| 23 | 21 |
| 24 | 22 |
| 25 @ReflectiveTestCase() | 23 @ReflectiveTestCase() |
| 26 class AssistProcessorTest extends AbstractSingleUnitTest { | 24 class AssistProcessorTest extends AbstractSingleUnitTest { |
| 27 Index index; | 25 Index index; |
| 28 SearchEngineImpl searchEngine; | 26 SearchEngineImpl searchEngine; |
| 29 | 27 |
| 30 int offset; | 28 int offset; |
| 31 int length; | 29 int length; |
| 32 | 30 |
| 33 Assist assist; | 31 Assist assist; |
| 34 Change change; | 32 SourceChange change; |
| 35 String resultCode; | 33 String resultCode; |
| 36 LinkedEditGroup linkedPositionGroup; | 34 LinkedEditGroup linkedPositionGroup; |
| 37 | 35 |
| 38 /** | 36 /** |
| 39 * 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 |
| 40 * produces the [expected] code when applied to [testCode]. | 38 * produces the [expected] code when applied to [testCode]. |
| 41 */ | 39 */ |
| 42 void assertHasAssist(AssistKind kind, String expected) { | 40 void assertHasAssist(AssistKind kind, String expected) { |
| 43 assist = _assertHasAssist(kind); | 41 assist = _assertHasAssist(kind); |
| 44 change = assist.change; | 42 change = assist.change; |
| 45 // apply to "file" | 43 // apply to "file" |
| 46 List<SourceFileEdit> fileEdits = change.fileEdits; | 44 List<SourceFileEdit> fileEdits = change.edits; |
| 47 expect(fileEdits, hasLength(1)); | 45 expect(fileEdits, hasLength(1)); |
| 48 resultCode = SourceEdit.applySequence(testCode, change.fileEdits[0].edits); | 46 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
| 49 // verify | 47 // verify |
| 50 expect(resultCode, expected); | 48 expect(resultCode, expected); |
| 51 } | 49 } |
| 52 | 50 |
| 53 /** | 51 /** |
| 54 * Calls [assertHasAssist] at the offset of [offsetSearch] in [testCode]. | 52 * Calls [assertHasAssist] at the offset of [offsetSearch] in [testCode]. |
| 55 */ | 53 */ |
| 56 void assertHasAssistAt(String offsetSearch, AssistKind kind, | 54 void assertHasAssistAt(String offsetSearch, AssistKind kind, |
| 57 String expected) { | 55 String expected) { |
| 58 offset = findOffset(offsetSearch); | 56 offset = findOffset(offsetSearch); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 89 List<Position> positions = <Position>[]; | 87 List<Position> positions = <Position>[]; |
| 90 patterns.forEach((String search) { | 88 patterns.forEach((String search) { |
| 91 positions.add(expectedPosition(search)); | 89 positions.add(expectedPosition(search)); |
| 92 }); | 90 }); |
| 93 return positions; | 91 return positions; |
| 94 } | 92 } |
| 95 | 93 |
| 96 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind, | 94 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind, |
| 97 List<String> values) { | 95 List<String> values) { |
| 98 return values.map((value) { | 96 return values.map((value) { |
| 99 return new LinkedEditSuggestion(kind, value); | 97 return new LinkedEditSuggestion(value, kind); |
| 100 }).toList(); | 98 }).toList(); |
| 101 } | 99 } |
| 102 | 100 |
| 103 void setUp() { | 101 void setUp() { |
| 104 super.setUp(); | 102 super.setUp(); |
| 105 index = createLocalMemoryIndex(); | 103 index = createLocalMemoryIndex(); |
| 106 searchEngine = new SearchEngineImpl(index); | 104 searchEngine = new SearchEngineImpl(index); |
| 107 offset = 0; | 105 offset = 0; |
| 108 length = 0; | 106 length = 0; |
| 109 } | 107 } |
| (...skipping 2100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2210 void _indexTestUnit(String code) { | 2208 void _indexTestUnit(String code) { |
| 2211 resolveTestUnit(code); | 2209 resolveTestUnit(code); |
| 2212 index.indexUnit(context, testUnit); | 2210 index.indexUnit(context, testUnit); |
| 2213 } | 2211 } |
| 2214 | 2212 |
| 2215 void _setStartEndSelection() { | 2213 void _setStartEndSelection() { |
| 2216 offset = findOffset('// start\n') + '// start\n'.length; | 2214 offset = findOffset('// start\n') + '// start\n'.length; |
| 2217 length = findOffset('// end') - offset; | 2215 length = findOffset('// end') - offset; |
| 2218 } | 2216 } |
| 2219 } | 2217 } |
| OLD | NEW |