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

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

Issue 562183003: Issue 10355. Quick Fix to replace 'var' with 'dynamic'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.fix; 5 library test.services.correction.fix;
6 6
7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; 7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError;
8 import 'package:analysis_server/src/services/correction/fix.dart'; 8 import 'package:analysis_server/src/services/correction/fix.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 13 matching lines...) Expand all
24 groupSep = ' | '; 24 groupSep = ' | ';
25 runReflectiveTests(FixProcessorTest); 25 runReflectiveTests(FixProcessorTest);
26 } 26 }
27 27
28 28
29 @ReflectiveTestCase() 29 @ReflectiveTestCase()
30 class FixProcessorTest extends AbstractSingleUnitTest { 30 class FixProcessorTest extends AbstractSingleUnitTest {
31 Index index; 31 Index index;
32 SearchEngineImpl searchEngine; 32 SearchEngineImpl searchEngine;
33 33
34 bool checkHasSingleError = true;
35
34 Fix fix; 36 Fix fix;
35 SourceChange change; 37 SourceChange change;
36 String resultCode; 38 String resultCode;
37 39
38 void assertHasFix(FixKind kind, String expected) { 40 void assertHasFix(FixKind kind, String expected) {
39 AnalysisError error = _findErrorToFix(); 41 AnalysisError error = _findErrorToFix();
40 fix = _assertHasFix(kind, error); 42 fix = _assertHasFix(kind, error);
41 change = fix.change; 43 change = fix.change;
42 // apply to "file" 44 // apply to "file"
43 List<SourceFileEdit> fileEdits = change.edits; 45 List<SourceFileEdit> fileEdits = change.edits;
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 'dart:math'; 1243 'dart:math';
1242 main() { 1244 main() {
1243 } 1245 }
1244 '''); 1246 ''');
1245 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, ''' 1247 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, '''
1246 main() { 1248 main() {
1247 } 1249 }
1248 '''); 1250 ''');
1249 } 1251 }
1250 1252
1253 void test_replaceVarWithDynamic() {
1254 checkHasSingleError = false;
1255 _indexTestUnit('''
1256 class A {
1257 Map<String, var> m;
1258 }
1259 ''');
1260 assertHasFix(FixKind.REPLACE_VAR_WITH_DYNAMIC, '''
1261 class A {
1262 Map<String, dynamic> m;
1263 }
1264 ''');
1265 }
1266
1251 void test_replaceWithConstInstanceCreation() { 1267 void test_replaceWithConstInstanceCreation() {
1252 _indexTestUnit(''' 1268 _indexTestUnit('''
1253 class A { 1269 class A {
1254 const A(); 1270 const A();
1255 } 1271 }
1256 const a = new A(); 1272 const a = new A();
1257 '''); 1273 ''');
1258 assertHasFix(FixKind.USE_CONST, ''' 1274 assertHasFix(FixKind.USE_CONST, '''
1259 class A { 1275 class A {
1260 const A(); 1276 const A();
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 [List<LinkedEditSuggestion> expectedSuggestions]) { 1820 [List<LinkedEditSuggestion> expectedSuggestions]) {
1805 List<Position> expectedPositions = _findResultPositions(expectedStrings); 1821 List<Position> expectedPositions = _findResultPositions(expectedStrings);
1806 expect(group.positions, unorderedEquals(expectedPositions)); 1822 expect(group.positions, unorderedEquals(expectedPositions));
1807 if (expectedSuggestions != null) { 1823 if (expectedSuggestions != null) {
1808 expect(group.suggestions, unorderedEquals(expectedSuggestions)); 1824 expect(group.suggestions, unorderedEquals(expectedSuggestions));
1809 } 1825 }
1810 } 1826 }
1811 1827
1812 AnalysisError _findErrorToFix() { 1828 AnalysisError _findErrorToFix() {
1813 List<AnalysisError> errors = context.computeErrors(testSource); 1829 List<AnalysisError> errors = context.computeErrors(testSource);
1814 expect( 1830 if (checkHasSingleError) {
1815 errors, 1831 expect(errors, hasLength(1));
1816 hasLength(1), 1832 }
1817 reason: 'Exactly 1 error expected, but ${errors.length} found:\n' +
1818 errors.join('\n'));
1819 return errors[0]; 1833 return errors[0];
1820 } 1834 }
1821 1835
1822 List<Position> _findResultPositions(List<String> searchStrings) { 1836 List<Position> _findResultPositions(List<String> searchStrings) {
1823 List<Position> positions = <Position>[]; 1837 List<Position> positions = <Position>[];
1824 for (String search in searchStrings) { 1838 for (String search in searchStrings) {
1825 int offset = resultCode.indexOf(search); 1839 int offset = resultCode.indexOf(search);
1826 int length = getLeadingIdentifierLength(search); 1840 int length = getLeadingIdentifierLength(search);
1827 positions.add(new Position(testFile, offset)); 1841 positions.add(new Position(testFile, offset));
1828 } 1842 }
1829 return positions; 1843 return positions;
1830 } 1844 }
1831 1845
1832 void _indexTestUnit(String code) { 1846 void _indexTestUnit(String code) {
1833 resolveTestUnit(code); 1847 resolveTestUnit(code);
1834 index.indexUnit(context, testUnit); 1848 index.indexUnit(context, testUnit);
1835 } 1849 }
1836 } 1850 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698