| 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.fix; | 5 library test.services.correction.fix; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol2.dart' show SourceEdit, | 7 import 'package:analysis_server/src/protocol2.dart' show LinkedEditGroup, |
| 8 SourceFileEdit, Position; | 8 LinkedEditSuggestion, LinkedEditSuggestionKind, Position, SourceChange, |
| 9 import 'package:analysis_server/src/services/correction/change.dart'; | 9 SourceEdit, SourceFileEdit; |
| 10 import 'package:analysis_server/src/services/correction/fix.dart'; | 10 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 11 import 'package:analysis_server/src/services/index/index.dart'; | 11 import 'package:analysis_server/src/services/index/index.dart'; |
| 12 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 12 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
| 13 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 13 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 14 import 'package:analysis_testing/abstract_context.dart'; | 14 import 'package:analysis_testing/abstract_context.dart'; |
| 15 import 'package:analysis_testing/abstract_single_unit.dart'; | 15 import 'package:analysis_testing/abstract_single_unit.dart'; |
| 16 import 'package:analysis_testing/reflective_tests.dart'; | 16 import 'package:analysis_testing/reflective_tests.dart'; |
| 17 import 'package:analyzer/file_system/file_system.dart'; | 17 import 'package:analyzer/file_system/file_system.dart'; |
| 18 import 'package:analyzer/source/package_map_resolver.dart'; | 18 import 'package:analyzer/source/package_map_resolver.dart'; |
| 19 import 'package:analyzer/src/generated/error.dart'; | 19 import 'package:analyzer/src/generated/error.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 21 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
| 22 | 22 |
| 23 | 23 |
| 24 main() { | 24 main() { |
| 25 groupSep = ' | '; | 25 groupSep = ' | '; |
| 26 runReflectiveTests(FixProcessorTest); | 26 runReflectiveTests(FixProcessorTest); |
| 27 } | 27 } |
| 28 | 28 |
| 29 | 29 |
| 30 @ReflectiveTestCase() | 30 @ReflectiveTestCase() |
| 31 class FixProcessorTest extends AbstractSingleUnitTest { | 31 class FixProcessorTest extends AbstractSingleUnitTest { |
| 32 Index index; | 32 Index index; |
| 33 SearchEngineImpl searchEngine; | 33 SearchEngineImpl searchEngine; |
| 34 | 34 |
| 35 Fix fix; | 35 Fix fix; |
| 36 Change change; | 36 SourceChange change; |
| 37 String resultCode; | 37 String resultCode; |
| 38 | 38 |
| 39 void assertHasFix(FixKind kind, String expected) { | 39 void assertHasFix(FixKind kind, String expected) { |
| 40 AnalysisError error = _findErrorToFix(); | 40 AnalysisError error = _findErrorToFix(); |
| 41 fix = _assertHasFix(kind, error); | 41 fix = _assertHasFix(kind, error); |
| 42 change = fix.change; | 42 change = fix.change; |
| 43 // apply to "file" | 43 // apply to "file" |
| 44 List<SourceFileEdit> fileEdits = change.fileEdits; | 44 List<SourceFileEdit> fileEdits = change.edits; |
| 45 expect(fileEdits, hasLength(1)); | 45 expect(fileEdits, hasLength(1)); |
| 46 resultCode = SourceEdit.applySequence(testCode, change.fileEdits[0].edits); | 46 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
| 47 // verify | 47 // verify |
| 48 expect(resultCode, expected); | 48 expect(resultCode, expected); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void assertNoFix(FixKind kind) { | 51 void assertNoFix(FixKind kind) { |
| 52 AnalysisError error = _findErrorToFix(); | 52 AnalysisError error = _findErrorToFix(); |
| 53 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); | 53 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); |
| 54 for (Fix fix in fixes) { | 54 for (Fix fix in fixes) { |
| 55 if (fix.kind == kind) { | 55 if (fix.kind == kind) { |
| 56 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); | 56 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 86 List<Position> positions = <Position>[]; | 86 List<Position> positions = <Position>[]; |
| 87 patterns.forEach((String search) { | 87 patterns.forEach((String search) { |
| 88 positions.add(expectedPosition(search)); | 88 positions.add(expectedPosition(search)); |
| 89 }); | 89 }); |
| 90 return positions; | 90 return positions; |
| 91 } | 91 } |
| 92 | 92 |
| 93 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind, | 93 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind, |
| 94 List<String> values) { | 94 List<String> values) { |
| 95 return values.map((value) { | 95 return values.map((value) { |
| 96 return new LinkedEditSuggestion(kind, value); | 96 return new LinkedEditSuggestion(value, kind); |
| 97 }).toList(); | 97 }).toList(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void setUp() { | 100 void setUp() { |
| 101 super.setUp(); | 101 super.setUp(); |
| 102 index = createLocalMemoryIndex(); | 102 index = createLocalMemoryIndex(); |
| 103 searchEngine = new SearchEngineImpl(index); | 103 searchEngine = new SearchEngineImpl(index); |
| 104 verifyNoTestUnitErrors = false; | 104 verifyNoTestUnitErrors = false; |
| 105 } | 105 } |
| 106 | 106 |
| (...skipping 1741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1848 positions.add(new Position(testFile, offset)); | 1848 positions.add(new Position(testFile, offset)); |
| 1849 } | 1849 } |
| 1850 return positions; | 1850 return positions; |
| 1851 } | 1851 } |
| 1852 | 1852 |
| 1853 void _indexTestUnit(String code) { | 1853 void _indexTestUnit(String code) { |
| 1854 resolveTestUnit(code); | 1854 resolveTestUnit(code); |
| 1855 index.indexUnit(context, testUnit); | 1855 index.indexUnit(context, testUnit); |
| 1856 } | 1856 } |
| 1857 } | 1857 } |
| OLD | NEW |